3
3
4
4
{ config , lib , pkgs , ... } :
5
5
6
- with lib ;
7
-
8
6
let
9
7
makeProg = args : pkgs . substituteAll ( args // {
10
8
dir = "bin" ;
17
15
'' ;
18
16
} ) ;
19
17
20
- inherit ( pkgs ) nixos-build-vms ;
21
-
22
- nixos-install = pkgs . nixos-install . override { nix = config . nix . package ; } ;
23
- nixos-rebuild = pkgs . nixos-rebuild . override { nix = config . nix . package . out ; } ;
24
-
25
18
nixos-generate-config = makeProg {
26
19
name = "nixos-generate-config" ;
27
20
src = ./nixos-generate-config.pl ;
34
27
manPage = ./manpages/nixos-generate-config.8 ;
35
28
} ;
36
29
37
- inherit ( pkgs ) nixos-option ;
38
-
39
30
nixos-version = makeProg {
40
31
name = "nixos-version" ;
41
32
src = ./nixos-version.sh ;
44
35
inherit ( config . system ) configurationRevision ;
45
36
json = builtins . toJSON ( {
46
37
nixosVersion = config . system . nixos . version ;
47
- } // optionalAttrs ( config . system . nixos . revision != null ) {
38
+ } // lib . optionalAttrs ( config . system . nixos . revision != null ) {
48
39
nixpkgsRevision = config . system . nixos . revision ;
49
- } // optionalAttrs ( config . system . configurationRevision != null ) {
40
+ } // lib . optionalAttrs ( config . system . configurationRevision != null ) {
50
41
configurationRevision = config . system . configurationRevision ;
51
42
} ) ;
52
43
manPage = ./manpages/nixos-version.8 ;
53
44
} ;
54
45
55
- inherit ( pkgs ) nixos-enter ;
46
+ nixos-install = pkgs . nixos-install . override { nix = config . nix . package ; } ;
47
+ nixos-rebuild = pkgs . nixos-rebuild . override { nix = config . nix . package ; } ;
48
+
49
+ defaultConfigTemplate = ''
50
+ # Edit this configuration file to define what should be installed on
51
+ # your system. Help is available in the configuration.nix(5) man page, on
52
+ # https://search.nixos.org/options and in the NixOS manual (`nixos-help`).
53
+
54
+ { config, lib, pkgs, ... }:
55
+
56
+ {
57
+ imports =
58
+ [ # Include the results of the hardware scan.
59
+ ./hardware-configuration.nix
60
+ ];
61
+
62
+ $bootLoaderConfig
63
+ # networking.hostName = "nixos"; # Define your hostname.
64
+ # Pick only one of the below networking options.
65
+ # networking.wireless.enable = true; # Enables wireless support via wpa_supplicant.
66
+ # networking.networkmanager.enable = true; # Easiest to use and most distros use this by default.
67
+
68
+ # Set your time zone.
69
+ # time.timeZone = "Europe/Amsterdam";
70
+
71
+ # Configure network proxy if necessary
72
+ # networking.proxy.default = "http://user:password\@proxy:port/";
73
+ # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";
74
+
75
+ # Select internationalisation properties.
76
+ # i18n.defaultLocale = "en_US.UTF-8";
77
+ # console = {
78
+ # font = "Lat2-Terminus16";
79
+ # keyMap = "us";
80
+ # useXkbConfig = true; # use xkb.options in tty.
81
+ # };
82
+
83
+ $xserverConfig
84
+
85
+ $desktopConfiguration
86
+ # Configure keymap in X11
87
+ # services.xserver.xkb.layout = "us";
88
+ # services.xserver.xkb.options = "eurosign:e,caps:escape";
89
+
90
+ # Enable CUPS to print documents.
91
+ # services.printing.enable = true;
92
+
93
+ # Enable sound.
94
+ # hardware.pulseaudio.enable = true;
95
+ # OR
96
+ # services.pipewire = {
97
+ # enable = true;
98
+ # pulse.enable = true;
99
+ # };
100
+
101
+ # Enable touchpad support (enabled default in most desktopManager).
102
+ # services.libinput.enable = true;
103
+
104
+ # Define a user account. Don't forget to set a password with ‘passwd’.
105
+ # users.users.alice = {
106
+ # isNormalUser = true;
107
+ # extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user.
108
+ # packages = with pkgs; [
109
+ # firefox
110
+ # tree
111
+ # ];
112
+ # };
113
+
114
+ # List packages installed in system profile. To search, run:
115
+ # \$ nix search wget
116
+ # environment.systemPackages = with pkgs; [
117
+ # vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default.
118
+ # wget
119
+ # ];
120
+
121
+ # Some programs need SUID wrappers, can be configured further or are
122
+ # started in user sessions.
123
+ # programs.mtr.enable = true;
124
+ # programs.gnupg.agent = {
125
+ # enable = true;
126
+ # enableSSHSupport = true;
127
+ # };
128
+
129
+ # List services that you want to enable:
130
+
131
+ # Enable the OpenSSH daemon.
132
+ # services.openssh.enable = true;
133
+
134
+ # Open ports in the firewall.
135
+ # networking.firewall.allowedTCPPorts = [ ... ];
136
+ # networking.firewall.allowedUDPPorts = [ ... ];
137
+ # Or disable the firewall altogether.
138
+ # networking.firewall.enable = false;
139
+
140
+ # Copy the NixOS configuration file and link it from the resulting system
141
+ # (/run/current-system/configuration.nix). This is useful in case you
142
+ # accidentally delete configuration.nix.
143
+ # system.copySystemConfiguration = true;
144
+
145
+ # This option defines the first version of NixOS you have installed on this particular machine,
146
+ # and is used to maintain compatibility with application data (e.g. databases) created on older NixOS versions.
147
+ #
148
+ # Most users should NEVER change this value after the initial install, for any reason,
149
+ # even if you've upgraded your system to a new NixOS release.
150
+ #
151
+ # This value does NOT affect the Nixpkgs version your packages and OS are pulled from,
152
+ # so changing it will NOT upgrade your system - see https://nixos.org/manual/nixos/stable/#sec-upgrading for how
153
+ # to actually do that.
154
+ #
155
+ # This value being lower than the current NixOS release does NOT mean your system is
156
+ # out of date, out of support, or vulnerable.
157
+ #
158
+ # Do NOT change this value unless you have manually inspected all the changes it would make to your configuration,
159
+ # and migrated your data accordingly.
160
+ #
161
+ # For more information, see `man configuration.nix` or https://nixos.org/manual/nixos/stable/options#opt-system.stateVersion .
162
+ system.stateVersion = "${ config . system . nixos . release } "; # Did you read the comment?
163
+
164
+ }
165
+ '' ;
56
166
in
57
-
58
167
{
59
-
60
168
options . system . nixos-generate-config = {
61
- configuration = mkOption {
169
+ configuration = lib . mkOption {
62
170
internal = true ;
63
- type = types . str ;
171
+ type = lib . types . str ;
172
+ default = defaultConfigTemplate ;
64
173
description = ''
65
174
The NixOS module that `nixos-generate-config`
66
175
saves to `/etc/nixos/configuration.nix`.
74
183
'' ;
75
184
} ;
76
185
77
- desktopConfiguration = mkOption {
186
+ desktopConfiguration = lib . mkOption {
78
187
internal = true ;
79
- type = types . listOf types . lines ;
188
+ type = lib . types . listOf lib . types . lines ;
80
189
default = [ ] ;
81
190
description = ''
82
191
Text to preseed the desktop configuration that `nixos-generate-config`
92
201
} ;
93
202
} ;
94
203
95
- options . system . disableInstallerTools = mkOption {
204
+ options . system . disableInstallerTools = lib . mkOption {
96
205
internal = true ;
97
- type = types . bool ;
206
+ type = lib . types . bool ;
98
207
default = false ;
99
208
description = ''
100
209
Disable nixos-rebuild, nixos-generate-config, nixos-installer
@@ -104,145 +213,48 @@ in
104
213
'' ;
105
214
} ;
106
215
107
- config = lib . mkMerge [ ( lib . mkIf ( config . nix . enable && ! config . system . disableInstallerTools ) {
108
-
109
- system . nixos-generate-config . configuration = mkDefault ''
110
- # Edit this configuration file to define what should be installed on
111
- # your system. Help is available in the configuration.nix(5) man page, on
112
- # https://search.nixos.org/options and in the NixOS manual (`nixos-help`).
113
-
114
- { config, lib, pkgs, ... }:
115
-
116
- {
117
- imports =
118
- [ # Include the results of the hardware scan.
119
- ./hardware-configuration.nix
120
- ];
121
-
122
- $bootLoaderConfig
123
- # networking.hostName = "nixos"; # Define your hostname.
124
- # Pick only one of the below networking options.
125
- # networking.wireless.enable = true; # Enables wireless support via wpa_supplicant.
126
- # networking.networkmanager.enable = true; # Easiest to use and most distros use this by default.
127
-
128
- # Set your time zone.
129
- # time.timeZone = "Europe/Amsterdam";
130
-
131
- # Configure network proxy if necessary
132
- # networking.proxy.default = "http://user:password\@proxy:port/";
133
- # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";
134
-
135
- # Select internationalisation properties.
136
- # i18n.defaultLocale = "en_US.UTF-8";
137
- # console = {
138
- # font = "Lat2-Terminus16";
139
- # keyMap = "us";
140
- # useXkbConfig = true; # use xkb.options in tty.
141
- # };
142
-
143
- $xserverConfig
144
-
145
- $desktopConfiguration
146
- # Configure keymap in X11
147
- # services.xserver.xkb.layout = "us";
148
- # services.xserver.xkb.options = "eurosign:e,caps:escape";
149
-
150
- # Enable CUPS to print documents.
151
- # services.printing.enable = true;
152
-
153
- # Enable sound.
154
- # hardware.pulseaudio.enable = true;
155
- # OR
156
- # services.pipewire = {
157
- # enable = true;
158
- # pulse.enable = true;
159
- # };
160
-
161
- # Enable touchpad support (enabled default in most desktopManager).
162
- # services.libinput.enable = true;
163
-
164
- # Define a user account. Don't forget to set a password with ‘passwd’.
165
- # users.users.alice = {
166
- # isNormalUser = true;
167
- # extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user.
168
- # packages = with pkgs; [
169
- # firefox
170
- # tree
171
- # ];
172
- # };
173
-
174
- # List packages installed in system profile. To search, run:
175
- # \$ nix search wget
176
- # environment.systemPackages = with pkgs; [
177
- # vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default.
178
- # wget
179
- # ];
180
-
181
- # Some programs need SUID wrappers, can be configured further or are
182
- # started in user sessions.
183
- # programs.mtr.enable = true;
184
- # programs.gnupg.agent = {
185
- # enable = true;
186
- # enableSSHSupport = true;
187
- # };
188
-
189
- # List services that you want to enable:
190
-
191
- # Enable the OpenSSH daemon.
192
- # services.openssh.enable = true;
193
-
194
- # Open ports in the firewall.
195
- # networking.firewall.allowedTCPPorts = [ ... ];
196
- # networking.firewall.allowedUDPPorts = [ ... ];
197
- # Or disable the firewall altogether.
198
- # networking.firewall.enable = false;
199
-
200
- # Copy the NixOS configuration file and link it from the resulting system
201
- # (/run/current-system/configuration.nix). This is useful in case you
202
- # accidentally delete configuration.nix.
203
- # system.copySystemConfiguration = true;
204
-
205
- # This option defines the first version of NixOS you have installed on this particular machine,
206
- # and is used to maintain compatibility with application data (e.g. databases) created on older NixOS versions.
207
- #
208
- # Most users should NEVER change this value after the initial install, for any reason,
209
- # even if you've upgraded your system to a new NixOS release.
210
- #
211
- # This value does NOT affect the Nixpkgs version your packages and OS are pulled from,
212
- # so changing it will NOT upgrade your system - see https://nixos.org/manual/nixos/stable/#sec-upgrading for how
213
- # to actually do that.
214
- #
215
- # This value being lower than the current NixOS release does NOT mean your system is
216
- # out of date, out of support, or vulnerable.
217
- #
218
- # Do NOT change this value unless you have manually inspected all the changes it would make to your configuration,
219
- # and migrated your data accordingly.
220
- #
221
- # For more information, see `man configuration.nix` or https://nixos.org/manual/nixos/stable/options#opt-system.stateVersion .
222
- system.stateVersion = "${ config . system . nixos . release } "; # Did you read the comment?
223
-
224
- }
225
- '' ;
226
-
227
- environment . systemPackages =
228
- [ nixos-build-vms
229
- nixos-install
230
- nixos-rebuild
231
- nixos-generate-config
232
- nixos-option
233
- nixos-version
234
- nixos-enter
235
- ] ;
216
+ imports = let
217
+ mkToolModule = { name , package ? pkgs . ${ name } } : { config , ... } : {
218
+ options . system . tools . ${ name } . enable = lib . mkEnableOption "${ name } script" // {
219
+ default = true ;
220
+ internal = true ;
221
+ } ;
236
222
237
- documentation . man . man-db . skipPackages = [ nixos-version ] ;
238
-
239
- } )
240
-
241
- # These may be used in auxiliary scripts (ie not part of toplevel), so they are defined unconditionally.
242
- ( {
243
- system . build = {
244
- inherit nixos-install nixos-generate-config nixos-option nixos-rebuild nixos-enter ;
223
+ config = lib . mkIf config . system . tools . ${ name } . enable {
224
+ environment . systemPackages = [ package ] ;
225
+ } ;
245
226
} ;
246
- } ) ] ;
247
-
227
+ in [
228
+ ( mkToolModule { name = "nixos-build-vms" ; } )
229
+ ( mkToolModule { name = "nixos-enter" ; } )
230
+ ( mkToolModule { name = "nixos-generate-config" ; package = nixos-generate-config ; } )
231
+ ( mkToolModule { name = "nixos-install" ; package = nixos-install ; } )
232
+ ( mkToolModule { name = "nixos-option" ; } )
233
+ ( mkToolModule { name = "nixos-rebuild" ; package = nixos-rebuild ; } )
234
+ ( mkToolModule { name = "nixos-version" ; package = nixos-version ; } )
235
+ ] ;
236
+
237
+ config = lib . mkMerge [
238
+ ( lib . mkIf config . system . disableInstallerTools {
239
+ system . tools = {
240
+ nixos-build-vms . enable = false ;
241
+ nixos-enter . enable = false ;
242
+ nixos-generate-config . enable = false ;
243
+ nixos-install . enable = false ;
244
+ nixos-option . enable = false ;
245
+ nixos-rebuild . enable = false ;
246
+ nixos-version . enable = false ;
247
+ } ;
248
+ } )
249
+ {
250
+ documentation . man . man-db . skipPackages = [ nixos-version ] ;
251
+
252
+ # These may be used in auxiliary scripts (ie not part of toplevel), so they are defined unconditionally.
253
+ system . build = {
254
+ inherit nixos-generate-config nixos-install nixos-rebuild ;
255
+ nixos-option = lib . warn "Accessing nixos-option through `config.system.build` is deprecated, use `pkgs.nixos-option` instead." pkgs . nixos-option ;
256
+ nixos-enter = lib . warn "Accessing nixos-enter through `config.system.build` is deprecated, use `pkgs.nixos-enter` instead." pkgs . nixos-enter ;
257
+ } ;
258
+ }
259
+ ] ;
248
260
}
0 commit comments