2018-11-04 19:51:40 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.dconf;
|
|
|
|
|
|
|
|
toDconfIni = generators.toINI { mkKeyValue = mkIniKeyValue; };
|
|
|
|
|
2020-12-21 23:22:22 +01:00
|
|
|
mkIniKeyValue = key: value: "${key}=${toString (hm.gvariant.mkValue value)}";
|
2018-11-04 19:51:40 +01:00
|
|
|
|
2022-07-01 23:33:43 +02:00
|
|
|
# The dconf keys managed by this configuration. We store this as part of the
|
|
|
|
# generation state to be able to reset keys that become unmanaged during
|
|
|
|
# switch.
|
|
|
|
stateDconfKeys = pkgs.writeText "dconf-keys.json" (builtins.toJSON
|
|
|
|
(concatLists (mapAttrsToList
|
|
|
|
(dir: entries: mapAttrsToList (key: _: "/${dir}/${key}") entries)
|
|
|
|
cfg.settings)));
|
|
|
|
|
2020-12-21 23:22:22 +01:00
|
|
|
in {
|
2021-12-25 08:28:37 +01:00
|
|
|
meta.maintainers = [ maintainers.rycee ];
|
2018-11-04 19:51:40 +01:00
|
|
|
|
|
|
|
options = {
|
|
|
|
dconf = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
visible = false;
|
|
|
|
description = ''
|
|
|
|
Whether to enable dconf settings.
|
2022-03-26 08:49:31 +01:00
|
|
|
</para><para>
|
|
|
|
Note, if you use NixOS then you must add
|
|
|
|
<code>programs.dconf.enable = true</code>
|
|
|
|
to your system configuration. Otherwise you will see a systemd error
|
|
|
|
message when your configuration is activated.
|
2018-11-04 19:51:40 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
settings = mkOption {
|
2020-03-09 23:25:45 +01:00
|
|
|
type = with types; attrsOf (attrsOf hm.types.gvariant);
|
2020-12-21 23:22:22 +01:00
|
|
|
default = { };
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2018-11-04 19:51:40 +01:00
|
|
|
{
|
|
|
|
"org/gnome/calculator" = {
|
|
|
|
button-mode = "programming";
|
|
|
|
show-thousands = true;
|
|
|
|
base = 10;
|
|
|
|
word-size = 64;
|
2020-03-09 23:25:45 +01:00
|
|
|
window-position = lib.hm.gvariant.mkTuple [100 100];
|
2018-11-04 19:51:40 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Settings to write to the dconf configuration system.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-12-21 23:22:22 +01:00
|
|
|
config = mkIf (cfg.enable && cfg.settings != { }) {
|
2021-01-20 00:21:00 +01:00
|
|
|
# Make sure the dconf directory exists.
|
|
|
|
xdg.configFile."dconf/.keep".source = builtins.toFile "keep" "";
|
|
|
|
|
2022-07-01 23:33:43 +02:00
|
|
|
home.extraBuilderCommands = ''
|
|
|
|
mkdir -p $out/state/
|
|
|
|
ln -s ${stateDconfKeys} $out/state/${stateDconfKeys.name}
|
|
|
|
'';
|
|
|
|
|
|
|
|
home.activation.dconfSettings = hm.dag.entryAfter [ "installPackages" ] (let
|
|
|
|
iniFile = pkgs.writeText "hm-dconf.ini" (toDconfIni cfg.settings);
|
|
|
|
|
|
|
|
statePath = "state/${stateDconfKeys.name}";
|
|
|
|
|
|
|
|
cleanup = pkgs.writeShellScript "dconf-cleanup" ''
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
${config.lib.bash.initHomeManagerLib}
|
2018-11-04 19:51:40 +01:00
|
|
|
|
2022-07-01 23:33:43 +02:00
|
|
|
PATH=${makeBinPath [ pkgs.dconf pkgs.jq ]}''${PATH:+:}$PATH
|
|
|
|
|
|
|
|
oldState="$1"
|
|
|
|
newState="$2"
|
|
|
|
|
|
|
|
# Can't do cleanup if we don't know the old state.
|
|
|
|
if [[ ! -f $oldState ]]; then
|
|
|
|
exit 0
|
2020-12-21 23:22:22 +01:00
|
|
|
fi
|
2018-11-04 19:51:40 +01:00
|
|
|
|
2022-07-01 23:33:43 +02:00
|
|
|
# Reset all keys that are present in the old generation but not the new
|
|
|
|
# one.
|
|
|
|
jq -r -n \
|
|
|
|
--slurpfile old "$oldState" \
|
|
|
|
--slurpfile new "$newState" \
|
|
|
|
'($old[] - $new[])[]' \
|
|
|
|
| while read -r key; do
|
|
|
|
$VERBOSE_ECHO "Resetting dconf key \"$key\""
|
|
|
|
$DRY_RUN_CMD $DCONF_DBUS_RUN_SESSION dconf reset "$key"
|
|
|
|
done
|
|
|
|
'';
|
|
|
|
in ''
|
|
|
|
if [[ -v DBUS_SESSION_BUS_ADDRESS ]]; then
|
|
|
|
export DCONF_DBUS_RUN_SESSION=""
|
|
|
|
else
|
|
|
|
export DCONF_DBUS_RUN_SESSION="${pkgs.dbus}/bin/dbus-run-session"
|
|
|
|
fi
|
|
|
|
|
2022-10-16 17:59:57 +02:00
|
|
|
if [[ -v oldGenPath ]]; then
|
|
|
|
${cleanup} \
|
|
|
|
"$oldGenPath/${statePath}" \
|
|
|
|
"$newGenPath/${statePath}"
|
|
|
|
fi
|
2022-07-01 23:33:43 +02:00
|
|
|
|
|
|
|
$DRY_RUN_CMD $DCONF_DBUS_RUN_SESSION ${pkgs.dconf}/bin/dconf load / < ${iniFile}
|
|
|
|
|
|
|
|
unset DCONF_DBUS_RUN_SESSION
|
|
|
|
'');
|
2018-11-04 19:51:40 +01:00
|
|
|
};
|
|
|
|
}
|