From 8f6c4a7a46cd3a0f2e4eaf6f11a6b8e527ec7bfb Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Fri, 30 Aug 2024 11:59:29 +0800 Subject: [PATCH] wrapper-manager/dconf: add env-wide dconf options --- modules/wrapper-manager/dconf.nix | 131 ++++++++++++++++++------------ 1 file changed, 79 insertions(+), 52 deletions(-) diff --git a/modules/wrapper-manager/dconf.nix b/modules/wrapper-manager/dconf.nix index cdfacc6e..fe6aaaea 100644 --- a/modules/wrapper-manager/dconf.nix +++ b/modules/wrapper-manager/dconf.nix @@ -8,9 +8,11 @@ # upstream and it may be here for the rest of time. # # In other words, dconf is just not built for this case. -{ lib, pkgs, ... }: +{ config, lib, pkgs, ... }: let + cfg = config.dconf; + settingsFormat = { type = with lib.types; let @@ -29,8 +31,72 @@ let generate = name: value: pkgs.writeTextDir "/dconf/${name}" (lib.generators.toDconfINI value); }; + + dconfModuleFactory = { isGlobal ? false }: { + enable = lib.mkEnableOption "configuration with dconf" // lib.optionalAttrs (!isGlobal) { + default = cfg.enable; + }; + + package = lib.mkPackageOption pkgs "dconf" { } // lib.optionalAttrs (!isGlobal) { + default = cfg.package; + }; + + settings = lib.mkOption { + type = settingsFormat.type; + default = { }; + description = if isGlobal then '' + Global settings to be applied per dconf-enabled wrapper. + '' else '' + The settings of the dconf database that the wrapper uses. + ''; + example = lib.literalExpression '' + { + "org/gnome/nautilus/list-view".use-tree-view = true; + "org/gnome/nautilus/preferences".show-create-link = true; + "org/gtk/settings/file-chooser" = { + sort-directories-first = true; + show-hidden = true; + }; + } + ''; + }; + + keyfiles = lib.mkOption { + type = with lib.types; listOf path; + description = if isGlobal then '' + Global list of keyfiles to be included to each dconf-enabled wrapper. + '' else '' + Additional list of keyfiles to be included as part of the dconf + database. + ''; + default = if isGlobal then [ ] else [ "user-db" ]; + example = lib.literalExpression '' + [ + ./config/dconf/90-extra-settings.conf + ] + ''; + }; + + profile = lib.mkOption { + type = with lib.types; listOf str; + description = if isGlobal then '' + Global list of dconf database that will be used for each dconf-enabled + wrappers. + '' else '' + A list of dconf databases that will be used for the main dconf + profile of the dconf-configured wrapper. + ''; + default = [ "user-db:user" ]; + defaultText = '' + "user-db:user" as the writeable database alongside the generated + database file from our settings. + ''; + }; + }; in { + options.dconf = dconfModuleFactory { isGlobal = true; }; + options.wrappers = let dconfSubmodule = { config, lib, name, ... }: let @@ -56,56 +122,7 @@ in dconf compile ${builtins.placeholder "out"} "${keyfilesDir}" ''; in { - options.dconf = { - enable = lib.mkEnableOption "configuration with dconf"; - - package = lib.mkPackageOption pkgs "dconf" { }; - - settings = lib.mkOption { - type = settingsFormat.type; - default = { }; - description = '' - The settings of the dconf database that the wrapper uses. - ''; - example = lib.literalExpression '' - { - "org/gnome/nautilus/list-view".use-tree-view = true; - "org/gnome/nautilus/preferences".show-create-link = true; - "org/gtk/settings/file-chooser" = { - sort-directories-first = true; - show-hidden = true; - }; - } - ''; - }; - - keyfiles = lib.mkOption { - type = with lib.types; listOf path; - description = '' - Additional list of keyfiles to be included as part of the dconf - database. - ''; - default = [ ]; - example = lib.literalExpression '' - [ - ./config/dconf/90-extra-settings.conf - ] - ''; - }; - - profile = lib.mkOption { - type = with lib.types; listOf str; - description = '' - A list of dconf databases that will be used for the main dconf - profile of the dconf-configured wrapper. - ''; - default = [ "user-db:user" "file-db:${dconfSettingsDatabase}" ]; - defaultText = '' - "user-db:user" as the writeable database alongside the generated - database file from our settings. - ''; - }; - + options.dconf = dconfModuleFactory { isGlobal = false; } // { databaseDrv = lib.mkOption { type = lib.types.package; description = '' @@ -118,7 +135,17 @@ in config = lib.mkIf submoduleCfg.enable { env.DCONF_PROFILE.value = dconfProfileFile; - dconf.databaseDrv = dconfSettingsDatabase; + + dconf = { + profile = lib.mkMerge [ + cfg.profile + + (lib.mkAfter [ (builtins.toString submoduleCfg.databaseDrv) ]) + ]; + keyfiles = cfg.keyfiles; + settings = cfg.settings; + databaseDrv = dconfSettingsDatabase; + }; }; }; in