From b2cc186d22a664a0e07233b7921320601b1b1016 Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Sun, 4 Nov 2018 19:51:40 +0100 Subject: [PATCH 1/5] dconf: add module This module allows unified configuration of dconf settings. --- modules/misc/dconf.nix | 83 ++++++++++++++++++++++++++++++++++++++++++ modules/misc/news.nix | 7 ++++ modules/modules.nix | 1 + 3 files changed, 91 insertions(+) create mode 100644 modules/misc/dconf.nix diff --git a/modules/misc/dconf.nix b/modules/misc/dconf.nix new file mode 100644 index 00000000..8c28fe9c --- /dev/null +++ b/modules/misc/dconf.nix @@ -0,0 +1,83 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.dconf; + dag = config.lib.dag; + + toDconfIni = generators.toINI { mkKeyValue = mkIniKeyValue; }; + + mkIniKeyValue = key: value: + let + tweakVal = v: + if isString v then "'${v}'" + else if isList v then "[" + concatMapStringsSep "," tweakVal v + "]" + else if isBool v then (if v then "true" else "false") + else toString v; + in + "${key}=${tweakVal value}"; + + primitive = with types; either bool (either int str); + +in + +{ + meta.maintainers = [ maintainers.gnidorah maintainers.rycee ]; + + options = { + dconf = { + enable = mkOption { + type = types.bool; + default = true; + visible = false; + description = '' + Whether to enable dconf settings. + ''; + }; + + settings = mkOption { + type = with types; + attrsOf (attrsOf (either primitive (listOf primitive))); + default = {}; + example = literalExample '' + { + "org/gnome/calculator" = { + button-mode = "programming"; + show-thousands = true; + base = 10; + word-size = 64; + }; + } + ''; + description = '' + Settings to write to the dconf configuration system. + ''; + }; + }; + }; + + config = mkIf (cfg.enable && cfg.settings != {}) { + home.activation.dconfSettings = dag.entryAfter ["installPackages"] ( + let + iniFile = pkgs.writeText "hm-dconf.ini" (toDconfIni cfg.settings); + in + '' + if [[ -v DBUS_SESSION_BUS_ADDRESS ]]; then + DCONF_DBUS_RUN_SESSION="" + else + DCONF_DBUS_RUN_SESSION="${pkgs.dbus}/bin/dbus-run-session" + fi + + if [[ -v DRY_RUN ]]; then + echo $DCONF_DBUS_RUN_SESSION ${pkgs.gnome3.dconf}/bin/dconf load / "<" ${iniFile} + else + $DCONF_DBUS_RUN_SESSION ${pkgs.gnome3.dconf}/bin/dconf load / < ${iniFile} + fi + + unset DCONF_DBUS_RUN_SESSION + '' + ); + }; +} diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 95948551..344f569c 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -904,6 +904,13 @@ in A new module is available: 'programs.jq'. ''; } + + { + time = "2018-12-24T16:26:16+00:00"; + message = '' + A new module is available: 'dconf'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index aa9c4583..45ab16a3 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -25,6 +25,7 @@ let (loadModule ./files.nix { }) (loadModule ./home-environment.nix { }) (loadModule ./manual.nix { }) + (loadModule ./misc/dconf.nix { }) (loadModule ./misc/fontconfig.nix { }) (loadModule ./misc/gtk.nix { }) (loadModule ./misc/lib.nix { }) From a0162dacf66f9f87e346f8cfe7b4a4759670eb4e Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Sun, 4 Nov 2018 20:56:43 +0100 Subject: [PATCH 2/5] gnome-terminal: use dconf module for settings --- modules/programs/gnome-terminal.nix | 63 ++++++++--------------------- 1 file changed, 16 insertions(+), 47 deletions(-) diff --git a/modules/programs/gnome-terminal.nix b/modules/programs/gnome-terminal.nix index fa379464..afe12849 100644 --- a/modules/programs/gnome-terminal.nix +++ b/modules/programs/gnome-terminal.nix @@ -6,8 +6,6 @@ let cfg = config.programs.gnome-terminal; - dag = config.lib.dag; - profileColorsSubModule = types.submodule ( { ... }: { options = { @@ -91,19 +89,6 @@ let } ); - toDconfIni = generators.toINI { mkKeyValue = mkIniKeyValue; }; - - mkIniKeyValue = key: value: - let - tweakVal = v: - if isString v then "'${v}'" - else if isList v then "[" + concatStringsSep "," (map tweakVal v) + "]" - else if isBool v && v then "true" - else if isBool v && !v then "false" - else toString v; - in - "${key}=${tweakVal value}"; - buildProfileSet = pcfg: { visible-name = pcfg.visibleName; @@ -136,25 +121,6 @@ let ) ); - buildIniSet = cfg: - { - "/" = { - default-show-menubar = cfg.showMenubar; - schema-version = 3; - }; - } - // - { - "profiles:" = { - default = head (attrNames (filterAttrs (n: v: v.default) cfg.profile)); - list = attrNames cfg.profile; - }; - } - // - mapAttrs' (name: value: - nameValuePair ("profiles:/:${name}") (buildProfileSet value) - ) cfg.profile; - in { @@ -181,20 +147,23 @@ in config = mkIf cfg.enable { home.packages = [ pkgs.gnome3.gnome_terminal ]; - # The dconf service needs to be installed and prepared. - home.activation.gnomeTerminal = dag.entryAfter ["installPackages"] ( + dconf.settings = let - iniText = toDconfIni (buildIniSet cfg); - iniFile = pkgs.writeText "gnome-terminal.ini" iniText; - dconfPath = "/org/gnome/terminal/legacy/"; + dconfPath = "org/gnome/terminal/legacy"; in - '' - if [[ -v DRY_RUN ]]; then - echo ${pkgs.gnome3.dconf}/bin/dconf load ${dconfPath} "<" ${iniFile} - else - ${pkgs.gnome3.dconf}/bin/dconf load ${dconfPath} < ${iniFile} - fi - '' - ); + { + "${dconfPath}" = { + default-show-menubar = cfg.showMenubar; + schema-version = 3; + }; + + "${dconfPath}/profiles:" = { + default = head (attrNames (filterAttrs (n: v: v.default) cfg.profile)); + list = attrNames cfg.profile; + }; + } + // mapAttrs' (n: v: + nameValuePair ("${dconfPath}/profiles:/:${n}") (buildProfileSet v) + ) cfg.profile; }; } From 4104ff2b6a60cb35dd5713327e73f0a9502fcaa3 Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Sun, 4 Nov 2018 21:10:40 +0100 Subject: [PATCH 3/5] gtk: use dconf module for settings --- modules/misc/gtk.nix | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/modules/misc/gtk.nix b/modules/misc/gtk.nix index 930823ff..9f7513d1 100644 --- a/modules/misc/gtk.nix +++ b/modules/misc/gtk.nix @@ -8,8 +8,6 @@ let cfg2 = config.gtk.gtk2; cfg3 = config.gtk.gtk3; - dag = config.lib.dag; - toGtk3Ini = generators.toINI { mkKeyValue = key: value: let @@ -29,16 +27,6 @@ let in "${n} = ${v'}"; - toDconfIni = generators.toINI { - mkKeyValue = key: value: - let - tweakVal = v: - if isString v then "'${v}'" - else toString v; - in - "${key}=${tweakVal value}"; - }; - fontType = types.submodule { options = { package = mkOption { @@ -216,21 +204,8 @@ in xdg.configFile."gtk-3.0/gtk.css".text = cfg3.extraCss; - home.activation = mkIf cfg3.waylandSupport { - gtk3 = dag.entryAfter ["installPackages"] ( - let - iniText = toDconfIni { "/" = dconfIni; }; - iniFile = pkgs.writeText "gtk3.ini" iniText; - dconfPath = "/org/gnome/desktop/interface/"; - in - '' - if [[ -v DRY_RUN ]]; then - echo ${pkgs.gnome3.dconf}/bin/dconf load ${dconfPath} "<" ${iniFile} - else - ${pkgs.gnome3.dconf}/bin/dconf load ${dconfPath} < ${iniFile} - fi - '' - ); + dconf.settings = mkIf cfg3.waylandSupport { + "org/gnome/desktop/interface" = dconfIni; }; } ); From 370a84192ef576d0c7ae3a4623ff8131a9f4482b Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Mon, 24 Dec 2018 12:07:26 +0100 Subject: [PATCH 4/5] gtk: make gtk.gtk2 and gtk.gtk3 not submodules --- modules/misc/gtk.nix | 92 +++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 52 deletions(-) diff --git a/modules/misc/gtk.nix b/modules/misc/gtk.nix index 9f7513d1..6542091c 100644 --- a/modules/misc/gtk.nix +++ b/modules/misc/gtk.nix @@ -100,63 +100,51 @@ in description = "The GTK+2/3 theme to use."; }; - gtk2 = mkOption { - description = "Options specific to GTK+ 2"; - default = {}; - type = types.submodule { - options = { - extraConfig = mkOption { - type = types.lines; - default = ""; - example = "gtk-can-change-accels = 1"; - description = '' - Extra configuration lines to add verbatim to - ~/.gtkrc-2.0. - ''; - }; - }; + gtk2 = { + extraConfig = mkOption { + type = types.lines; + default = ""; + example = "gtk-can-change-accels = 1"; + description = '' + Extra configuration lines to add verbatim to + ~/.gtkrc-2.0. + ''; }; }; - gtk3 = mkOption { - description = "Options specific to GTK+ 3"; - default = {}; - type = types.submodule { - options = { - extraConfig = mkOption { - type = types.attrs; - default = {}; - example = { gtk-cursor-blink = false; gtk-recent-files-limit = 20; }; - description = '' - Extra configuration options to add to - ~/.config/gtk-3.0/settings.ini. - ''; - }; + gtk3 = { + extraConfig = mkOption { + type = types.attrs; + default = {}; + example = { gtk-cursor-blink = false; gtk-recent-files-limit = 20; }; + description = '' + Extra configuration options to add to + ~/.config/gtk-3.0/settings.ini. + ''; + }; - extraCss = mkOption { - type = types.lines; - default = ""; - description = '' - Extra configuration lines to add verbatim to - ~/.config/gtk-3.0/gtk.css. - ''; - }; + extraCss = mkOption { + type = types.lines; + default = ""; + description = '' + Extra configuration lines to add verbatim to + ~/.config/gtk-3.0/gtk.css. + ''; + }; - waylandSupport = mkOption { - type = types.bool; - default = false; - description = '' - Support GSettings provider (dconf) in addition to - GtkSettings (INI file). This is needed for Wayland. - - Note, on NixOS the following line must be in the - system configuration: - - services.dbus.packages = [ pkgs.gnome3.dconf ]; - - ''; - }; - }; + waylandSupport = mkOption { + type = types.bool; + default = false; + description = '' + Support GSettings provider (dconf) in addition to + GtkSettings (INI file). This is needed for Wayland. + + Note, on NixOS the following line must be in the + system configuration: + + services.dbus.packages = [ pkgs.gnome3.dconf ]; + + ''; }; }; }; From cc964b4609616e4dffbe67a6e8c8924540ceae6e Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Mon, 24 Dec 2018 12:05:28 +0100 Subject: [PATCH 5/5] gtk: remove option gtk.gtk3.waylandSupport --- modules/misc/gtk.nix | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/modules/misc/gtk.nix b/modules/misc/gtk.nix index 6542091c..c88ee4c0 100644 --- a/modules/misc/gtk.nix +++ b/modules/misc/gtk.nix @@ -76,6 +76,12 @@ in { meta.maintainers = [ maintainers.rycee ]; + imports = [ + (mkRemovedOptionModule ["gtk" "gtk3" "waylandSupport"] '' + This options is not longer needed and can be removed. + '') + ]; + options = { gtk = { enable = mkEnableOption "GTK 2/3 configuration"; @@ -131,21 +137,6 @@ in ~/.config/gtk-3.0/gtk.css. ''; }; - - waylandSupport = mkOption { - type = types.bool; - default = false; - description = '' - Support GSettings provider (dconf) in addition to - GtkSettings (INI file). This is needed for Wayland. - - Note, on NixOS the following line must be in the - system configuration: - - services.dbus.packages = [ pkgs.gnome3.dconf ]; - - ''; - }; }; }; }; @@ -176,7 +167,6 @@ in optional (opt != null && opt.package != null) opt.package; in { - home.packages = optionalPackage cfg.font ++ optionalPackage cfg.theme @@ -192,9 +182,7 @@ in xdg.configFile."gtk-3.0/gtk.css".text = cfg3.extraCss; - dconf.settings = mkIf cfg3.waylandSupport { - "org/gnome/desktop/interface" = dconfIni; - }; + dconf.settings."org/gnome/desktop/interface" = dconfIni; } ); }