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;
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 {
@ -88,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";
@ -112,11 +106,7 @@ in
description = "The GTK+2/3 theme to use.";
};
gtk2 = mkOption {
description = "Options specific to GTK+ 2";
default = {};
type = types.submodule {
options = {
gtk2 = {
extraConfig = mkOption {
type = types.lines;
default = "";
@ -127,14 +117,8 @@ in
'';
};
};
};
};
gtk3 = mkOption {
description = "Options specific to GTK+ 3";
default = {};
type = types.submodule {
options = {
gtk3 = {
extraConfig = mkOption {
type = types.attrs;
default = {};
@ -153,23 +137,6 @@ in
<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;
in
{
home.packages =
optionalPackage cfg.font
++ optionalPackage cfg.theme
@ -216,22 +182,7 @@ 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."org/gnome/desktop/interface" = dconfIni;
}
);
}

View file

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

View file

@ -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 { })

View file

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