nixos/dconf: add locks support

linsui 038d78d4 fb52d5df

Changed files
+57
nixos
modules
programs
tests
+22
nixos/modules/programs/dconf.nix
···
cp -R ${dir} $out
'';
+
mkAllLocks = settings: lib.flatten (
+
lib.mapAttrsToList (k: v: lib.mapAttrsToList (k': _: "/${k}/${k'}") v) settings);
+
# Generate dconf DB from dconfDatabase and keyfiles
mkDconfDb = val: compileDconfDb (pkgs.symlinkJoin {
name = "nixos-generated-dconf-keyfiles";
paths = [
(pkgs.writeTextDir "nixos-generated-dconf-keyfiles" (lib.generators.toDconfINI val.settings))
+
(pkgs.writeTextDir "locks/nixos-generated-dconf-locks" (lib.concatStringsSep "\n"
+
(if val.lockAll then mkAllLocks val.settings else val.locks)
+
))
] ++ (map checkDconfKeyfiles val.keyfiles);
});
···
};
}
'';
+
};
+
locks = lib.mkOption {
+
type = with lib.types; listOf str;
+
default = [ ];
+
description = lib.mdDoc ''
+
A list of dconf keys to be lockdown. This doesn't take effect if `lockAll`
+
is set.
+
'';
+
example = literalExpression ''
+
[ "/org/gnome/desktop/background/picture-uri" ]
+
'';
+
};
+
lockAll = lib.mkOption {
+
type = lib.types.bool;
+
default = false;
+
description = lib.mdDoc "Lockdown all dconf keys in `settings`.";
};
};
};
+1
nixos/tests/all-tests.nix
···
custom-ca = handleTest ./custom-ca.nix {};
croc = handleTest ./croc.nix {};
darling = handleTest ./darling.nix {};
+
dconf = handleTest ./dconf.nix {};
deepin = handleTest ./deepin.nix {};
deluge = handleTest ./deluge.nix {};
dendrite = handleTest ./matrix/dendrite.nix {};
+34
nixos/tests/dconf.nix
···
+
import ./make-test-python.nix
+
({ lib, ... }:
+
{
+
name = "dconf";
+
+
meta.maintainers = with lib.maintainers; [
+
linsui
+
];
+
+
nodes.machine = { config, pkgs, lib, ... }: {
+
users.extraUsers.alice = { isNormalUser = true; };
+
programs.dconf = with lib.gvariant; {
+
enable = true;
+
profiles.user.databases = [
+
{
+
settings = {
+
"test/not/locked" = mkInt32 1;
+
"test/is/locked" = "locked";
+
};
+
locks = [
+
"/test/is/locked"
+
];
+
}
+
];
+
};
+
};
+
+
testScript = ''
+
machine.succeed("test $(dconf read -d /test/not/locked) == 1")
+
machine.succeed("test $(dconf read -d /test/is/locked) == \"'locked'\"")
+
machine.fail("sudo -u alice dbus-run-session -- dconf write /test/is/locked \"@s 'unlocked'\"")
+
machine.succeed("sudo -u alice dbus-run-session -- dconf write /test/not/locked \"@i 2\"")
+
'';
+
})