2020-04-24 23:36:52 +00:00
|
|
|
{pkgs, lib, config, ...}:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
2021-10-06 13:57:05 +00:00
|
|
|
inherit (lib) mkOption mkIf optionals literalExpression;
|
2020-04-24 23:36:52 +00:00
|
|
|
cfg = config.services.xserver.windowManager.xmonad;
|
2020-10-16 20:44:37 +00:00
|
|
|
|
2020-12-29 15:07:52 +00:00
|
|
|
ghcWithPackages = cfg.haskellPackages.ghcWithPackages;
|
|
|
|
packages = self: cfg.extraPackages self ++
|
|
|
|
optionals cfg.enableContribAndExtras
|
|
|
|
[ self.xmonad-contrib self.xmonad-extras ];
|
|
|
|
|
2020-10-16 20:44:37 +00:00
|
|
|
xmonad-vanilla = pkgs.xmonad-with-packages.override {
|
2020-12-29 15:07:52 +00:00
|
|
|
inherit ghcWithPackages packages;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2020-10-16 20:44:37 +00:00
|
|
|
|
2020-12-29 15:07:52 +00:00
|
|
|
xmonad-config =
|
|
|
|
let
|
|
|
|
xmonadAndPackages = self: [ self.xmonad ] ++ packages self;
|
|
|
|
xmonadEnv = ghcWithPackages xmonadAndPackages;
|
|
|
|
configured = pkgs.writers.writeHaskellBin "xmonad" {
|
|
|
|
ghc = cfg.haskellPackages.ghc;
|
|
|
|
libraries = xmonadAndPackages cfg.haskellPackages;
|
|
|
|
inherit (cfg) ghcArgs;
|
|
|
|
} cfg.config;
|
|
|
|
in
|
|
|
|
pkgs.runCommandLocal "xmonad" {
|
|
|
|
nativeBuildInputs = [ pkgs.makeWrapper ];
|
|
|
|
} ''
|
|
|
|
install -D ${xmonadEnv}/share/man/man1/xmonad.1.gz $out/share/man/man1/xmonad.1.gz
|
|
|
|
makeWrapper ${configured}/bin/xmonad $out/bin/xmonad \
|
|
|
|
--set NIX_GHC "${xmonadEnv}/bin/ghc" \
|
|
|
|
--set XMONAD_XMESSAGE "${pkgs.xorg.xmessage}/bin/xmessage"
|
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-10-16 20:44:37 +00:00
|
|
|
xmonad = if (cfg.config != null) then xmonad-config else xmonad-vanilla;
|
|
|
|
in {
|
2020-12-29 15:07:52 +00:00
|
|
|
meta.maintainers = with maintainers; [ lassulus xaverdh ivanbrennan ];
|
2020-10-16 20:44:37 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
options = {
|
|
|
|
services.xserver.windowManager.xmonad = {
|
|
|
|
enable = mkEnableOption "xmonad";
|
|
|
|
haskellPackages = mkOption {
|
|
|
|
default = pkgs.haskellPackages;
|
2021-10-06 13:57:05 +00:00
|
|
|
defaultText = literalExpression "pkgs.haskellPackages";
|
|
|
|
example = literalExpression "pkgs.haskell.packages.ghc784";
|
2020-04-24 23:36:52 +00:00
|
|
|
description = ''
|
|
|
|
haskellPackages used to build Xmonad and other packages.
|
|
|
|
This can be used to change the GHC version used to build
|
|
|
|
Xmonad and the packages listed in
|
|
|
|
<varname>extraPackages</varname>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraPackages = mkOption {
|
2021-02-05 17:12:51 +00:00
|
|
|
type = types.functionTo (types.listOf types.package);
|
2020-04-24 23:36:52 +00:00
|
|
|
default = self: [];
|
2021-10-06 13:57:05 +00:00
|
|
|
defaultText = literalExpression "self: []";
|
|
|
|
example = literalExpression ''
|
2020-04-24 23:36:52 +00:00
|
|
|
haskellPackages: [
|
|
|
|
haskellPackages.xmonad-contrib
|
|
|
|
haskellPackages.monad-logger
|
|
|
|
]
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Extra packages available to ghc when rebuilding Xmonad. The
|
|
|
|
value must be a function which receives the attrset defined
|
|
|
|
in <varname>haskellPackages</varname> as the sole argument.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
enableContribAndExtras = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = lib.types.bool;
|
|
|
|
description = "Enable xmonad-{contrib,extras} in Xmonad.";
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkOption {
|
|
|
|
default = null;
|
|
|
|
type = with lib.types; nullOr (either path str);
|
|
|
|
description = ''
|
2020-10-16 20:44:37 +00:00
|
|
|
Configuration from which XMonad gets compiled. If no value is
|
|
|
|
specified, a vanilla xmonad binary is put in PATH, which will
|
|
|
|
attempt to recompile and exec your xmonad config from $HOME/.xmonad.
|
|
|
|
This setup is then analogous to other (non-NixOS) linux distributions.
|
|
|
|
|
|
|
|
If you do set this option, you likely want to use "launch" as your
|
2020-12-29 15:07:52 +00:00
|
|
|
entry point for xmonad (as in the example), to avoid xmonad's
|
2020-10-16 20:44:37 +00:00
|
|
|
recompilation logic on startup. Doing so will render the default
|
|
|
|
"mod+q" restart key binding dysfunctional though, because that attempts
|
|
|
|
to call your binary with the "--restart" command line option, unless
|
|
|
|
you implement that yourself. You way mant to bind "mod+q" to
|
|
|
|
<literal>(restart "xmonad" True)</literal> instead, which will just restart
|
2020-12-29 15:07:52 +00:00
|
|
|
xmonad from PATH. This allows e.g. switching to the new xmonad binary
|
2020-10-16 20:44:37 +00:00
|
|
|
after rebuilding your system with nixos-rebuild.
|
|
|
|
|
|
|
|
If you actually want to run xmonad with a config specified here, but
|
|
|
|
also be able to recompile and restart it from a copy of that source in
|
|
|
|
$HOME/.xmonad on the fly, you will have to implement that yourself
|
|
|
|
using something like "compileRestart" from the example.
|
|
|
|
This should allow you to switch at will between the local xmonad and
|
|
|
|
the one NixOS puts in your PATH.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
example = ''
|
|
|
|
import XMonad
|
2020-10-16 20:44:37 +00:00
|
|
|
import XMonad.Util.EZConfig (additionalKeys)
|
2020-12-29 15:07:52 +00:00
|
|
|
import Control.Monad (when)
|
2020-10-16 20:44:37 +00:00
|
|
|
import Text.Printf (printf)
|
|
|
|
import System.Posix.Process (executeFile)
|
|
|
|
import System.Info (arch,os)
|
|
|
|
import System.Environment (getArgs)
|
|
|
|
import System.FilePath ((</>))
|
|
|
|
|
|
|
|
compiledConfig = printf "xmonad-%s-%s" arch os
|
|
|
|
|
2020-12-29 15:07:52 +00:00
|
|
|
compileRestart resume =
|
|
|
|
whenX (recompile True) $
|
|
|
|
when resume writeStateToFile
|
|
|
|
*> catchIO
|
|
|
|
( do
|
|
|
|
dir <- getXMonadDataDir
|
|
|
|
args <- getArgs
|
|
|
|
executeFile (dir </> compiledConfig) False args Nothing
|
|
|
|
)
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
main = launch defaultConfig
|
2020-10-16 20:44:37 +00:00
|
|
|
{ modMask = mod4Mask -- Use Super instead of Alt
|
|
|
|
, terminal = "urxvt" }
|
|
|
|
`additionalKeys`
|
2020-12-29 15:07:52 +00:00
|
|
|
[ ( (mod4Mask,xK_r), compileRestart True)
|
2020-10-16 20:44:37 +00:00
|
|
|
, ( (mod4Mask,xK_q), restart "xmonad" True ) ]
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
2020-09-25 04:45:31 +00:00
|
|
|
|
|
|
|
xmonadCliArgs = mkOption {
|
|
|
|
default = [];
|
|
|
|
type = with lib.types; listOf str;
|
|
|
|
description = ''
|
|
|
|
Command line arguments passed to the xmonad binary.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
ghcArgs = mkOption {
|
|
|
|
default = [];
|
|
|
|
type = with lib.types; listOf str;
|
|
|
|
description = ''
|
|
|
|
Command line arguments passed to the compiler (ghc)
|
|
|
|
invocation when xmonad.config is set.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
services.xserver.windowManager = {
|
|
|
|
session = [{
|
|
|
|
name = "xmonad";
|
2020-10-16 20:44:37 +00:00
|
|
|
start = ''
|
|
|
|
systemd-cat -t xmonad -- ${xmonad}/bin/xmonad ${lib.escapeShellArgs cfg.xmonadCliArgs} &
|
2020-09-25 04:45:31 +00:00
|
|
|
waitPID=$!
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
}];
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.systemPackages = [ xmonad ];
|
|
|
|
};
|
|
|
|
}
|