nixos: introduce system.nixosLabel option and use it where appropriate
Setting nixosVersion to something custom is useful for meaningful GRUB menus and /nix/store paths, but actuallly changing it rebulids the whole system path (because of `nixos-version` script and manual pages). Also, changing it is not a particularly good idea because you can then be differentitated from other NixOS users by a lot of programs that read /etc/os-release. This patch introduces an alternative option that does all you want from nixosVersion, but rebuilds only the very top system level and /etc while using your label in the names of system /nix/store paths, GRUB and other boot loaders' menus, getty greetings and so on.
This commit is contained in:
parent
732eb3c4cc
commit
119c8f91e7
@ -16,7 +16,7 @@ with lib;
|
|||||||
];
|
];
|
||||||
|
|
||||||
# ISO naming.
|
# 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";
|
isoImage.volumeID = substring 0 11 "NIXOS_ISO";
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ let
|
|||||||
DEFAULT boot
|
DEFAULT boot
|
||||||
|
|
||||||
LABEL boot
|
LABEL boot
|
||||||
MENU LABEL NixOS ${config.system.nixosVersion}${config.isoImage.appendToMenuLabel}
|
MENU LABEL NixOS ${config.system.nixosLabel}${config.isoImage.appendToMenuLabel}
|
||||||
LINUX /boot/bzImage
|
LINUX /boot/bzImage
|
||||||
APPEND init=${config.system.build.toplevel}/init ${toString config.boot.kernelParams}
|
APPEND init=${config.system.build.toplevel}/init ${toString config.boot.kernelParams}
|
||||||
INITRD /boot/initrd
|
INITRD /boot/initrd
|
||||||
|
@ -30,6 +30,29 @@ in
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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 {
|
nixosVersion = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
type = types.str;
|
type = types.str;
|
||||||
@ -75,8 +98,9 @@ in
|
|||||||
config = {
|
config = {
|
||||||
|
|
||||||
system = {
|
system = {
|
||||||
# This is set here rather than up there so that changing this
|
# These defaults are set here rather than up there so that
|
||||||
# env variable will not rebuild the manual
|
# changing them would not rebuild the manual
|
||||||
|
nixosLabel = mkDefault (maybeEnv "NIXOS_LABEL" cfg.nixosVersion);
|
||||||
nixosVersion = mkDefault (maybeEnv "NIXOS_VERSION" (cfg.nixosRelease + cfg.nixosVersionSuffix));
|
nixosVersion = mkDefault (maybeEnv "NIXOS_VERSION" (cfg.nixosRelease + cfg.nixosVersionSuffix));
|
||||||
|
|
||||||
# Note: code names must only increase in alphabetical order.
|
# Note: code names must only increase in alphabetical order.
|
||||||
|
@ -2,6 +2,13 @@
|
|||||||
|
|
||||||
with lib;
|
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
|
###### interface
|
||||||
@ -21,9 +28,9 @@ with lib;
|
|||||||
|
|
||||||
greetingLine = mkOption {
|
greetingLine = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
default = ''<<< Welcome to NixOS ${config.system.nixosVersion} (\m) - \l >>>'';
|
|
||||||
description = ''
|
description = ''
|
||||||
Welcome line printed by mingetty.
|
Welcome line printed by mingetty.
|
||||||
|
The default shows current NixOS version label, machine type and tty.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -55,10 +62,11 @@ with lib;
|
|||||||
|
|
||||||
###### implementation
|
###### implementation
|
||||||
|
|
||||||
config = let
|
config = {
|
||||||
autologinArg = optionalString (config.services.mingetty.autologinUser != null) "--autologin ${config.services.mingetty.autologinUser}";
|
# Note: this is set here rather than up there so that changing
|
||||||
gettyCmd = extraArgs: "@${pkgs.utillinux}/sbin/agetty agetty --login-program ${pkgs.shadow}/bin/login ${autologinArg} ${extraArgs}";
|
# nixosLabel would not rebuild manual pages
|
||||||
in {
|
services.mingetty.greetingLine = mkDefault ''<<< Welcome to NixOS ${config.system.nixosLabel} (\m) - \l >>>'';
|
||||||
|
|
||||||
systemd.services."getty@" =
|
systemd.services."getty@" =
|
||||||
{ serviceConfig.ExecStart = gettyCmd "--noclear --keep-baud %I 115200,38400,9600 $TERM";
|
{ serviceConfig.ExecStart = gettyCmd "--noclear --keep-baud %I 115200,38400,9600 $TERM";
|
||||||
restartIfChanged = false;
|
restartIfChanged = false;
|
||||||
@ -81,7 +89,7 @@ with lib;
|
|||||||
{ serviceConfig.ExecStart = gettyCmd "--noclear --keep-baud console 115200,38400,9600 $TERM";
|
{ serviceConfig.ExecStart = gettyCmd "--noclear --keep-baud console 115200,38400,9600 $TERM";
|
||||||
serviceConfig.Restart = "always";
|
serviceConfig.Restart = "always";
|
||||||
restartIfChanged = false;
|
restartIfChanged = false;
|
||||||
enable = mkDefault config.boot.isContainer;
|
enable = mkDefault config.boot.isContainer;
|
||||||
};
|
};
|
||||||
|
|
||||||
environment.etc = singleton
|
environment.etc = singleton
|
||||||
|
@ -67,7 +67,7 @@ let
|
|||||||
|
|
||||||
echo -n "$configurationName" > $out/configuration-name
|
echo -n "$configurationName" > $out/configuration-name
|
||||||
echo -n "systemd ${toString config.systemd.package.interfaceVersion}" > $out/init-interface-version
|
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
|
echo -n "$system" > $out/system
|
||||||
|
|
||||||
mkdir $out/fine-tune
|
mkdir $out/fine-tune
|
||||||
@ -101,7 +101,7 @@ let
|
|||||||
if [] == failed then pkgs.stdenv.mkDerivation {
|
if [] == failed then pkgs.stdenv.mkDerivation {
|
||||||
name = let hn = config.networking.hostName;
|
name = let hn = config.networking.hostName;
|
||||||
nn = if (hn != "") then hn else "unnamed";
|
nn = if (hn != "") then hn else "unnamed";
|
||||||
in "nixos-system-${nn}-${config.system.nixosVersion}";
|
in "nixos-system-${nn}-${config.system.nixosLabel}";
|
||||||
preferLocalBuild = true;
|
preferLocalBuild = true;
|
||||||
allowSubstitutes = false;
|
allowSubstitutes = false;
|
||||||
buildCommand = systemBuilder;
|
buildCommand = systemBuilder;
|
||||||
@ -115,7 +115,7 @@ let
|
|||||||
config.system.build.installBootLoader
|
config.system.build.installBootLoader
|
||||||
or "echo 'Warning: do not know how to make this configuration bootable; please enable a boot loader.' 1>&2; true";
|
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;
|
activationScript = config.system.activationScripts.script;
|
||||||
nixosVersion = config.system.nixosVersion;
|
nixosLabel = config.system.nixosLabel;
|
||||||
|
|
||||||
configurationName = config.boot.loader.grub.configurationName;
|
configurationName = config.boot.loader.grub.configurationName;
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ addEntry() {
|
|||||||
timestampEpoch=$(stat -L -c '%Z' $path)
|
timestampEpoch=$(stat -L -c '%Z' $path)
|
||||||
|
|
||||||
timestamp=$(date "+%Y-%m-%d %H:%M" -d @$timestampEpoch)
|
timestamp=$(date "+%Y-%m-%d %H:%M" -d @$timestampEpoch)
|
||||||
nixosVersion="$(cat $path/nixos-version)"
|
nixosLabel="$(cat $path/nixos-version)"
|
||||||
extraParams="$(cat $path/kernel-params)"
|
extraParams="$(cat $path/kernel-params)"
|
||||||
|
|
||||||
echo
|
echo
|
||||||
@ -91,7 +91,7 @@ addEntry() {
|
|||||||
if [ "$tag" = "default" ]; then
|
if [ "$tag" = "default" ]; then
|
||||||
echo " MENU LABEL NixOS - Default"
|
echo " MENU LABEL NixOS - Default"
|
||||||
else
|
else
|
||||||
echo " MENU LABEL NixOS - Configuration $tag ($timestamp - $nixosVersion)"
|
echo " MENU LABEL NixOS - Configuration $tag ($timestamp - $nixosLabel)"
|
||||||
fi
|
fi
|
||||||
echo " LINUX ../nixos/$(basename $kernel)"
|
echo " LINUX ../nixos/$(basename $kernel)"
|
||||||
echo " INITRD ../nixos/$(basename $initrd)"
|
echo " INITRD ../nixos/$(basename $initrd)"
|
||||||
|
@ -26,7 +26,7 @@ in
|
|||||||
${pkgs.vmTools.qemu}/bin/qemu-img convert -f raw -O vpc $diskImage $out/disk.vhd
|
${pkgs.vmTools.qemu}/bin/qemu-img convert -f raw -O vpc $diskImage $out/disk.vhd
|
||||||
rm $diskImage
|
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 ];
|
buildInputs = [ pkgs.utillinux pkgs.perl ];
|
||||||
exportReferencesGraph =
|
exportReferencesGraph =
|
||||||
[ "closure" config.system.build.toplevel ];
|
[ "closure" config.system.build.toplevel ];
|
||||||
|
@ -26,7 +26,7 @@ in
|
|||||||
rm $diskImageBase
|
rm $diskImageBase
|
||||||
popd
|
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 ];
|
buildInputs = [ pkgs.utillinux pkgs.perl ];
|
||||||
exportReferencesGraph =
|
exportReferencesGraph =
|
||||||
[ "closure" config.system.build.toplevel ];
|
[ "closure" config.system.build.toplevel ];
|
||||||
|
@ -30,7 +30,7 @@ in
|
|||||||
rm $out/disk.raw
|
rm $out/disk.raw
|
||||||
popd
|
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 ];
|
buildInputs = [ pkgs.utillinux pkgs.perl ];
|
||||||
exportReferencesGraph =
|
exportReferencesGraph =
|
||||||
[ "closure" config.system.build.toplevel ];
|
[ "closure" config.system.build.toplevel ];
|
||||||
|
@ -44,8 +44,8 @@ in {
|
|||||||
|
|
||||||
system.build.virtualBoxOVA = pkgs.runCommand "virtualbox-ova"
|
system.build.virtualBoxOVA = pkgs.runCommand "virtualbox-ova"
|
||||||
{ buildInputs = [ pkgs.linuxPackages.virtualbox ];
|
{ buildInputs = [ pkgs.linuxPackages.virtualbox ];
|
||||||
vmName = "NixOS ${config.system.nixosVersion} (${pkgs.stdenv.system})";
|
vmName = "NixOS ${config.system.nixosLabel} (${pkgs.stdenv.system})";
|
||||||
fileName = "nixos-image-${config.system.nixosVersion}-${pkgs.stdenv.system}.ova";
|
fileName = "nixos-image-${config.system.nixosLabel}-${pkgs.stdenv.system}.ova";
|
||||||
}
|
}
|
||||||
''
|
''
|
||||||
echo "creating VirtualBox VM..."
|
echo "creating VirtualBox VM..."
|
||||||
|
Loading…
Reference in New Issue
Block a user