at 23.05-pre 8.0 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 }); 13 14 nixos-build-vms = makeProg { 15 name = "nixos-build-vms"; 16 src = ./nixos-build-vms/nixos-build-vms.sh; 17 inherit (pkgs) runtimeShell; 18 }; 19 20 nixos-install = makeProg { 21 name = "nixos-install"; 22 src = ./nixos-install.sh; 23 inherit (pkgs) runtimeShell; 24 nix = config.nix.package.out; 25 path = makeBinPath [ 26 pkgs.jq 27 nixos-enter 28 ]; 29 }; 30 31 nixos-rebuild = pkgs.nixos-rebuild.override { nix = config.nix.package.out; }; 32 33 nixos-generate-config = makeProg { 34 name = "nixos-generate-config"; 35 src = ./nixos-generate-config.pl; 36 perl = "${pkgs.perl.withPackages (p: [ p.FileSlurp ])}/bin/perl"; 37 nixInstantiate = "${pkgs.nix}/bin/nix-instantiate"; 38 detectvirt = "${config.systemd.package}/bin/systemd-detect-virt"; 39 btrfs = "${pkgs.btrfs-progs}/bin/btrfs"; 40 inherit (config.system.nixos-generate-config) configuration desktopConfiguration; 41 xserverEnabled = config.services.xserver.enable; 42 }; 43 44 nixos-option = 45 if lib.versionAtLeast (lib.getVersion config.nix.package) "2.4pre" 46 then null 47 else pkgs.nixos-option; 48 49 nixos-version = makeProg { 50 name = "nixos-version"; 51 src = ./nixos-version.sh; 52 inherit (pkgs) runtimeShell; 53 inherit (config.system.nixos) version codeName revision; 54 inherit (config.system) configurationRevision; 55 json = builtins.toJSON ({ 56 nixosVersion = config.system.nixos.version; 57 } // optionalAttrs (config.system.nixos.revision != null) { 58 nixpkgsRevision = config.system.nixos.revision; 59 } // optionalAttrs (config.system.configurationRevision != null) { 60 configurationRevision = config.system.configurationRevision; 61 }); 62 }; 63 64 nixos-enter = makeProg { 65 name = "nixos-enter"; 66 src = ./nixos-enter.sh; 67 inherit (pkgs) runtimeShell; 68 }; 69 70in 71 72{ 73 74 options.system.nixos-generate-config = { 75 configuration = mkOption { 76 internal = true; 77 type = types.str; 78 description = lib.mdDoc '' 79 The NixOS module that `nixos-generate-config` 80 saves to `/etc/nixos/configuration.nix`. 81 82 This is an internal option. No backward compatibility is guaranteed. 83 Use at your own risk! 84 85 Note that this string gets spliced into a Perl script. The perl 86 variable `$bootLoaderConfig` can be used to 87 splice in the boot loader configuration. 88 ''; 89 }; 90 91 desktopConfiguration = mkOption { 92 internal = true; 93 type = types.listOf types.lines; 94 default = []; 95 description = lib.mdDoc '' 96 Text to preseed the desktop configuration that `nixos-generate-config` 97 saves to `/etc/nixos/configuration.nix`. 98 99 This is an internal option. No backward compatibility is guaranteed. 100 Use at your own risk! 101 102 Note that this string gets spliced into a Perl script. The perl 103 variable `$bootLoaderConfig` can be used to 104 splice in the boot loader configuration. 105 ''; 106 }; 107 }; 108 109 options.system.disableInstallerTools = mkOption { 110 internal = true; 111 type = types.bool; 112 default = false; 113 description = lib.mdDoc '' 114 Disable nixos-rebuild, nixos-generate-config, nixos-installer 115 and other NixOS tools. This is useful to shrink embedded, 116 read-only systems which are not expected to be rebuild or 117 reconfigure themselves. Use at your own risk! 118 ''; 119 }; 120 121 config = lib.mkIf (config.nix.enable && !config.system.disableInstallerTools) { 122 123 system.nixos-generate-config.configuration = mkDefault '' 124 # Edit this configuration file to define what should be installed on 125 # your system. Help is available in the configuration.nix(5) man page 126 # and in the NixOS manual (accessible by running nixos-help). 127 128 { config, pkgs, ... }: 129 130 { 131 imports = 132 [ # Include the results of the hardware scan. 133 ./hardware-configuration.nix 134 ]; 135 136 $bootLoaderConfig 137 # networking.hostName = "nixos"; # Define your hostname. 138 # Pick only one of the below networking options. 139 # networking.wireless.enable = true; # Enables wireless support via wpa_supplicant. 140 # networking.networkmanager.enable = true; # Easiest to use and most distros use this by default. 141 142 # Set your time zone. 143 # time.timeZone = "Europe/Amsterdam"; 144 145 # Configure network proxy if necessary 146 # networking.proxy.default = "http://user:password\@proxy:port/"; 147 # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain"; 148 149 # Select internationalisation properties. 150 # i18n.defaultLocale = "en_US.UTF-8"; 151 # console = { 152 # font = "Lat2-Terminus16"; 153 # keyMap = "us"; 154 # useXkbConfig = true; # use xkbOptions in tty. 155 # }; 156 157 $xserverConfig 158 159 $desktopConfiguration 160 # Configure keymap in X11 161 # services.xserver.layout = "us"; 162 # services.xserver.xkbOptions = { 163 # "eurosign:e"; 164 # "caps:escape" # map caps to escape. 165 # }; 166 167 # Enable CUPS to print documents. 168 # services.printing.enable = true; 169 170 # Enable sound. 171 # sound.enable = true; 172 # hardware.pulseaudio.enable = true; 173 174 # Enable touchpad support (enabled default in most desktopManager). 175 # services.xserver.libinput.enable = true; 176 177 # Define a user account. Don't forget to set a password with passwd. 178 # users.users.alice = { 179 # isNormalUser = true; 180 # extraGroups = [ "wheel" ]; # Enable sudo for the user. 181 # packages = with pkgs; [ 182 # firefox 183 # thunderbird 184 # ]; 185 # }; 186 187 # List packages installed in system profile. To search, run: 188 # \$ nix search wget 189 # environment.systemPackages = with pkgs; [ 190 # vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default. 191 # wget 192 # ]; 193 194 # Some programs need SUID wrappers, can be configured further or are 195 # started in user sessions. 196 # programs.mtr.enable = true; 197 # programs.gnupg.agent = { 198 # enable = true; 199 # enableSSHSupport = true; 200 # }; 201 202 # List services that you want to enable: 203 204 # Enable the OpenSSH daemon. 205 # services.openssh.enable = true; 206 207 # Open ports in the firewall. 208 # networking.firewall.allowedTCPPorts = [ ... ]; 209 # networking.firewall.allowedUDPPorts = [ ... ]; 210 # Or disable the firewall altogether. 211 # networking.firewall.enable = false; 212 213 # Copy the NixOS configuration file and link it from the resulting system 214 # (/run/current-system/configuration.nix). This is useful in case you 215 # accidentally delete configuration.nix. 216 # system.copySystemConfiguration = true; 217 218 # This value determines the NixOS release from which the default 219 # settings for stateful data, like file locations and database versions 220 # on your system were taken. Its perfectly fine and recommended to leave 221 # this value at the release version of the first install of this system. 222 # Before changing this value read the documentation for this option 223 # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html). 224 system.stateVersion = "${config.system.nixos.release}"; # Did you read the comment? 225 226 } 227 ''; 228 229 environment.systemPackages = 230 [ nixos-build-vms 231 nixos-install 232 nixos-rebuild 233 nixos-generate-config 234 nixos-version 235 nixos-enter 236 ] ++ lib.optional (nixos-option != null) nixos-option; 237 238 system.build = { 239 inherit nixos-install nixos-generate-config nixos-option nixos-rebuild nixos-enter; 240 }; 241 242 }; 243 244}