From 2cf33f24be9de76d0a2d5818818b9826bf05a996 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 25 Oct 2015 02:06:37 +0100 Subject: tv xmonad service: save state on shutdown --- tv/2configs/xserver/default.nix | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) (limited to 'tv/2configs/xserver/default.nix') diff --git a/tv/2configs/xserver/default.nix b/tv/2configs/xserver/default.nix index 5d3372609..9e20bda18 100644 --- a/tv/2configs/xserver/default.nix +++ b/tv/2configs/xserver/default.nix @@ -44,11 +44,14 @@ let systemd.services.display-manager = mkForce {}; services.xserver.enable = true; + systemd.services.xmonad = { wantedBy = [ "multi-user.target" ]; requires = [ "xserver.service" ]; + environment = xmonad-environment; serviceConfig = { - ExecStart = "${xmonad}/bin/xmonad"; + ExecStart = "${xmonad-start}/bin/xmonad"; + ExecStop = "${xmonad-stop}/bin/xmonad-stop"; User = user.name; WorkingDirectory = user.home; }; @@ -69,15 +72,19 @@ let }; }; - xmonad = let - pkg = pkgs.haskellPackages.callPackage src {}; - src = pkgs.runCommand "xmonad-package" {} '' - ${pkgs.cabal2nix}/bin/cabal2nix ${./xmonad} > $out - ''; - in pkgs.writeScriptBin "xmonad" '' - #! /bin/sh + xmonad-pkg = pkgs.haskellPackages.callPackage xmonad-src {}; + xmonad-src = pkgs.runCommand "xmonad-package" {} '' + ${pkgs.cabal2nix}/bin/cabal2nix ${./xmonad} > $out + ''; + + xmonad-environment = { + DISPLAY = ":${toString config.services.xserver.display}"; + XMONAD_STATE = "/tmp/xmonad.state"; + }; + + xmonad-start = pkgs.writeScriptBin "xmonad" '' + #! ${pkgs.bash}/bin/bash set -efu - export DISPLAY; DISPLAY=:${toString config.services.xserver.display} export PATH; PATH=${makeSearchPath "bin" [ pkgs.rxvt_unicode ]}:/var/setuid-wrappers @@ -93,7 +100,17 @@ let settle ${pkgs.xorg.xhost}/bin/xhost +LOCAL: settle ${pkgs.xorg.xrdb}/bin/xrdb -merge ${import ./Xresources.nix args} settle ${pkgs.xorg.xsetroot}/bin/xsetroot -solid '#1c1c1c' - exec ${pkg}/bin/xmonad + if test -e "$XMONAD_STATE"; then + IFS=''$'\n' + exec ${xmonad-pkg}/bin/xmonad --resume $(< "$XMONAD_STATE") + else + exec ${xmonad-pkg}/bin/xmonad + fi + ''; + + xmonad-stop = pkgs.writeScriptBin "xmonad-stop" '' + #! /bin/sh + exec ${xmonad-pkg}/bin/xmonad --shutdown ''; xserver-environment = { @@ -103,7 +120,7 @@ let [ "${pkgs.xorg.libX11}/lib" "${pkgs.xorg.libXext}/lib" ] ++ concatLists (catAttrs "libPath" config.services.xserver.drivers)); }; - + xserver = pkgs.writeScriptBin "xserver" '' #! /bin/sh set -efu -- cgit v1.2.3 From e281271239289a266777d0b429e604ec9aeaed41 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 25 Oct 2015 02:32:19 +0100 Subject: {tv cfgs => krebs pkgs} writeNixFromCabal --- tv/2configs/xserver/default.nix | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'tv/2configs/xserver/default.nix') diff --git a/tv/2configs/xserver/default.nix b/tv/2configs/xserver/default.nix index 9e20bda18..facdf6df2 100644 --- a/tv/2configs/xserver/default.nix +++ b/tv/2configs/xserver/default.nix @@ -73,9 +73,7 @@ let }; xmonad-pkg = pkgs.haskellPackages.callPackage xmonad-src {}; - xmonad-src = pkgs.runCommand "xmonad-package" {} '' - ${pkgs.cabal2nix}/bin/cabal2nix ${./xmonad} > $out - ''; + xmonad-src = pkgs.writeNixFromCabal "xmonad.nix" ./xmonad; xmonad-environment = { DISPLAY = ":${toString config.services.xserver.display}"; -- cgit v1.2.3 From 39236213abc668d35fab45e6bb747f11862e992d Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 25 Oct 2015 12:21:46 +0100 Subject: tv xmonad: read initial workspaces from file --- tv/2configs/xserver/default.nix | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tv/2configs/xserver/default.nix') diff --git a/tv/2configs/xserver/default.nix b/tv/2configs/xserver/default.nix index facdf6df2..c5cffbb30 100644 --- a/tv/2configs/xserver/default.nix +++ b/tv/2configs/xserver/default.nix @@ -78,6 +78,19 @@ let xmonad-environment = { DISPLAY = ":${toString config.services.xserver.display}"; XMONAD_STATE = "/tmp/xmonad.state"; + + # XXX JSON is close enough :) + XMONAD_WORKSPACES0_FILE = pkgs.writeText "xmonad.workspaces0" (toJSON [ + "Dashboard" # we start here + "23" + "cr" + "ff" + "hack" + "im" + "mail" + "stockholm" + "za" "zj" "zs" + ]); }; xmonad-start = pkgs.writeScriptBin "xmonad" '' -- cgit v1.2.3