summary refs log tree commit diff
path: root/nixos/modules/programs
diff options
context:
space:
mode:
authorlinsui <linsui555@gmail.com>2023-06-14 16:22:17 +0800
committerlinsui <linsui@inbox.lv>2023-08-15 19:20:39 +0800
commitcce75fa51e1ef5d6f1657b9c0b9ca1963f8f3b03 (patch)
treef27442663537017a2dc8e986da122558a8312405 /nixos/modules/programs
parentda614d98e9540002bb1a1a9165177c3a6719f07f (diff)
downloadnixpkgs-cce75fa51e1ef5d6f1657b9c0b9ca1963f8f3b03.tar
nixpkgs-cce75fa51e1ef5d6f1657b9c0b9ca1963f8f3b03.tar.gz
nixpkgs-cce75fa51e1ef5d6f1657b9c0b9ca1963f8f3b03.tar.bz2
nixpkgs-cce75fa51e1ef5d6f1657b9c0b9ca1963f8f3b03.tar.lz
nixpkgs-cce75fa51e1ef5d6f1657b9c0b9ca1963f8f3b03.tar.xz
nixpkgs-cce75fa51e1ef5d6f1657b9c0b9ca1963f8f3b03.tar.zst
nixpkgs-cce75fa51e1ef5d6f1657b9c0b9ca1963f8f3b03.zip
nixos/dconf: refractor
remove `with lib;`
profiles option now accepts packages in addition to paths.
profiles option is no longer internal.
cfgDir definition has been inlined.
pulled GIO_EXTRA_MODULES inside mkif.
removed pointless comments with section headings.
defined profiles are now turned into package, allowing to simplify the db update logic.
Diffstat (limited to 'nixos/modules/programs')
-rw-r--r--nixos/modules/programs/dconf.nix74
1 files changed, 35 insertions, 39 deletions
diff --git a/nixos/modules/programs/dconf.nix b/nixos/modules/programs/dconf.nix
index 7261a143528..b5bfb79be20 100644
--- a/nixos/modules/programs/dconf.nix
+++ b/nixos/modules/programs/dconf.nix
@@ -1,55 +1,50 @@
 { config, lib, pkgs, ... }:
 
-with lib;
-
 let
   cfg = config.programs.dconf;
-  cfgDir = pkgs.symlinkJoin {
-    name = "dconf-system-config";
-    paths = map (x: "${x}/etc/dconf") cfg.packages;
-    postBuild = ''
-      mkdir -p $out/profile
-      mkdir -p $out/db
-    '' + (
-      concatStringsSep "\n" (
-        mapAttrsToList (
-          name: path: ''
-            ln -s ${path} $out/profile/${name}
-          ''
-        ) cfg.profiles
-      )
-    ) + ''
-      ${pkgs.dconf}/bin/dconf update $out/db
+
+  # Generate dconf profile
+  mkDconfProfile = name: value:
+    pkgs.runCommand "dconf-profile" { } ''
+      mkdir -p $out/etc/dconf/profile/
+      cp ${value} $out/etc/dconf/profile/${name}
     '';
-  };
 in
 {
-  ###### interface
-
   options = {
     programs.dconf = {
-      enable = mkEnableOption (lib.mdDoc "dconf");
-
-      profiles = mkOption {
-        type = types.attrsOf types.path;
-        default = {};
-        description = lib.mdDoc "Set of dconf profile files, installed at {file}`/etc/dconf/profiles/«name»`.";
-        internal = true;
+      enable = lib.mkEnableOption (lib.mdDoc "dconf");
+
+      profiles = lib.mkOption {
+        type = with lib.types; attrsOf (oneOf [
+          path
+          package
+        ]);
+        description = lib.mdDoc "Attrset of dconf profiles.";
       };
 
-      packages = mkOption {
-        type = types.listOf types.package;
-        default = [];
+      packages = lib.mkOption {
+        type = lib.types.listOf lib.types.package;
+        default = [ ];
         description = lib.mdDoc "A list of packages which provide dconf profiles and databases in {file}`/etc/dconf`.";
       };
     };
   };
 
-  ###### implementation
-
-  config = mkIf (cfg.profiles != {} || cfg.enable) {
-    environment.etc.dconf = mkIf (cfg.profiles != {} || cfg.packages != []) {
-      source = cfgDir;
+  config = lib.mkIf (cfg.profiles != { } || cfg.enable) {
+    programs.dconf.packages = lib.mapAttrsToList mkDconfProfile cfg.profiles;
+
+    environment.etc.dconf = lib.mkIf (cfg.packages != [ ]) {
+      source = pkgs.symlinkJoin {
+        name = "dconf-system-config";
+        paths = map (x: "${x}/etc/dconf") cfg.packages;
+        nativeBuildInputs = [ (lib.getBin pkgs.dconf) ];
+        postBuild = ''
+          if test -d $out/db; then
+            dconf update $out/db
+          fi
+        '';
+      };
     };
 
     services.dbus.packages = [ pkgs.dconf ];
@@ -59,8 +54,9 @@ in
     # For dconf executable
     environment.systemPackages = [ pkgs.dconf ];
 
-    # Needed for unwrapped applications
-    environment.sessionVariables.GIO_EXTRA_MODULES = mkIf cfg.enable [ "${pkgs.dconf.lib}/lib/gio/modules" ];
+    environment.sessionVariables = lib.mkIf cfg.enable {
+      # Needed for unwrapped applications
+      GIO_EXTRA_MODULES = [ "${pkgs.dconf.lib}/lib/gio/modules" ];
+    };
   };
-
 }