1 # This module generates nixos-install, nixos-rebuild,
2 # nixos-generate-config, etc.
4 { config, lib, pkgs, ... }:
7 makeProg = args: pkgs.substituteAll (args // {
11 pkgs.installShellFiles
14 installManPage ${args.manPage}
18 nixos-generate-config = makeProg {
19 name = "nixos-generate-config";
20 src = ./nixos-generate-config.pl;
21 perl = "${pkgs.perl.withPackages (p: [ p.FileSlurp ])}/bin/perl";
22 hostPlatformSystem = pkgs.stdenv.hostPlatform.system;
23 detectvirt = "${config.systemd.package}/bin/systemd-detect-virt";
24 btrfs = "${pkgs.btrfs-progs}/bin/btrfs";
25 inherit (config.system.nixos-generate-config) configuration desktopConfiguration;
26 xserverEnabled = config.services.xserver.enable;
27 manPage = ./manpages/nixos-generate-config.8;
30 nixos-version = makeProg {
31 name = "nixos-version";
32 src = ./nixos-version.sh;
33 inherit (pkgs) runtimeShell;
34 inherit (config.system.nixos) version codeName revision;
35 inherit (config.system) configurationRevision;
36 json = builtins.toJSON ({
37 nixosVersion = config.system.nixos.version;
38 } // lib.optionalAttrs (config.system.nixos.revision != null) {
39 nixpkgsRevision = config.system.nixos.revision;
40 } // lib.optionalAttrs (config.system.configurationRevision != null) {
41 configurationRevision = config.system.configurationRevision;
43 manPage = ./manpages/nixos-version.8;
46 nixos-install = pkgs.nixos-install.override { nix = config.nix.package; };
47 nixos-rebuild = pkgs.nixos-rebuild.override { nix = config.nix.package; };
48 nixos-rebuild-ng = pkgs.nixos-rebuild-ng.override {
49 nix = config.nix.package;
54 defaultConfigTemplate = ''
55 # Edit this configuration file to define what should be installed on
56 # your system. Help is available in the configuration.nix(5) man page, on
57 # https://search.nixos.org/options and in the NixOS manual (`nixos-help`).
59 { config, lib, pkgs, ... }:
63 [ # Include the results of the hardware scan.
64 ./hardware-configuration.nix
68 # networking.hostName = "nixos"; # Define your hostname.
69 # Pick only one of the below networking options.
70 # networking.wireless.enable = true; # Enables wireless support via wpa_supplicant.
71 # networking.networkmanager.enable = true; # Easiest to use and most distros use this by default.
74 # time.timeZone = "Europe/Amsterdam";
76 # Configure network proxy if necessary
77 # networking.proxy.default = "http://user:password\@proxy:port/";
78 # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";
80 # Select internationalisation properties.
81 # i18n.defaultLocale = "en_US.UTF-8";
83 # font = "Lat2-Terminus16";
85 # useXkbConfig = true; # use xkb.options in tty.
91 # Configure keymap in X11
92 # services.xserver.xkb.layout = "us";
93 # services.xserver.xkb.options = "eurosign:e,caps:escape";
95 # Enable CUPS to print documents.
96 # services.printing.enable = true;
99 # hardware.pulseaudio.enable = true;
101 # services.pipewire = {
103 # pulse.enable = true;
106 # Enable touchpad support (enabled default in most desktopManager).
107 # services.libinput.enable = true;
109 # Define a user account. Don't forget to set a password with ‘passwd’.
110 # users.users.alice = {
111 # isNormalUser = true;
112 # extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user.
113 # packages = with pkgs; [
118 # programs.firefox.enable = true;
120 # List packages installed in system profile. To search, run:
122 # environment.systemPackages = with pkgs; [
123 # vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default.
127 # Some programs need SUID wrappers, can be configured further or are
128 # started in user sessions.
129 # programs.mtr.enable = true;
130 # programs.gnupg.agent = {
132 # enableSSHSupport = true;
135 # List services that you want to enable:
137 # Enable the OpenSSH daemon.
138 # services.openssh.enable = true;
140 # Open ports in the firewall.
141 # networking.firewall.allowedTCPPorts = [ ... ];
142 # networking.firewall.allowedUDPPorts = [ ... ];
143 # Or disable the firewall altogether.
144 # networking.firewall.enable = false;
146 # Copy the NixOS configuration file and link it from the resulting system
147 # (/run/current-system/configuration.nix). This is useful in case you
148 # accidentally delete configuration.nix.
149 # system.copySystemConfiguration = true;
151 # This option defines the first version of NixOS you have installed on this particular machine,
152 # and is used to maintain compatibility with application data (e.g. databases) created on older NixOS versions.
154 # Most users should NEVER change this value after the initial install, for any reason,
155 # even if you've upgraded your system to a new NixOS release.
157 # This value does NOT affect the Nixpkgs version your packages and OS are pulled from,
158 # so changing it will NOT upgrade your system - see https://nixos.org/manual/nixos/stable/#sec-upgrading for how
159 # to actually do that.
161 # This value being lower than the current NixOS release does NOT mean your system is
162 # out of date, out of support, or vulnerable.
164 # Do NOT change this value unless you have manually inspected all the changes it would make to your configuration,
165 # and migrated your data accordingly.
167 # For more information, see `man configuration.nix` or https://nixos.org/manual/nixos/stable/options#opt-system.stateVersion .
168 system.stateVersion = "${config.system.nixos.release}"; # Did you read the comment?
174 options.system.nixos-generate-config = {
175 configuration = lib.mkOption {
177 type = lib.types.str;
178 default = defaultConfigTemplate;
180 The NixOS module that `nixos-generate-config`
181 saves to `/etc/nixos/configuration.nix`.
183 This is an internal option. No backward compatibility is guaranteed.
184 Use at your own risk!
186 Note that this string gets spliced into a Perl script. The perl
187 variable `$bootLoaderConfig` can be used to
188 splice in the boot loader configuration.
192 desktopConfiguration = lib.mkOption {
194 type = lib.types.listOf lib.types.lines;
197 Text to preseed the desktop configuration that `nixos-generate-config`
198 saves to `/etc/nixos/configuration.nix`.
200 This is an internal option. No backward compatibility is guaranteed.
201 Use at your own risk!
203 Note that this string gets spliced into a Perl script. The perl
204 variable `$bootLoaderConfig` can be used to
205 splice in the boot loader configuration.
210 options.system.disableInstallerTools = lib.mkOption {
212 type = lib.types.bool;
215 Disable nixos-rebuild, nixos-generate-config, nixos-installer
216 and other NixOS tools. This is useful to shrink embedded,
217 read-only systems which are not expected to be rebuild or
218 reconfigure themselves. Use at your own risk!
222 options.system.rebuild.enableNg = lib.mkEnableOption "" // {
224 Whether to use ‘nixos-rebuild-ng’ in place of ‘nixos-rebuild’, the
225 Python-based re-implementation of the original in Bash.
230 mkToolModule = { name, package ? pkgs.${name} }: { config, ... }: {
231 options.system.tools.${name}.enable = lib.mkEnableOption "${name} script" // {
232 default = config.nix.enable && ! config.system.disableInstallerTools;
233 defaultText = "config.nix.enable && !config.system.disableInstallerTools";
236 config = lib.mkIf config.system.tools.${name}.enable {
237 environment.systemPackages = [ package ];
241 (mkToolModule { name = "nixos-build-vms"; })
242 (mkToolModule { name = "nixos-enter"; })
243 (mkToolModule { name = "nixos-generate-config"; package = config.system.build.nixos-generate-config; })
244 (mkToolModule { name = "nixos-install"; package = config.system.build.nixos-install; })
245 (mkToolModule { name = "nixos-option"; })
246 (mkToolModule { name = "nixos-rebuild"; package = config.system.build.nixos-rebuild; })
247 (mkToolModule { name = "nixos-version"; package = nixos-version; })
251 documentation.man.man-db.skipPackages = [ nixos-version ];
253 # These may be used in auxiliary scripts (ie not part of toplevel), so they are defined unconditionally.
255 inherit nixos-generate-config nixos-install;
257 if config.system.rebuild.enableNg
258 then nixos-rebuild-ng
260 nixos-option = lib.warn "Accessing nixos-option through `config.system.build` is deprecated, use `pkgs.nixos-option` instead." pkgs.nixos-option;
261 nixos-enter = lib.warn "Accessing nixos-enter through `config.system.build` is deprecated, use `pkgs.nixos-enter` instead." pkgs.nixos-enter;