about summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorJan Malakhovski <oxij@oxij.org>2017-04-01 00:00:00 +0000
committerJan Malakhovski <oxij@oxij.org>2018-02-18 12:56:31 +0000
commitc6d8a58e8d3a9751197e8f731e823c08f5ee5dc3 (patch)
tree636ca96d47928916df51d284b2fc17ba3b50af4e /nixos
parent0fd8ce96ac7c708919da422d032dbf0f23c8c03a (diff)
downloadnixlib-c6d8a58e8d3a9751197e8f731e823c08f5ee5dc3.tar
nixlib-c6d8a58e8d3a9751197e8f731e823c08f5ee5dc3.tar.gz
nixlib-c6d8a58e8d3a9751197e8f731e823c08f5ee5dc3.tar.bz2
nixlib-c6d8a58e8d3a9751197e8f731e823c08f5ee5dc3.tar.lz
nixlib-c6d8a58e8d3a9751197e8f731e823c08f5ee5dc3.tar.xz
nixlib-c6d8a58e8d3a9751197e8f731e823c08f5ee5dc3.tar.zst
nixlib-c6d8a58e8d3a9751197e8f731e823c08f5ee5dc3.zip
nixos: allow overriding labels with environment variables
This reintroduces a better version of what 2a05368ff3217175cd87105e778e2e70bc7eef1c removed.
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/misc/label.nix22
1 files changed, 21 insertions, 1 deletions
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 <option>system.nixos.tags</option> separated by
+        "-" + "-" + <envar>NIXOS_LABEL_VERSION</envar> environment
+        variable (defaults to the value of
+        <option>system.nixos.version</option>).
+
+        Can be overriden by setting <envar>NIXOS_LABEL</envar>.
+
+        Useful for not loosing track of configurations built from different
+        nixos branches/revisions, 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_VERSION="$today.$branch-''${revision:0:7}"
+        nixos-rebuild switch</screen>
       '';
     };
 
@@ -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));
   };
 
 }