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