Merge pull request #10996 from oxij/nixos-label

nixos: introduce system.nixosLabel support

Changed files
+77 -39
nixos
modules
installer
misc
services
ttys
system
activation
boot
loader
generic-extlinux-compatible
virtualisation
+1 -1
nixos/modules/installer/cd-dvd/installation-cd-base.nix
···
];
# ISO naming.
-
isoImage.isoName = "${config.isoImage.isoBaseName}-${config.system.nixosVersion}-${pkgs.stdenv.system}.iso";
+
isoImage.isoName = "${config.isoImage.isoBaseName}-${config.system.nixosLabel}-${pkgs.stdenv.system}.iso";
isoImage.volumeID = substring 0 11 "NIXOS_ISO";
+1 -1
nixos/modules/installer/cd-dvd/iso-image.nix
···
DEFAULT boot
LABEL boot
-
MENU LABEL NixOS ${config.system.nixosVersion}${config.isoImage.appendToMenuLabel}
+
MENU LABEL NixOS ${config.system.nixosLabel}${config.isoImage.appendToMenuLabel}
LINUX /boot/bzImage
APPEND init=${config.system.build.toplevel}/init ${toString config.boot.kernelParams}
INITRD /boot/initrd
+51 -21
nixos/modules/misc/version.nix
···
with lib;
+
let
+
cfg = config.system;
+
+
releaseFile = "${toString pkgs.path}/.version";
+
suffixFile = "${toString pkgs.path}/.version-suffix";
+
revisionFile = "${toString pkgs.path}/.git-revision";
+
in
+
{
-
options = {
+
options.system = {
-
system.stateVersion = mkOption {
+
stateVersion = mkOption {
type = types.str;
-
default = config.system.nixosRelease;
+
default = cfg.nixosRelease;
description = ''
Every once in a while, a new NixOS release may change
configuration defaults in a way incompatible with stateful
···
'';
};
-
system.nixosVersion = mkOption {
+
nixosLabel = mkOption {
+
type = types.str;
+
description = ''
+
NixOS version name to be used in the names of generated
+
outputs and boot labels.
+
+
If you ever wanted to influence the labels in your GRUB menu,
+
this is option is for you.
+
+
Can be set directly or with <envar>NIXOS_LABEL</envar>
+
environment variable for <command>nixos-rebuild</command>,
+
e.g.:
+
+
<screen>
+
#!/bin/sh
+
today=`date +%Y%m%d`
+
branch=`(cd nixpkgs ; git branch 2>/dev/null | sed -n '/^\* / { s|^\* ||; p; }')`
+
revision=`(cd nixpkgs ; git rev-parse HEAD)`
+
export NIXOS_LABEL="$today.$branch-''${revision:0:7}"
+
nixos-rebuild switch</screen>
+
'';
+
};
+
+
nixosVersion = mkOption {
internal = true;
type = types.str;
description = "NixOS version.";
};
-
system.nixosRelease = mkOption {
+
nixosRelease = mkOption {
readOnly = true;
type = types.str;
-
default = readFile "${toString pkgs.path}/.version";
+
default = readFile releaseFile;
description = "NixOS release.";
};
-
system.nixosVersionSuffix = mkOption {
+
nixosVersionSuffix = mkOption {
internal = true;
type = types.str;
+
default = if pathExists suffixFile then readFile suffixFile else "pre-git";
description = "NixOS version suffix.";
};
-
system.nixosRevision = mkOption {
+
nixosRevision = mkOption {
internal = true;
type = types.str;
+
default = if pathExists revisionFile then readFile revisionFile else "master";
description = "NixOS Git revision hash.";
};
-
system.nixosCodeName = mkOption {
+
nixosCodeName = mkOption {
readOnly = true;
type = types.str;
description = "NixOS release code name.";
};
-
system.defaultChannel = mkOption {
+
defaultChannel = mkOption {
internal = true;
type = types.str;
default = https://nixos.org/channels/nixos-unstable;
···
config = {
-
system.nixosVersion = mkDefault (config.system.nixosRelease + config.system.nixosVersionSuffix);
-
-
system.nixosVersionSuffix =
-
let suffixFile = "${toString pkgs.path}/.version-suffix"; in
-
mkDefault (if pathExists suffixFile then readFile suffixFile else "pre-git");
-
-
system.nixosRevision =
-
let fn = "${toString pkgs.path}/.git-revision"; in
-
mkDefault (if pathExists fn then readFile fn else "master");
+
system = {
+
# These defaults are set here rather than up there so that
+
# changing them would not rebuild the manual
+
nixosLabel = mkDefault (maybeEnv "NIXOS_LABEL" cfg.nixosVersion);
+
nixosVersion = mkDefault (maybeEnv "NIXOS_VERSION" (cfg.nixosRelease + cfg.nixosVersionSuffix));
-
# Note: code names must only increase in alphabetical order.
-
system.nixosCodeName = "Emu";
+
# Note: code names must only increase in alphabetical order.
+
nixosCodeName = "Emu";
+
};
# Generate /etc/os-release. See
# http://0pointer.de/public/systemd-man/os-release.html for the
+14 -6
nixos/modules/services/ttys/agetty.nix
···
with lib;
+
let
+
+
autologinArg = optionalString (config.services.mingetty.autologinUser != null) "--autologin ${config.services.mingetty.autologinUser}";
+
gettyCmd = extraArgs: "@${pkgs.utillinux}/sbin/agetty agetty --login-program ${pkgs.shadow}/bin/login ${autologinArg} ${extraArgs}";
+
+
in
+
{
###### interface
···
greetingLine = mkOption {
type = types.str;
-
default = ''<<< Welcome to NixOS ${config.system.nixosVersion} (\m) - \l >>>'';
description = ''
Welcome line printed by mingetty.
+
The default shows current NixOS version label, machine type and tty.
'';
};
···
###### implementation
-
config = let
-
autologinArg = optionalString (config.services.mingetty.autologinUser != null) "--autologin ${config.services.mingetty.autologinUser}";
-
gettyCmd = extraArgs: "@${pkgs.utillinux}/sbin/agetty agetty --login-program ${pkgs.shadow}/bin/login ${autologinArg} ${extraArgs}";
-
in {
+
config = {
+
# Note: this is set here rather than up there so that changing
+
# nixosLabel would not rebuild manual pages
+
services.mingetty.greetingLine = mkDefault ''<<< Welcome to NixOS ${config.system.nixosLabel} (\m) - \l >>>'';
+
systemd.services."getty@" =
{ serviceConfig.ExecStart = gettyCmd "--noclear --keep-baud %I 115200,38400,9600 $TERM";
restartIfChanged = false;
···
{ serviceConfig.ExecStart = gettyCmd "--noclear --keep-baud console 115200,38400,9600 $TERM";
serviceConfig.Restart = "always";
restartIfChanged = false;
-
enable = mkDefault config.boot.isContainer;
+
enable = mkDefault config.boot.isContainer;
};
environment.etc = singleton
+3 -3
nixos/modules/system/activation/top-level.nix
···
echo -n "$configurationName" > $out/configuration-name
echo -n "systemd ${toString config.systemd.package.interfaceVersion}" > $out/init-interface-version
-
echo -n "$nixosVersion" > $out/nixos-version
+
echo -n "$nixosLabel" > $out/nixos-version
echo -n "$system" > $out/system
mkdir $out/fine-tune
···
if [] == failed then pkgs.stdenv.mkDerivation {
name = let hn = config.networking.hostName;
nn = if (hn != "") then hn else "unnamed";
-
in "nixos-system-${nn}-${config.system.nixosVersion}";
+
in "nixos-system-${nn}-${config.system.nixosLabel}";
preferLocalBuild = true;
allowSubstitutes = false;
buildCommand = systemBuilder;
···
config.system.build.installBootLoader
or "echo 'Warning: do not know how to make this configuration bootable; please enable a boot loader.' 1>&2; true";
activationScript = config.system.activationScripts.script;
-
nixosVersion = config.system.nixosVersion;
+
nixosLabel = config.system.nixosLabel;
configurationName = config.boot.loader.grub.configurationName;
+2 -2
nixos/modules/system/boot/loader/generic-extlinux-compatible/extlinux-conf-builder.sh
···
timestampEpoch=$(stat -L -c '%Z' $path)
timestamp=$(date "+%Y-%m-%d %H:%M" -d @$timestampEpoch)
-
nixosVersion="$(cat $path/nixos-version)"
+
nixosLabel="$(cat $path/nixos-version)"
extraParams="$(cat $path/kernel-params)"
echo
···
if [ "$tag" = "default" ]; then
echo " MENU LABEL NixOS - Default"
else
-
echo " MENU LABEL NixOS - Configuration $tag ($timestamp - $nixosVersion)"
+
echo " MENU LABEL NixOS - Configuration $tag ($timestamp - $nixosLabel)"
fi
echo " LINUX ../nixos/$(basename $kernel)"
echo " INITRD ../nixos/$(basename $initrd)"
+1 -1
nixos/modules/virtualisation/azure-image.nix
···
${pkgs.vmTools.qemu}/bin/qemu-img convert -f raw -O vpc $diskImage $out/disk.vhd
rm $diskImage
'';
-
diskImageBase = "nixos-image-${config.system.nixosVersion}-${pkgs.stdenv.system}.raw";
+
diskImageBase = "nixos-image-${config.system.nixosLabel}-${pkgs.stdenv.system}.raw";
buildInputs = [ pkgs.utillinux pkgs.perl ];
exportReferencesGraph =
[ "closure" config.system.build.toplevel ];
+1 -1
nixos/modules/virtualisation/brightbox-image.nix
···
rm $diskImageBase
popd
'';
-
diskImageBase = "nixos-image-${config.system.nixosVersion}-${pkgs.stdenv.system}.raw";
+
diskImageBase = "nixos-image-${config.system.nixosLabel}-${pkgs.stdenv.system}.raw";
buildInputs = [ pkgs.utillinux pkgs.perl ];
exportReferencesGraph =
[ "closure" config.system.build.toplevel ];
+1 -1
nixos/modules/virtualisation/google-compute-image.nix
···
rm $out/disk.raw
popd
'';
-
diskImageBase = "nixos-image-${config.system.nixosVersion}-${pkgs.stdenv.system}.raw";
+
diskImageBase = "nixos-image-${config.system.nixosLabel}-${pkgs.stdenv.system}.raw";
buildInputs = [ pkgs.utillinux pkgs.perl ];
exportReferencesGraph =
[ "closure" config.system.build.toplevel ];
+2 -2
nixos/modules/virtualisation/virtualbox-image.nix
···
system.build.virtualBoxOVA = pkgs.runCommand "virtualbox-ova"
{ buildInputs = [ pkgs.linuxPackages.virtualbox ];
-
vmName = "NixOS ${config.system.nixosVersion} (${pkgs.stdenv.system})";
-
fileName = "nixos-image-${config.system.nixosVersion}-${pkgs.stdenv.system}.ova";
+
vmName = "NixOS ${config.system.nixosLabel} (${pkgs.stdenv.system})";
+
fileName = "nixos-image-${config.system.nixosLabel}-${pkgs.stdenv.system}.ova";
}
''
echo "creating VirtualBox VM..."