Skip to content

Commit 3219a92

Browse files
authored
Configure nix settings (#257)
Only manage /etc/nix/nix.conf options based on nixpkgs options. We cannot control nix-gc / nix-daemon services yet as they rely on users.
1 parent ba09b78 commit 3219a92

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

nix/modules/upstream/nixpkgs/default.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
imports =
88
[
99
./nginx.nix
10+
./nix.nix
1011
]
1112
++
1213
# List of imported NixOS modules
@@ -15,6 +16,8 @@
1516
"/misc/meta.nix"
1617
"/security/acme/"
1718
"/services/web-servers/nginx/"
19+
# nix settings
20+
"/config/nix.nix"
1821
];
1922

2023
options =
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{ lib, pkgs, ... }:
2+
{
3+
options = {
4+
# options coming from modules/services/system/nix-daemon.nix that we cannot import just yet because it
5+
# depends on users. These are the minimum options we need to be able to configure Nix using system-manager.
6+
nix = {
7+
enable = lib.mkOption {
8+
type = lib.types.bool;
9+
default = true;
10+
description = ''
11+
Whether to enable Nix.
12+
Disabling Nix makes the system hard to modify and the Nix programs and configuration will not be made available by NixOS itself.
13+
'';
14+
};
15+
package = lib.mkOption {
16+
type = lib.types.package;
17+
default = pkgs.nix;
18+
defaultText = lib.literalExpression "pkgs.nix";
19+
description = ''
20+
This option specifies the Nix package instance to use throughout the system.
21+
'';
22+
};
23+
};
24+
};
25+
}

test/nix/modules/default.nix

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,16 @@ let
134134
'';
135135
};
136136
};
137+
138+
nix = {
139+
settings = {
140+
experimental-features = [
141+
"nix-command"
142+
"flakes"
143+
];
144+
trusted-users = [ "zimbatm" ];
145+
};
146+
};
137147
};
138148
}
139149
)
@@ -149,7 +159,7 @@ forEachUbuntuImage "example" {
149159
];
150160
extraPathsToRegister = [ newConfig ];
151161
testScriptFunction =
152-
{ toplevel, ... }:
162+
{ toplevel, hostPkgs, ... }:
153163
#python
154164
''
155165
# Start all machines in parallel
@@ -223,6 +233,9 @@ forEachUbuntuImage "example" {
223233
vm.fail("test -f /etc/baz/bar/foo2")
224234
vm.succeed("test -f /etc/foo_new")
225235
236+
nix_trusted_users = vm.succeed("${hostPkgs.nix}/bin/nix config show trusted-users").strip()
237+
assert "zimbatm" in nix_trusted_users, f"Expected 'zimbatm' to be in trusted-users, got {nix_trusted_users}"
238+
226239
${system-manager.lib.deactivateProfileSnippet {
227240
node = "vm";
228241
profile = newConfig;

0 commit comments

Comments
 (0)