nixos/users/modules/darkman.nix

52 lines
1.2 KiB
Nix

{
pkgs,
lib,
config,
...
}: let
cfg = config.services.darkman;
mkScript = text: {
inherit text;
executable = true;
};
mkLightPath = path: "light-mode.d/${path}";
mkDarkPath = path: "dark-mode.d/${path}";
in {
options.services.darkman = with lib; {
enable = mkEnableOption "darkman, the darkmode switcher";
scripts = mkOption {
description = "Darkman scripts";
type = with types;
attrsOf (uniq (submodule {
options = {
onLight = mkOption {
description = "Script to execute when lightmode is activated";
type = lines;
};
onDark = mkOption {
description = "Script to execute when darkmode is activated";
type = lines;
};
};
}));
};
};
config = lib.mkIf cfg.enable {
systemd.user.services."darkman".Install.WantedBy = ["graphical-session.target"];
xdg.dataFile =
(lib.attrsets.mapAttrs' (key: conf: {
name = mkLightPath key;
value = mkScript conf.onLight;
})
cfg.scripts)
// (lib.attrsets.mapAttrs' (key: conf: {
name = mkDarkPath key;
value = mkScript conf.onDark;
})
cfg.scripts);
};
}