diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index e3255a6a..b39486cf 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -59,6 +59,8 @@ Makefile @thiagokokada /tests/modules/misc/xdg/desktop-full-expected.desktop @cwyc /tests/modules/misc/xdg/desktop-min-expected.desktop @cwyc +/modules/misc/xfconf.nix @chuangzhu + /modules/programs/aerc.nix @lukasngl /modules/programs/aerc-accounts.nix @lukasngl /tests/modules/programs/aerc @lukasngl diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 21303e63..bb1e7e2b 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -807,6 +807,14 @@ in A new module is available: 'programs.oh-my-posh'. ''; } + + { + time = "2022-11-02T10:56:14+00:00"; + condition = hostPlatform.isLinux; + message = '' + A new module is available: 'xfconf'. + ''; + } ]; }; } diff --git a/modules/misc/xfconf.nix b/modules/misc/xfconf.nix new file mode 100644 index 00000000..b4141bf5 --- /dev/null +++ b/modules/misc/xfconf.nix @@ -0,0 +1,102 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.xfconf; + + withType = v: + if builtins.isBool v then [ + "-t" + "bool" + "-s" + (if v then "true" else "false") + ] else if builtins.isInt v then [ + "-t" + "int" + "-s" + (toString v) + ] else if builtins.isFloat v then [ + "-t" + "double" + "-s" + (toString v) + ] else if builtins.isString v then [ + "-t" + "string" + "-s" + v + ] else if builtins.isList v then + [ "-a" ] ++ concatMap withType v + else + throw "unexpected xfconf type: ${builtins.typeOf v}"; + +in { + meta.maintainers = [ maintainers.chuangzhu ]; + + options.xfconf = { + enable = mkOption { + type = types.bool; + default = true; + visible = false; + description = '' + Whether to enable Xfconf settings. + + Note, if you use NixOS then you must add + programs.xfconf.enable = true + to your system configuration. Otherwise you will see a systemd error + message when your configuration is activated. + ''; + }; + + settings = mkOption { + type = with types; + attrsOf (attrsOf (oneOf [ + bool + int + float + str + (listOf (oneOf [ bool int float str ])) + ])) // { + description = "xfconf settings"; + }; + default = { }; + example = literalExpression '' + { + xfce4-session = { + "startup/ssh-agent/enabled" = false; + "general/LockCommand" = "''${pkgs.lightdm}/bin/dm-tool lock"; + }; + xfce4-desktop = { + "backdrop/screen0/monitorLVDS-1/workspace0/last-image" = + "''${pkgs.nixos-artwork.wallpapers.stripes-logo.gnomeFilePath}"; + }; + } + ''; + description = '' + Settings to write to the Xfconf configuration system. + ''; + }; + }; + + config = mkIf (cfg.enable && cfg.settings != { }) { + assertions = + [ (hm.assertions.assertPlatform "xfconf" pkgs platforms.linux) ]; + + home.activation.xfconfSettings = hm.dag.entryAfter [ "installPackages" ] + (let + mkCommand = channel: property: value: '' + $DRY_RUN_CMD ${pkgs.xfce.xfconf}/bin/xfconf-query \ + ${ + escapeShellArgs + ([ "-n" "-c" channel "-p" "/${property}" ] ++ withType value) + } + ''; + + commands = mapAttrsToList + (channel: properties: mapAttrsToList (mkCommand channel) properties) + cfg.settings; + in concatMapStrings concatStrings commands); + }; +} diff --git a/modules/modules.nix b/modules/modules.nix index bfeae7e7..d465e8ca 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -43,6 +43,7 @@ let ./misc/xdg-system-dirs.nix ./misc/xdg-user-dirs.nix ./misc/xdg.nix + ./misc/xfconf.nix ./programs/abook.nix ./programs/aerc.nix ./programs/afew.nix