summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-12-04 01:30:49 +0000
committertv <tv@krebsco.de>2026-12-04 03:05:12 +0000
commitb25c2abad084fa6d2fc930e27998533010b50708 (patch)
tree9fde45348b6c9eb2753489486bc978f085023aa5
parent607fb1010baae845910e75ba31687bffb259636b (diff)
x11: xmonad
From the dirt. Hosts set what's specific to them: XMONAD_MASTER_* by the unit's environment, and shortcuts by hrm.xmonad.shortcuts. hrm.xresources replaces tv.Xresources: X resources per display, and "*" for all, loaded by the session service xresources@ instead of a system service.
-rw-r--r--configs/x11/default.nix1
-rw-r--r--configs/x11/xmonad.nix84
-rw-r--r--configs/xserver/nsxiv.nix2
-rw-r--r--configs/xserver/urxvt.nix2
-rw-r--r--modules/Xresources.nix44
-rw-r--r--modules/x11/xresources.nix44
-rw-r--r--systems/leg/config.nix6
7 files changed, 137 insertions, 46 deletions
diff --git a/configs/x11/default.nix b/configs/x11/default.nix
index 8ee40c22..22630ae5 100644
--- a/configs/x11/default.nix
+++ b/configs/x11/default.nix
@@ -1,5 +1,6 @@
{
imports = [
+ ./xmonad.nix
./xserver.nix
];
diff --git a/configs/x11/xmonad.nix b/configs/x11/xmonad.nix
new file mode 100644
index 00000000..8616fa59
--- /dev/null
+++ b/configs/x11/xmonad.nix
@@ -0,0 +1,84 @@
+{ config, mylib, lib, pkgs, ... }: let
+ xmonad-main =
+ mylib.haskell.substitutePkgs "main.hs" {
+ inherit pkgs;
+ path = cfg.pkg.src + "/main.hs";
+ };
+
+ cfg = {
+ pkg = pkgs.haskellPackages.xmonad-tv;
+ };
+in {
+ options.hrm.xmonad.shortcuts = lib.mkOption {
+ default = {};
+ type = lib.types.attrsOf lib.types.str;
+ example = {
+ "M4-<F7>" = "/run/current-system/sw/bin/xtoggledpms";
+ };
+ description = ''
+ Programs to run, by key, in the notation of XMonad.Util.EZConfig.
+ '';
+ };
+
+ config = {
+ hrm.xsession.services = [ "xmonad" ];
+
+ systemd.user.services."xmonad@" = {
+ after = [ "xresources@%i.service" ];
+ serviceConfig = {
+ ExecStart = pkgs.writeDash "xmonad-start" ''
+ ${pkgs.coreutils}/bin/mkdir -p "$XMONAD_CACHE_DIR"
+ ${pkgs.coreutils}/bin/mkdir -p "$XMONAD_CONFIG_DIR"
+ ${pkgs.coreutils}/bin/mkdir -p "$XMONAD_DATA_DIR"
+
+ case $(${pkgs.desktop-pager}/bin/desktops) in
+ null|[])
+ ${pkgs.desktop-pager}/bin/desktops set ${lib.concatMapStringsSep " " mylib.shell.escape [
+ "Dashboard" # we start here
+ ]}
+ ;;
+ esac
+
+ exec ${cfg.pkg}/bin/xmonad
+ '';
+ ExecStop = "${cfg.pkg}/bin/xmonad --shutdown";
+ ExecReload = "${pkgs.coreutils}/bin/echo RELOAD, lol";
+ Slice = "session.slice";
+ };
+
+ environment = {
+ XOUTINFO_OVERRIDE = config.hrm.environment.variables.XOUTINFO_OVERRIDE or "{}";
+
+ TMPDIR = "/run/user/%U";
+ FZMENU_FZF_DEFAULT_OPTS = toString [
+ "--color=dark,border:126,bg+:090"
+ "--inline-info"
+ ];
+ XMONAD_CACHE_DIR = "/run/user/%U/xmonad-%i";
+ XMONAD_CONFIG_DIR = "/var/empty";
+ XMONAD_DATA_DIR = "/run/user/%U/xmonad-%i";
+ XMONAD_SHORTCUTS =
+ pkgs.writeJSON "xmonad-shortcuts.json" config.hrm.xmonad.shortcuts;
+ XMONAD_STARTUP_HOOK = pkgs.writeDash "xmonad-ready" ''
+ if ! ${pkgs.xhost}/bin/xhost | ${pkgs.gnugrep}/bin/grep -q "^SI:localuser:$USER\$"; then
+ ${pkgs.xhost}/bin/xhost "+SI:localuser:$USER"
+ ${pkgs.xhost}/bin/xhost -LOCAL:
+ fi
+ case $DISPLAY in
+ :11) bgColor=#1c1c1c;;
+ *) bgColor=#231c23;;
+ esac
+ ${pkgs.hsetroot}/bin/hsetroot -solid "$bgColor" &
+ ${pkgs.xsetroot}/bin/xsetroot -cursor_name plus &
+ wait
+ '';
+ };
+
+ path = xmonad-main.dependencies ++ [ config.tv.slock.package ];
+ };
+
+ hrm.xresources."*" = {
+ "Xcursor.size" = "64";
+ };
+ };
+}
diff --git a/configs/xserver/nsxiv.nix b/configs/xserver/nsxiv.nix
index 477429fd..83ab5a13 100644
--- a/configs/xserver/nsxiv.nix
+++ b/configs/xserver/nsxiv.nix
@@ -1,7 +1,7 @@
{ config, pkgs, ... }: let
cfg.user = config.krebs.build.user;
in {
- tv.Xresources = {
+ hrm.xresources."*" = {
"Nsxiv.window.foreground" = "#232323";
"Nsxiv.window.background" = "#424242";
};
diff --git a/configs/xserver/urxvt.nix b/configs/xserver/urxvt.nix
index df5affab..f143da78 100644
--- a/configs/xserver/urxvt.nix
+++ b/configs/xserver/urxvt.nix
@@ -13,7 +13,7 @@ in {
User = cfg.user.name;
};
};
- tv.Xresources = {
+ hrm.xresources."*" = {
"URxvt*cutchars" = ''"\\`\"'&()*,;<=>?@[]^{|}‘’"'';
"URxvt*eightBitInput" = "false";
"URxvt*font" = "-*-clean-*-*-*-*-*-*-*-*-*-*-iso10646-1";
diff --git a/modules/Xresources.nix b/modules/Xresources.nix
deleted file mode 100644
index afba48e3..00000000
--- a/modules/Xresources.nix
+++ /dev/null
@@ -1,44 +0,0 @@
-{ config, lib, pkgs, ... }: let
- cfg = {
- enable = config.services.xserver.enable && config.tv.Xresources != {};
- user = config.krebs.build.user;
- };
- local.types.Xresources = lib.types.attrsOf lib.types.str;
-
- mapAttrNames = f: lib.mapAttrs' (name: lib.nameValuePair (f name));
- mapAttrValues = f: lib.mapAttrs (_: f);
-in {
- options.tv.Xresources = lib.mkOption {
- default = {};
- type = lib.types.attrsOf lib.types.str;
- };
- config = {
- nixpkgs.overlays = lib.singleton (self: super: {
- tv = super.tv or {} // {
- Xresources =
- self.writeText "Xresources"
- (lib.concatStrings
- (lib.mapAttrsToList
- (name: value: /* xdefaults */ ''
- ${name}: ${value}
- '')
- config.tv.Xresources));
- };
- });
- systemd.services.${if cfg.enable then "Xresources" else null} = {
- wantedBy = [ "graphical.target" ];
- after = [ "xmonad.service" ];
- environment = {
- DISPLAY = ":${toString config.services.xserver.display}";
- };
- serviceConfig = {
- ExecStart = "${pkgs.xrdb}/bin/xrdb ${pkgs.tv.Xresources}";
- RemainAfterExit = true;
- SyslogIdentifier = "Xresources";
- Type = "oneshot";
- User = cfg.user.name;
- WorkingDirectory = cfg.user.home;
- };
- };
- };
-}
diff --git a/modules/x11/xresources.nix b/modules/x11/xresources.nix
new file mode 100644
index 00000000..981d1cad
--- /dev/null
+++ b/modules/x11/xresources.nix
@@ -0,0 +1,44 @@
+# Loads X resources into each X session, before the session's other
+# services start.
+{ config, lib, pkgs, ... }: let
+ cfg = config.hrm.xresources;
+
+ files =
+ pkgs.linkFarm "xresources"
+ (lib.mapAttrs
+ (display: resources:
+ pkgs.writeText "xresources-${display}"
+ (lib.concatStrings
+ (lib.mapAttrsToList
+ (name: value: "${name}: ${value}\n")
+ resources)))
+ ({ "*" = {}; } // cfg));
+in {
+ options.hrm.xresources = lib.mkOption {
+ default = {};
+ type = lib.types.attrsOf (lib.types.attrsOf lib.types.str);
+ example = {
+ "*"."Xcursor.size" = "64";
+ "8"."XTerm*background" = "#1e171e";
+ };
+ description = ''
+ X resources, by display number. Those under "*" are for every
+ display, and a display's own override them.
+ '';
+ };
+ config = lib.mkIf config.hrm.xsession.enable {
+ hrm.xsession.services = [ "xresources" ];
+ systemd.user.services."xresources@".serviceConfig = {
+ ExecStart = pkgs.writeDash "xresources-load" ''
+ set -efu
+ LC_ALL=C ${pkgs.xrdb}/bin/xrdb -load ${files}/'*'
+ f=${files}/''${DISPLAY#:}
+ if test -e "$f"; then
+ LC_ALL=C ${pkgs.xrdb}/bin/xrdb -override "$f"
+ fi
+ '';
+ RemainAfterExit = true;
+ Type = "oneshot";
+ };
+ };
+}
diff --git a/systems/leg/config.nix b/systems/leg/config.nix
index 066aafe9..ec780dcd 100644
--- a/systems/leg/config.nix
+++ b/systems/leg/config.nix
@@ -149,4 +149,10 @@
};
services.illum.enable = true;
+
+ # master width = master terminal columns * column width / screen width
+ systemd.user.services."xmonad@".environment = {
+ XMONAD_MASTER_WIDTH = toString (80 * 14 / 2560.);
+ XMONAD_MASTER_DELTA = toString (8 * 14 / 2560.);
+ };
}