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