@@ -5,25 +5,37 @@ let
55 inherit (lib) mkOption mkIf optionals literalExample;
66 cfg = config.services.xserver.windowManager.xmonad;
77
8+ ghcWithPackages = cfg.haskellPackages.ghcWithPackages;
9+ packages = self: cfg.extraPackages self ++
10+ optionals cfg.enableContribAndExtras
11+ [ self.xmonad-contrib self.xmonad-extras ];
12+
813 xmonad-vanilla = pkgs.xmonad-with-packages.override {
9− ghcWithPackages = cfg.haskellPackages.ghcWithPackages;
10− packages = self: cfg.extraPackages self ++
11− optionals cfg.enableContribAndExtras
12− [ self.xmonad-contrib self.xmonad-extras ];
14+ inherit ghcWithPackages packages;
1315 };
1416
15− xmonad-config = pkgs.writers.writeHaskellBin "xmonad" {
16− ghc = cfg.haskellPackages.ghc;
17− libraries = [ cfg.haskellPackages.xmonad ] ++
18− cfg.extraPackages cfg.haskellPackages ++
19− optionals cfg.enableContribAndExtras
20− (with cfg.haskellPackages; [ xmonad-contrib xmonad-extras ]);
21− inherit (cfg) ghcArgs;
22− } cfg.config;
17+ xmonad-config =
18+ let
19+ xmonadAndPackages = self: [ self.xmonad ] ++ packages self;
20+ xmonadEnv = ghcWithPackages xmonadAndPackages;
21+ configured = pkgs.writers.writeHaskellBin "xmonad" {
22+ ghc = cfg.haskellPackages.ghc;
23+ libraries = xmonadAndPackages cfg.haskellPackages;
24+ inherit (cfg) ghcArgs;
25+ } cfg.config;
26+ in
27+ pkgs.runCommandLocal "xmonad" {
28+ nativeBuildInputs = [ pkgs.makeWrapper ];
29+ } ''
30+ install -D ${xmonadEnv}/share/man/man1/xmonad.1.gz $out/share/man/man1/xmonad.1.gz
31+ makeWrapper ${configured}/bin/xmonad $out/bin/xmonad \
32+ --set NIX_GHC "${xmonadEnv}/bin/ghc" \
33+ --set XMONAD_XMESSAGE "${pkgs.xorg.xmessage}/bin/xmessage"
34+ '';
2335
2436 xmonad = if (cfg.config != null) then xmonad-config else xmonad-vanilla;
2537in {
26− meta.maintainers = with maintainers; [ lassulus xaverdh ];
38+ meta.maintainers = with maintainers; [ lassulus xaverdh ivanbrennan ];
2739
2840 options = {
2941 services.xserver.windowManager.xmonad = {
@@ -72,13 +84,13 @@ in {
7284 This setup is then analogous to other (non-NixOS) linux distributions.
7385
7486 If you do set this option, you likely want to use "launch" as your
75− entry point for xmonad (as in the example), to avoid xmonads
87+ entry point for xmonad (as in the example), to avoid xmonad's
7688 recompilation logic on startup. Doing so will render the default
7789 "mod+q" restart key binding dysfunctional though, because that attempts
7890 to call your binary with the "--restart" command line option, unless
7991 you implement that yourself. You way mant to bind "mod+q" to
8092 <literal>(restart "xmonad" True)</literal> instead, which will just restart
81− xmonad from PATH. This allows e.g. switching to the new xmonad binary,
93+ xmonad from PATH. This allows e.g. switching to the new xmonad binary
8294 after rebuilding your system with nixos-rebuild.
8395
8496 If you actually want to run xmonad with a config specified here, but
@@ -91,6 +103,7 @@ in {
91103 example = ''
92104 import XMonad
93105 import XMonad.Util.EZConfig (additionalKeys)
106+ import Control.Monad (when)
94107 import Text.Printf (printf)
95108 import System.Posix.Process (executeFile)
96109 import System.Info (arch,os)
@@ -99,16 +112,21 @@ in {
99112
100113 compiledConfig = printf "xmonad-%s-%s" arch os
101114
102− compileRestart = whenX (recompile True) . catchIO $ do
103− dir <- getXMonadDataDir
104− args <- getArgs
105− executeFile (dir </> compiledConfig) False args Nothing
115+ compileRestart resume =
116+ whenX (recompile True) $
117+ when resume writeStateToFile
118+ *> catchIO
119+ ( do
120+ dir <- getXMonadDataDir
121+ args <- getArgs
122+ executeFile (dir </> compiledConfig) False args Nothing
123+ )
106124
107125 main = launch defaultConfig
108126 { modMask = mod4Mask -- Use Super instead of Alt
109127 , terminal = "urxvt" }
110128 `additionalKeys`
111− [ ( (mod4Mask,xK_r), compileRestart )
129+ [ ( (mod4Mask,xK_r), compileRestart True)
112130 , ( (mod4Mask,xK_q), restart "xmonad" True ) ]
113131 '';
114132 };