diff --git a/nixos/modules/misc/label.nix b/nixos/modules/misc/label.nix
index b4e88915d829..250914e8f82e 100644
--- a/nixos/modules/misc/label.nix
+++ b/nixos/modules/misc/label.nix
@@ -18,6 +18,24 @@ in
If you ever wanted to influence the labels in your GRUB menu,
this is the option for you.
+
+ The default is separated by
+ "-" + "-" + NIXOS_LABEL_VERSION environment
+ variable (defaults to the value of
+ ).
+
+ Can be overriden by setting NIXOS_LABEL.
+
+ Useful for not loosing track of configurations built from different
+ nixos branches/revisions, e.g.:
+
+
+ #!/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_VERSION="$today.$branch-''${revision:0:7}"
+ nixos-rebuild switch
'';
};
@@ -46,7 +64,9 @@ in
config = {
# This is set here rather than up there so that changing it would
# not rebuild the manual
- system.nixos.label = mkDefault (concatStringsSep "-" (sort (x: y: x < y) cfg.tags) + "-" + cfg.version);
+ system.nixos.label = mkDefault (maybeEnv "NIXOS_LABEL"
+ (concatStringsSep "-" (sort (x: y: x < y) cfg.tags)
+ + "-" + maybeEnv "NIXOS_LABEL_VERSION" cfg.version));
};
}