···
cfg = config.programs.dconf;
6
+
# Compile keyfiles to dconf DB
7
+
compileDconfDb = dir: pkgs.runCommand "dconf-db"
9
+
nativeBuildInputs = [ (lib.getBin pkgs.dconf) ];
10
+
} "dconf compile $out ${dir}";
12
+
# Check if dconf keyfiles are valid
13
+
checkDconfKeyfiles = dir: pkgs.runCommand "check-dconf-keyfiles"
15
+
nativeBuildInputs = [ (lib.getBin pkgs.dconf) ];
17
+
if [[ -f ${dir} ]]; then
18
+
echo "dconf keyfiles should be a directory but a file is provided: ${dir}"
22
+
dconf compile db ${dir} || (
23
+
echo "The dconf keyfiles are invalid: ${dir}"
29
+
# Generate dconf DB from dconfDatabase and keyfiles
30
+
mkDconfDb = val: compileDconfDb (pkgs.symlinkJoin {
31
+
name = "nixos-generated-dconf-keyfiles";
33
+
(pkgs.writeTextDir "nixos-generated-dconf-keyfiles" (lib.generators.toDconfINI val.settings))
34
+
] ++ (map checkDconfKeyfiles val.keyfiles);
37
+
# Check if a dconf DB file is valid. The dconf cli doesn't return 1 when it can't
38
+
# open the database file so we have to check if the output is empty.
39
+
checkDconfDb = file: pkgs.runCommand "check-dconf-db"
41
+
nativeBuildInputs = [ (lib.getBin pkgs.dconf) ];
43
+
if [[ -d ${file} ]]; then
44
+
echo "dconf DB should be a file but a directory is provided: ${file}"
48
+
echo "file-db:${file}" > profile
49
+
DCONF_PROFILE=$(pwd)/profile dconf dump / > output 2> error
50
+
if [[ ! -s output ]] && [[ -s error ]]; then
52
+
echo "The dconf DB file is invalid: ${file}"
mkDconfProfile = name: value:
8
-
pkgs.runCommand "dconf-profile" { } ''
9
-
mkdir -p $out/etc/dconf/profile/
10
-
cp ${value} $out/etc/dconf/profile/${name}
61
+
if lib.isDerivation value || lib.isPath value then
62
+
pkgs.runCommand "dconf-profile" { } ''
63
+
if [[ -d ${value} ]]; then
64
+
echo "Dconf profile should be a file but a directory is provided."
67
+
mkdir -p $out/etc/dconf/profile/
68
+
cp ${value} $out/etc/dconf/profile/${name}
71
+
pkgs.writeTextDir "etc/dconf/profile/${name}" (
72
+
lib.concatMapStrings (x: "${x}\n") ((
73
+
lib.optional value.enableUserDb "user-db:user"
78
+
db = if lib.isAttrs value && !lib.isDerivation value then mkDconfDb value else checkDconfDb value;
85
+
dconfDatabase = with lib.types; submodule {
87
+
keyfiles = lib.mkOption {
88
+
type = listOf (oneOf [ path package ]);
90
+
description = lib.mdDoc "A list of dconf keyfile directories.";
92
+
settings = lib.mkOption {
95
+
description = lib.mdDoc "An attrset used to generate dconf keyfile.";
96
+
example = literalExpression ''
99
+
"com/raggesilver/BlackBox" = {
100
+
scrollback-lines = mkUint32 10000;
101
+
theme-dark = "Tommorow Night";
109
+
dconfProfile = with lib.types; submodule {
111
+
enableUserDb = lib.mkOption {
114
+
description = lib.mdDoc "Add `user-db:user` at the beginning of the profile.";
117
+
databases = lib.mkOption {
118
+
type = with lib.types; listOf (oneOf [
124
+
description = lib.mdDoc ''
125
+
List of data sources for the profile. An element can be an attrset,
126
+
or the path of an already compiled database. Each element is converted
129
+
A key is searched from up to down and the first result takes the
130
+
priority. If a lock for a particular key is installed then the value from
131
+
the last database in the profile where the key is locked will be used.
132
+
This can be used to enforce mandatory settings.
···
type = with lib.types; attrsOf (oneOf [
23
-
description = lib.mdDoc "Attrset of dconf profiles.";
151
+
description = lib.mdDoc ''
152
+
Attrset of dconf profiles. By default the `user` profile is used which
153
+
ends up in `/etc/dconf/profile/user`.
155
+
example = lib.literalExpression ''
157
+
# A "user" profile with a database
163
+
# A "bar" profile from a package
164
+
bar = pkgs.bar-dconf-profile;
165
+
# A "foo" profile from a path
packages = lib.mkOption {