Skip to content

Commit 5dcbab6

Browse files
committed
nixos/tools: continue cleanup
- remove with lib - shuffle some things around for readability - add separate options for each tool
1 parent ee301a0 commit 5dcbab6

File tree

1 file changed

+171
-159
lines changed

1 file changed

+171
-159
lines changed

nixos/modules/installer/tools/tools.nix

+171-159
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
{ config, lib, pkgs, ... }:
55

6-
with lib;
7-
86
let
97
makeProg = args: pkgs.substituteAll (args // {
108
dir = "bin";
@@ -17,11 +15,6 @@ let
1715
'';
1816
});
1917

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-
2518
nixos-generate-config = makeProg {
2619
name = "nixos-generate-config";
2720
src = ./nixos-generate-config.pl;
@@ -34,8 +27,6 @@ let
3427
manPage = ./manpages/nixos-generate-config.8;
3528
};
3629

37-
inherit (pkgs) nixos-option;
38-
3930
nixos-version = makeProg {
4031
name = "nixos-version";
4132
src = ./nixos-version.sh;
@@ -44,23 +35,141 @@ let
4435
inherit (config.system) configurationRevision;
4536
json = builtins.toJSON ({
4637
nixosVersion = config.system.nixos.version;
47-
} // optionalAttrs (config.system.nixos.revision != null) {
38+
} // lib.optionalAttrs (config.system.nixos.revision != null) {
4839
nixpkgsRevision = config.system.nixos.revision;
49-
} // optionalAttrs (config.system.configurationRevision != null) {
40+
} // lib.optionalAttrs (config.system.configurationRevision != null) {
5041
configurationRevision = config.system.configurationRevision;
5142
});
5243
manPage = ./manpages/nixos-version.8;
5344
};
5445

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+
'';
56166
in
57-
58167
{
59-
60168
options.system.nixos-generate-config = {
61-
configuration = mkOption {
169+
configuration = lib.mkOption {
62170
internal = true;
63-
type = types.str;
171+
type = lib.types.str;
172+
default = defaultConfigTemplate;
64173
description = ''
65174
The NixOS module that `nixos-generate-config`
66175
saves to `/etc/nixos/configuration.nix`.
@@ -74,9 +183,9 @@ in
74183
'';
75184
};
76185

77-
desktopConfiguration = mkOption {
186+
desktopConfiguration = lib.mkOption {
78187
internal = true;
79-
type = types.listOf types.lines;
188+
type = lib.types.listOf lib.types.lines;
80189
default = [];
81190
description = ''
82191
Text to preseed the desktop configuration that `nixos-generate-config`
@@ -92,9 +201,9 @@ in
92201
};
93202
};
94203

95-
options.system.disableInstallerTools = mkOption {
204+
options.system.disableInstallerTools = lib.mkOption {
96205
internal = true;
97-
type = types.bool;
206+
type = lib.types.bool;
98207
default = false;
99208
description = ''
100209
Disable nixos-rebuild, nixos-generate-config, nixos-installer
@@ -104,145 +213,48 @@ in
104213
'';
105214
};
106215

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+
};
236222

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+
};
245226
};
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+
];
248260
}

0 commit comments

Comments
 (0)