appvm/base.nix.go

124 lines
2.8 KiB
Go
Raw Normal View History

2019-12-29 17:41:44 +00:00
package main
2020-01-07 20:01:52 +00:00
import (
"fmt"
"log"
"os/user"
)
var base_nix = `
2018-07-12 19:29:35 +00:00
{pkgs, ...}:
2018-06-30 08:39:47 +00:00
{
imports = [
<nix/local.nix>
];
2018-06-30 08:39:47 +00:00
services.xserver = {
enable = true;
desktopManager.xterm.enable = false;
displayManager = {
lightdm.enable = true;
autoLogin = {
enable = true;
user = "user";
};
2018-06-30 08:39:47 +00:00
};
windowManager.xmonad.enable = true;
};
2018-07-12 17:43:42 +00:00
services.spice-vdagentd.enable = true;
2018-06-30 08:39:47 +00:00
users.extraUsers.user = {
2020-01-07 20:01:52 +00:00
uid = %s;
2018-06-30 08:39:47 +00:00
isNormalUser = true;
extraGroups = [ "audio" ];
createHome = true;
};
environment.etc."xmonad.hs".text = ''
import XMonad
main = xmonad defaultConfig
{ workspaces = [ "" ]
, borderWidth = 0
2018-07-12 17:43:42 +00:00
, startupHook = startup
}
2018-07-12 17:43:42 +00:00
startup :: X ()
startup = do
2020-01-03 10:14:28 +00:00
spawn "while [ 1 ]; do ${pkgs.spice-vdagent}/bin/spice-vdagent -x; done &"
'';
systemd.services.home-user-build-xmonad = {
description = "Link xmonad configuration";
serviceConfig = {
ConditionFileNotEmpty = "!/home/user/.xmonad/xmonad.hs";
2018-07-12 17:43:20 +00:00
ExecStart = "/bin/sh -c 'mkdir -p /home/user/.xmonad && ln -s /etc/xmonad.hs /home/user/.xmonad/xmonad.hs'";
RemainAfterExit = "yes";
User = "user";
Restart = "on-failure";
TimeoutSec = 10;
};
wantedBy = [ "multi-user.target" ];
};
2018-07-11 23:34:36 +00:00
systemd.services.mount-home-user = {
description = "Mount /home/user (crutch)";
serviceConfig = {
2020-01-07 20:01:52 +00:00
ExecStart = "/bin/sh -c '/run/current-system/sw/bin/mount -t 9p -o trans=virtio,version=9p2000.L home /home/user'";
2018-07-11 23:34:36 +00:00
RemainAfterExit = "yes";
Type = "oneshot";
User = "root";
};
wantedBy = [ "sysinit.target" ];
};
systemd.user.services."xrandr" = {
serviceConfig = {
StartLimitBurst = 100;
};
script = "${pkgs.xorg.xrandr}/bin/xrandr --output Virtual-1 --mode $(${pkgs.xorg.xrandr}/bin/xrandr | grep ' ' | head -n 2 | tail -n 1 | ${pkgs.gawk}/bin/awk '{ print $1 }')";
};
systemd.user.timers."xrandr" = {
description = "Auto update resolution crutch";
timerConfig = {
OnBootSec = "1s";
OnUnitInactiveSec = "1s";
Unit = "xrandr.service";
AccuracySec = "1us";
};
wantedBy = ["timers.target"];
};
systemd.services."autoballoon" = {
serviceConfig = {
StartLimitBurst = 100;
};
script = ''
${pkgs.procps}/bin/free -m | grep Mem | \
${pkgs.gawk}/bin/awk '{print $2 "-" $4}' | \
${pkgs.bc}/bin/bc > /home/user/.memory_used
'';
};
systemd.timers."autoballoon" = {
description = "Auto update resolution crutch";
timerConfig = {
OnBootSec = "1s";
OnUnitInactiveSec = "1s";
Unit = "autoballoon.service";
AccuracySec = "1us";
};
wantedBy = ["timers.target"];
};
2018-06-30 08:39:47 +00:00
}
2020-01-07 20:01:52 +00:00
`
func baseNix() []byte {
u, err := user.Current()
if err != nil {
log.Fatal(err)
}
return []byte(fmt.Sprintf(base_nix, u.Uid))
}