wrapper-manager/dconf: add env-wide dconf options

This commit is contained in:
Gabriel Arazas 2024-08-30 11:59:29 +08:00
parent 496527e76b
commit 8f6c4a7a46
No known key found for this signature in database
GPG Key ID: 62104B43D00AA360

View File

@ -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