Merge pull request #10996 from oxij/nixos-label

nixos: introduce system.nixosLabel support

+77 -39
+1 -1
nixos/modules/installer/cd-dvd/installation-cd-base.nix
··· 16 ]; 17 18 # ISO naming. 19 - isoImage.isoName = "${config.isoImage.isoBaseName}-${config.system.nixosVersion}-${pkgs.stdenv.system}.iso"; 20 21 isoImage.volumeID = substring 0 11 "NIXOS_ISO"; 22
··· 16 ]; 17 18 # ISO naming. 19 + isoImage.isoName = "${config.isoImage.isoBaseName}-${config.system.nixosLabel}-${pkgs.stdenv.system}.iso"; 20 21 isoImage.volumeID = substring 0 11 "NIXOS_ISO"; 22
+1 -1
nixos/modules/installer/cd-dvd/iso-image.nix
··· 39 DEFAULT boot 40 41 LABEL boot 42 - MENU LABEL NixOS ${config.system.nixosVersion}${config.isoImage.appendToMenuLabel} 43 LINUX /boot/bzImage 44 APPEND init=${config.system.build.toplevel}/init ${toString config.boot.kernelParams} 45 INITRD /boot/initrd
··· 39 DEFAULT boot 40 41 LABEL boot 42 + MENU LABEL NixOS ${config.system.nixosLabel}${config.isoImage.appendToMenuLabel} 43 LINUX /boot/bzImage 44 APPEND init=${config.system.build.toplevel}/init ${toString config.boot.kernelParams} 45 INITRD /boot/initrd
+51 -21
nixos/modules/misc/version.nix
··· 2 3 with lib; 4 5 { 6 7 - options = { 8 9 - system.stateVersion = mkOption { 10 type = types.str; 11 - default = config.system.nixosRelease; 12 description = '' 13 Every once in a while, a new NixOS release may change 14 configuration defaults in a way incompatible with stateful ··· 22 ''; 23 }; 24 25 - system.nixosVersion = mkOption { 26 internal = true; 27 type = types.str; 28 description = "NixOS version."; 29 }; 30 31 - system.nixosRelease = mkOption { 32 readOnly = true; 33 type = types.str; 34 - default = readFile "${toString pkgs.path}/.version"; 35 description = "NixOS release."; 36 }; 37 38 - system.nixosVersionSuffix = mkOption { 39 internal = true; 40 type = types.str; 41 description = "NixOS version suffix."; 42 }; 43 44 - system.nixosRevision = mkOption { 45 internal = true; 46 type = types.str; 47 description = "NixOS Git revision hash."; 48 }; 49 50 - system.nixosCodeName = mkOption { 51 readOnly = true; 52 type = types.str; 53 description = "NixOS release code name."; 54 }; 55 56 - system.defaultChannel = mkOption { 57 internal = true; 58 type = types.str; 59 default = https://nixos.org/channels/nixos-unstable; ··· 64 65 config = { 66 67 - system.nixosVersion = mkDefault (config.system.nixosRelease + config.system.nixosVersionSuffix); 68 - 69 - system.nixosVersionSuffix = 70 - let suffixFile = "${toString pkgs.path}/.version-suffix"; in 71 - mkDefault (if pathExists suffixFile then readFile suffixFile else "pre-git"); 72 - 73 - system.nixosRevision = 74 - let fn = "${toString pkgs.path}/.git-revision"; in 75 - mkDefault (if pathExists fn then readFile fn else "master"); 76 77 - # Note: code names must only increase in alphabetical order. 78 - system.nixosCodeName = "Emu"; 79 80 # Generate /etc/os-release. See 81 # http://0pointer.de/public/systemd-man/os-release.html for the
··· 2 3 with lib; 4 5 + let 6 + cfg = config.system; 7 + 8 + releaseFile = "${toString pkgs.path}/.version"; 9 + suffixFile = "${toString pkgs.path}/.version-suffix"; 10 + revisionFile = "${toString pkgs.path}/.git-revision"; 11 + in 12 + 13 { 14 15 + options.system = { 16 17 + stateVersion = mkOption { 18 type = types.str; 19 + default = cfg.nixosRelease; 20 description = '' 21 Every once in a while, a new NixOS release may change 22 configuration defaults in a way incompatible with stateful ··· 30 ''; 31 }; 32 33 + nixosLabel = mkOption { 34 + type = types.str; 35 + description = '' 36 + NixOS version name to be used in the names of generated 37 + outputs and boot labels. 38 + 39 + If you ever wanted to influence the labels in your GRUB menu, 40 + this is option is for you. 41 + 42 + Can be set directly or with <envar>NIXOS_LABEL</envar> 43 + environment variable for <command>nixos-rebuild</command>, 44 + e.g.: 45 + 46 + <screen> 47 + #!/bin/sh 48 + today=`date +%Y%m%d` 49 + branch=`(cd nixpkgs ; git branch 2>/dev/null | sed -n '/^\* / { s|^\* ||; p; }')` 50 + revision=`(cd nixpkgs ; git rev-parse HEAD)` 51 + export NIXOS_LABEL="$today.$branch-''${revision:0:7}" 52 + nixos-rebuild switch</screen> 53 + ''; 54 + }; 55 + 56 + nixosVersion = mkOption { 57 internal = true; 58 type = types.str; 59 description = "NixOS version."; 60 }; 61 62 + nixosRelease = mkOption { 63 readOnly = true; 64 type = types.str; 65 + default = readFile releaseFile; 66 description = "NixOS release."; 67 }; 68 69 + nixosVersionSuffix = mkOption { 70 internal = true; 71 type = types.str; 72 + default = if pathExists suffixFile then readFile suffixFile else "pre-git"; 73 description = "NixOS version suffix."; 74 }; 75 76 + nixosRevision = mkOption { 77 internal = true; 78 type = types.str; 79 + default = if pathExists revisionFile then readFile revisionFile else "master"; 80 description = "NixOS Git revision hash."; 81 }; 82 83 + nixosCodeName = mkOption { 84 readOnly = true; 85 type = types.str; 86 description = "NixOS release code name."; 87 }; 88 89 + defaultChannel = mkOption { 90 internal = true; 91 type = types.str; 92 default = https://nixos.org/channels/nixos-unstable; ··· 97 98 config = { 99 100 + system = { 101 + # These defaults are set here rather than up there so that 102 + # changing them would not rebuild the manual 103 + nixosLabel = mkDefault (maybeEnv "NIXOS_LABEL" cfg.nixosVersion); 104 + nixosVersion = mkDefault (maybeEnv "NIXOS_VERSION" (cfg.nixosRelease + cfg.nixosVersionSuffix)); 105 106 + # Note: code names must only increase in alphabetical order. 107 + nixosCodeName = "Emu"; 108 + }; 109 110 # Generate /etc/os-release. See 111 # http://0pointer.de/public/systemd-man/os-release.html for the
+14 -6
nixos/modules/services/ttys/agetty.nix
··· 2 3 with lib; 4 5 { 6 7 ###### interface ··· 21 22 greetingLine = mkOption { 23 type = types.str; 24 - default = ''<<< Welcome to NixOS ${config.system.nixosVersion} (\m) - \l >>>''; 25 description = '' 26 Welcome line printed by mingetty. 27 ''; 28 }; 29 ··· 55 56 ###### implementation 57 58 - config = let 59 - autologinArg = optionalString (config.services.mingetty.autologinUser != null) "--autologin ${config.services.mingetty.autologinUser}"; 60 - gettyCmd = extraArgs: "@${pkgs.utillinux}/sbin/agetty agetty --login-program ${pkgs.shadow}/bin/login ${autologinArg} ${extraArgs}"; 61 - in { 62 systemd.services."getty@" = 63 { serviceConfig.ExecStart = gettyCmd "--noclear --keep-baud %I 115200,38400,9600 $TERM"; 64 restartIfChanged = false; ··· 81 { serviceConfig.ExecStart = gettyCmd "--noclear --keep-baud console 115200,38400,9600 $TERM"; 82 serviceConfig.Restart = "always"; 83 restartIfChanged = false; 84 - enable = mkDefault config.boot.isContainer; 85 }; 86 87 environment.etc = singleton
··· 2 3 with lib; 4 5 + let 6 + 7 + autologinArg = optionalString (config.services.mingetty.autologinUser != null) "--autologin ${config.services.mingetty.autologinUser}"; 8 + gettyCmd = extraArgs: "@${pkgs.utillinux}/sbin/agetty agetty --login-program ${pkgs.shadow}/bin/login ${autologinArg} ${extraArgs}"; 9 + 10 + in 11 + 12 { 13 14 ###### interface ··· 28 29 greetingLine = mkOption { 30 type = types.str; 31 description = '' 32 Welcome line printed by mingetty. 33 + The default shows current NixOS version label, machine type and tty. 34 ''; 35 }; 36 ··· 62 63 ###### implementation 64 65 + config = { 66 + # Note: this is set here rather than up there so that changing 67 + # nixosLabel would not rebuild manual pages 68 + services.mingetty.greetingLine = mkDefault ''<<< Welcome to NixOS ${config.system.nixosLabel} (\m) - \l >>>''; 69 + 70 systemd.services."getty@" = 71 { serviceConfig.ExecStart = gettyCmd "--noclear --keep-baud %I 115200,38400,9600 $TERM"; 72 restartIfChanged = false; ··· 89 { serviceConfig.ExecStart = gettyCmd "--noclear --keep-baud console 115200,38400,9600 $TERM"; 90 serviceConfig.Restart = "always"; 91 restartIfChanged = false; 92 + enable = mkDefault config.boot.isContainer; 93 }; 94 95 environment.etc = singleton
+3 -3
nixos/modules/system/activation/top-level.nix
··· 67 68 echo -n "$configurationName" > $out/configuration-name 69 echo -n "systemd ${toString config.systemd.package.interfaceVersion}" > $out/init-interface-version 70 - echo -n "$nixosVersion" > $out/nixos-version 71 echo -n "$system" > $out/system 72 73 mkdir $out/fine-tune ··· 101 if [] == failed then pkgs.stdenv.mkDerivation { 102 name = let hn = config.networking.hostName; 103 nn = if (hn != "") then hn else "unnamed"; 104 - in "nixos-system-${nn}-${config.system.nixosVersion}"; 105 preferLocalBuild = true; 106 allowSubstitutes = false; 107 buildCommand = systemBuilder; ··· 115 config.system.build.installBootLoader 116 or "echo 'Warning: do not know how to make this configuration bootable; please enable a boot loader.' 1>&2; true"; 117 activationScript = config.system.activationScripts.script; 118 - nixosVersion = config.system.nixosVersion; 119 120 configurationName = config.boot.loader.grub.configurationName; 121
··· 67 68 echo -n "$configurationName" > $out/configuration-name 69 echo -n "systemd ${toString config.systemd.package.interfaceVersion}" > $out/init-interface-version 70 + echo -n "$nixosLabel" > $out/nixos-version 71 echo -n "$system" > $out/system 72 73 mkdir $out/fine-tune ··· 101 if [] == failed then pkgs.stdenv.mkDerivation { 102 name = let hn = config.networking.hostName; 103 nn = if (hn != "") then hn else "unnamed"; 104 + in "nixos-system-${nn}-${config.system.nixosLabel}"; 105 preferLocalBuild = true; 106 allowSubstitutes = false; 107 buildCommand = systemBuilder; ··· 115 config.system.build.installBootLoader 116 or "echo 'Warning: do not know how to make this configuration bootable; please enable a boot loader.' 1>&2; true"; 117 activationScript = config.system.activationScripts.script; 118 + nixosLabel = config.system.nixosLabel; 119 120 configurationName = config.boot.loader.grub.configurationName; 121
+2 -2
nixos/modules/system/boot/loader/generic-extlinux-compatible/extlinux-conf-builder.sh
··· 83 timestampEpoch=$(stat -L -c '%Z' $path) 84 85 timestamp=$(date "+%Y-%m-%d %H:%M" -d @$timestampEpoch) 86 - nixosVersion="$(cat $path/nixos-version)" 87 extraParams="$(cat $path/kernel-params)" 88 89 echo ··· 91 if [ "$tag" = "default" ]; then 92 echo " MENU LABEL NixOS - Default" 93 else 94 - echo " MENU LABEL NixOS - Configuration $tag ($timestamp - $nixosVersion)" 95 fi 96 echo " LINUX ../nixos/$(basename $kernel)" 97 echo " INITRD ../nixos/$(basename $initrd)"
··· 83 timestampEpoch=$(stat -L -c '%Z' $path) 84 85 timestamp=$(date "+%Y-%m-%d %H:%M" -d @$timestampEpoch) 86 + nixosLabel="$(cat $path/nixos-version)" 87 extraParams="$(cat $path/kernel-params)" 88 89 echo ··· 91 if [ "$tag" = "default" ]; then 92 echo " MENU LABEL NixOS - Default" 93 else 94 + echo " MENU LABEL NixOS - Configuration $tag ($timestamp - $nixosLabel)" 95 fi 96 echo " LINUX ../nixos/$(basename $kernel)" 97 echo " INITRD ../nixos/$(basename $initrd)"
+1 -1
nixos/modules/virtualisation/azure-image.nix
··· 26 ${pkgs.vmTools.qemu}/bin/qemu-img convert -f raw -O vpc $diskImage $out/disk.vhd 27 rm $diskImage 28 ''; 29 - diskImageBase = "nixos-image-${config.system.nixosVersion}-${pkgs.stdenv.system}.raw"; 30 buildInputs = [ pkgs.utillinux pkgs.perl ]; 31 exportReferencesGraph = 32 [ "closure" config.system.build.toplevel ];
··· 26 ${pkgs.vmTools.qemu}/bin/qemu-img convert -f raw -O vpc $diskImage $out/disk.vhd 27 rm $diskImage 28 ''; 29 + diskImageBase = "nixos-image-${config.system.nixosLabel}-${pkgs.stdenv.system}.raw"; 30 buildInputs = [ pkgs.utillinux pkgs.perl ]; 31 exportReferencesGraph = 32 [ "closure" config.system.build.toplevel ];
+1 -1
nixos/modules/virtualisation/brightbox-image.nix
··· 26 rm $diskImageBase 27 popd 28 ''; 29 - diskImageBase = "nixos-image-${config.system.nixosVersion}-${pkgs.stdenv.system}.raw"; 30 buildInputs = [ pkgs.utillinux pkgs.perl ]; 31 exportReferencesGraph = 32 [ "closure" config.system.build.toplevel ];
··· 26 rm $diskImageBase 27 popd 28 ''; 29 + diskImageBase = "nixos-image-${config.system.nixosLabel}-${pkgs.stdenv.system}.raw"; 30 buildInputs = [ pkgs.utillinux pkgs.perl ]; 31 exportReferencesGraph = 32 [ "closure" config.system.build.toplevel ];
+1 -1
nixos/modules/virtualisation/google-compute-image.nix
··· 30 rm $out/disk.raw 31 popd 32 ''; 33 - diskImageBase = "nixos-image-${config.system.nixosVersion}-${pkgs.stdenv.system}.raw"; 34 buildInputs = [ pkgs.utillinux pkgs.perl ]; 35 exportReferencesGraph = 36 [ "closure" config.system.build.toplevel ];
··· 30 rm $out/disk.raw 31 popd 32 ''; 33 + diskImageBase = "nixos-image-${config.system.nixosLabel}-${pkgs.stdenv.system}.raw"; 34 buildInputs = [ pkgs.utillinux pkgs.perl ]; 35 exportReferencesGraph = 36 [ "closure" config.system.build.toplevel ];
+2 -2
nixos/modules/virtualisation/virtualbox-image.nix
··· 44 45 system.build.virtualBoxOVA = pkgs.runCommand "virtualbox-ova" 46 { buildInputs = [ pkgs.linuxPackages.virtualbox ]; 47 - vmName = "NixOS ${config.system.nixosVersion} (${pkgs.stdenv.system})"; 48 - fileName = "nixos-image-${config.system.nixosVersion}-${pkgs.stdenv.system}.ova"; 49 } 50 '' 51 echo "creating VirtualBox VM..."
··· 44 45 system.build.virtualBoxOVA = pkgs.runCommand "virtualbox-ova" 46 { buildInputs = [ pkgs.linuxPackages.virtualbox ]; 47 + vmName = "NixOS ${config.system.nixosLabel} (${pkgs.stdenv.system})"; 48 + fileName = "nixos-image-${config.system.nixosLabel}-${pkgs.stdenv.system}.ova"; 49 } 50 '' 51 echo "creating VirtualBox VM..."