This commit is contained in:
Robert Helgesson 2018-12-24 17:35:27 +01:00
commit e3167068d9
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
5 changed files with 140 additions and 129 deletions

83
modules/misc/dconf.nix Normal file
View file

@ -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
''
);
};
}

View file

@ -8,8 +8,6 @@ let
cfg2 = config.gtk.gtk2; cfg2 = config.gtk.gtk2;
cfg3 = config.gtk.gtk3; cfg3 = config.gtk.gtk3;
dag = config.lib.dag;
toGtk3Ini = generators.toINI { toGtk3Ini = generators.toINI {
mkKeyValue = key: value: mkKeyValue = key: value:
let let
@ -29,16 +27,6 @@ let
in in
"${n} = ${v'}"; "${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 { fontType = types.submodule {
options = { options = {
package = mkOption { package = mkOption {
@ -88,6 +76,12 @@ in
{ {
meta.maintainers = [ maintainers.rycee ]; meta.maintainers = [ maintainers.rycee ];
imports = [
(mkRemovedOptionModule ["gtk" "gtk3" "waylandSupport"] ''
This options is not longer needed and can be removed.
'')
];
options = { options = {
gtk = { gtk = {
enable = mkEnableOption "GTK 2/3 configuration"; enable = mkEnableOption "GTK 2/3 configuration";
@ -112,63 +106,36 @@ in
description = "The GTK+2/3 theme to use."; description = "The GTK+2/3 theme to use.";
}; };
gtk2 = mkOption { gtk2 = {
description = "Options specific to GTK+ 2"; extraConfig = mkOption {
default = {}; type = types.lines;
type = types.submodule { default = "";
options = { example = "gtk-can-change-accels = 1";
extraConfig = mkOption { description = ''
type = types.lines; Extra configuration lines to add verbatim to
default = ""; <filename>~/.gtkrc-2.0</filename>.
example = "gtk-can-change-accels = 1"; '';
description = ''
Extra configuration lines to add verbatim to
<filename>~/.gtkrc-2.0</filename>.
'';
};
};
}; };
}; };
gtk3 = mkOption { gtk3 = {
description = "Options specific to GTK+ 3"; extraConfig = mkOption {
default = {}; type = types.attrs;
type = types.submodule { default = {};
options = { example = { gtk-cursor-blink = false; gtk-recent-files-limit = 20; };
extraConfig = mkOption { description = ''
type = types.attrs; Extra configuration options to add to
default = {}; <filename>~/.config/gtk-3.0/settings.ini</filename>.
example = { gtk-cursor-blink = false; gtk-recent-files-limit = 20; }; '';
description = '' };
Extra configuration options to add to
<filename>~/.config/gtk-3.0/settings.ini</filename>.
'';
};
extraCss = mkOption { extraCss = mkOption {
type = types.lines; type = types.lines;
default = ""; default = "";
description = '' description = ''
Extra configuration lines to add verbatim to Extra configuration lines to add verbatim to
<filename>~/.config/gtk-3.0/gtk.css</filename>. <filename>~/.config/gtk-3.0/gtk.css</filename>.
''; '';
};
waylandSupport = mkOption {
type = types.bool;
default = false;
description = ''
Support GSettings provider (dconf) in addition to
GtkSettings (INI file). This is needed for Wayland.
</para><para>
Note, on NixOS the following line must be in the
system configuration:
<programlisting>
services.dbus.packages = [ pkgs.gnome3.dconf ];
</programlisting>
'';
};
};
}; };
}; };
}; };
@ -200,7 +167,6 @@ in
optional (opt != null && opt.package != null) opt.package; optional (opt != null && opt.package != null) opt.package;
in in
{ {
home.packages = home.packages =
optionalPackage cfg.font optionalPackage cfg.font
++ optionalPackage cfg.theme ++ optionalPackage cfg.theme
@ -216,22 +182,7 @@ in
xdg.configFile."gtk-3.0/gtk.css".text = cfg3.extraCss; xdg.configFile."gtk-3.0/gtk.css".text = cfg3.extraCss;
home.activation = mkIf cfg3.waylandSupport { dconf.settings."org/gnome/desktop/interface" = dconfIni;
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
''
);
};
} }
); );
} }

View file

@ -904,6 +904,13 @@ in
A new module is available: 'programs.jq'. A new module is available: 'programs.jq'.
''; '';
} }
{
time = "2018-12-24T16:26:16+00:00";
message = ''
A new module is available: 'dconf'.
'';
}
]; ];
}; };
} }

View file

@ -25,6 +25,7 @@ let
(loadModule ./files.nix { }) (loadModule ./files.nix { })
(loadModule ./home-environment.nix { }) (loadModule ./home-environment.nix { })
(loadModule ./manual.nix { }) (loadModule ./manual.nix { })
(loadModule ./misc/dconf.nix { })
(loadModule ./misc/fontconfig.nix { }) (loadModule ./misc/fontconfig.nix { })
(loadModule ./misc/gtk.nix { }) (loadModule ./misc/gtk.nix { })
(loadModule ./misc/lib.nix { }) (loadModule ./misc/lib.nix { })

View file

@ -6,8 +6,6 @@ let
cfg = config.programs.gnome-terminal; cfg = config.programs.gnome-terminal;
dag = config.lib.dag;
profileColorsSubModule = types.submodule ( profileColorsSubModule = types.submodule (
{ ... }: { { ... }: {
options = { 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: buildProfileSet = pcfg:
{ {
visible-name = pcfg.visibleName; 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 in
{ {
@ -181,20 +147,23 @@ in
config = mkIf cfg.enable { config = mkIf cfg.enable {
home.packages = [ pkgs.gnome3.gnome_terminal ]; home.packages = [ pkgs.gnome3.gnome_terminal ];
# The dconf service needs to be installed and prepared. dconf.settings =
home.activation.gnomeTerminal = dag.entryAfter ["installPackages"] (
let let
iniText = toDconfIni (buildIniSet cfg); dconfPath = "org/gnome/terminal/legacy";
iniFile = pkgs.writeText "gnome-terminal.ini" iniText;
dconfPath = "/org/gnome/terminal/legacy/";
in in
'' {
if [[ -v DRY_RUN ]]; then "${dconfPath}" = {
echo ${pkgs.gnome3.dconf}/bin/dconf load ${dconfPath} "<" ${iniFile} default-show-menubar = cfg.showMenubar;
else schema-version = 3;
${pkgs.gnome3.dconf}/bin/dconf load ${dconfPath} < ${iniFile} };
fi
'' "${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;
}; };
} }