fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . xsession . windowManager . xmonad ; 8 9xmonad = pkgs . xmonad-with-packages . override { 10ghcWithPackages = cfg . haskellPackages . ghcWithPackages ; 11packages = self : 12cfg . extraPackages self ++ optionals cfg . enableContribAndExtras [ 13self . xmonad-contrib 14self . xmonad-extras 15]; 16}; 17 18in { 19options = { 20xsession . windowManager . xmonad = { 21enable = mkEnableOption "xmonad window manager" ; 22 23haskellPackages = mkOption { 24default = pkgs . haskellPackages ; 25defaultText = literalExpression "pkgs.haskellPackages" ; 26example = literalExpression "pkgs.haskell.packages.ghc784" ; 27description = '' 28The {var}`haskellPackages` used to build xmonad 29and other packages. This can be used to change the GHC 30version used to build xmonad and the packages listed in 31{var}`extraPackages`. 32'' ; 33}; 34 35extraPackages = mkOption { 36default = self :[ ]; 37defaultText = "self: []" ; 38example = literalExpression '' 39haskellPackages: [ 40haskellPackages.xmonad-contrib 41haskellPackages.monad-logger 42] 43'' ; 44description = '' 45Extra packages available to GHC when rebuilding xmonad. The 46value must be a function which receives the attribute set 47defined in {var}`haskellPackages` as the sole 48argument. 49'' ; 50}; 51 52enableContribAndExtras = mkOption { 53default = false ; 54type = types . bool ; 55description = "Enable xmonad-{contrib,extras} in xmonad." ; 56}; 57 58config = mkOption { 59type = types . nullOr types . path ; 60default = null ; 61example = literalExpression '' 62pkgs.writeText "xmonad.hs" ''' 63import XMonad 64main = xmonad defaultConfig 65{ terminal = "urxvt" 66, modMask = mod4Mask 67, borderWidth = 3 68} 69''' 70'' ; 71description = '' 72The configuration file to be used for xmonad. This must be 73an absolute path or `null` in which case 74{file}`~/.xmonad/xmonad.hs` will not be managed 75by Home Manager. 76 77If this option is set to a non-`null` value, 78recompilation of xmonad outside of Home Manager (e.g. via 79{command}`xmonad --recompile`) will fail. 80'' ; 81}; 82 83libFiles = mkOption { 84type = types . attrsOf ( types . oneOf [ types . path ]); 85default = { }; 86example = literalExpression '' 87{ 88"Tools.hs" = pkgs.writeText "Tools.hs" ''' 89module Tools where 90screenshot = "scrot" 91'''; 92} 93'' ; 94description = '' 95Additional files that will be saved in 96{file}`~/.xmonad/lib/` and included in the configuration 97build. The keys are the file names while the values are paths to the 98contents of the files. 99'' ; 100}; 101}; 102}; 103 104config = let 105 106xmonadBin = " ${ 107pkgs . runCommandLocal "xmonad-compile" { 108nativeBuildInputs = [ xmonad ]; 109} '' 110mkdir -p $ out /bin 111 112export XMONAD_CONFIG_DIR =" $( pwd ) /xmonad-config" 113export XMONAD_DATA_DIR =" $( pwd ) /data" 114export XMONAD_CACHE_DIR =" $( pwd ) /cache" 115 116mkdir -p " $ XMONAD_CONFIG_DIR /lib" " $ XMONAD_CACHE_DIR " " $ XMONAD_DATA_DIR " 117 118cp ${ cfg . config } xmonad-config/xmonad.hs 119 120declare -A libFiles 121libFiles =( ${ 122concatStringsSep " " 123( mapAttrsToList ( name : value : "[' ${ name } ']=' ${ value } '" ) 124cfg . libFiles ) 125} ) 126for key in "'' $ { !libFiles[@]} "; do 127cp "'' $ { libFiles [ $ key ]}" " xmonad-config/lib/ $ key "; 128done 129 130xmonad --recompile 131 132# The resulting binary name depends on the arch and os 133# https://github.com/xmonad/xmonad/blob/56b0f850bc35200ec23f05c079eca8b0a1f90305/src/XMonad/Core.hs#L565-L572 134if [ -f " $ XMONAD_DATA_DIR/xmonad- ${ pkgs . stdenv . hostPlatform . system } " ]; then 135# xmonad 0.15.0 136mv " $ XMONAD_DATA_DIR /xmonad- ${ pkgs . stdenv . hostPlatform . system } " $ out /bin/ 137else 138# xmonad 0.17.0 (https://github.com/xmonad/xmonad/commit/9813e218b034009b0b6d09a70650178980e05d54) 139mv " $ XMONAD_CACHE_DIR /xmonad- ${ pkgs . stdenv . hostPlatform . system } " $ out /bin/ 140fi 141'' 142} /bin/xmonad- ${ pkgs . stdenv . hostPlatform . system } " ; 143 144in mkIf cfg . enable ( mkMerge [ 145{ 146assertions = [ 147( hm . assertions . assertPlatform "xsession.windowManager.xmonad" pkgs 148platforms . linux ) 149]; 150 151home . packages = [ ( lowPrio xmonad ) ]; 152 153home . file = mapAttrs' ( name :value : 154attrsets . nameValuePair ( ".xmonad/lib/" + name ) { source = value ; }) 155cfg . libFiles ; 156} 157 158( mkIf ( cfg . config == null ) { 159xsession . windowManager . command = " ${ xmonad } /bin/xmonad" ; 160}) 161 162( mkIf ( cfg . config != null ) { 163xsession . windowManager . command = xmonadBin ; 164home . file . ".xmonad/xmonad.hs" . source = cfg . config ; 165home . file . ".xmonad/xmonad- ${ pkgs . stdenv . hostPlatform . system } " = { 166source = xmonadBin ; 167onChange = '' 168# Attempt to restart xmonad if X is running. 169if [[ -v DISPLAY ]]; then 170${ config . xsession . windowManager . command } --restart 171fi 172'' ; 173}; 174}) 175 176]); 177}