aboutsummaryrefslogtreecommitdiff
path: root/nixpkgs/nixos/modules/misc/label.nix
diff options
context:
space:
mode:
authorKatharina Fey <kookie@spacekookie.de>2019-10-05 12:43:18 +0000
committerKatharina Fey <kookie@spacekookie.de>2019-10-05 12:44:52 +0000
commitcf85056ba64caf3267d43255ef4a1243e9c8ee3b (patch)
tree3051519e9c8275b870aac43f80af875715c9d124 /nixpkgs/nixos/modules/misc/label.nix
parent1148b1d122bc03e9a3665856c9b7bb96bd4e3994 (diff)
parent2436c27541b2f52deea3a4c1691216a02152e729 (diff)
Add 'nixpkgs/' from commit '2436c27541b2f52deea3a4c1691216a02152e729'
git-subtree-dir: nixpkgs git-subtree-mainline: 1148b1d122bc03e9a3665856c9b7bb96bd4e3994 git-subtree-split: 2436c27541b2f52deea3a4c1691216a02152e729
Diffstat (limited to 'nixpkgs/nixos/modules/misc/label.nix')
-rw-r--r--nixpkgs/nixos/modules/misc/label.nix72
1 files changed, 72 insertions, 0 deletions
diff --git a/nixpkgs/nixos/modules/misc/label.nix b/nixpkgs/nixos/modules/misc/label.nix
new file mode 100644
index 00000000000..02b91555b3c
--- /dev/null
+++ b/nixpkgs/nixos/modules/misc/label.nix
@@ -0,0 +1,72 @@
+{ config, lib, ... }:
+
+with lib;
+
+let
+ cfg = config.system.nixos;
+in
+
+{
+
+ options.system = {
+
+ nixos.label = 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 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>
+ '';
+ };
+
+ nixos.tags = mkOption {
+ type = types.listOf types.str;
+ default = [];
+ example = [ "with-xen" ];
+ description = ''
+ Strings to prefix to the default
+ <option>system.nixos.label</option>.
+
+ Useful for not loosing track of configurations built with
+ different options, e.g.:
+
+ <screen>
+ {
+ system.nixos.tags = [ "with-xen" ];
+ virtualisation.xen.enable = true;
+ }
+ </screen>
+ '';
+ };
+
+ };
+
+ config = {
+ # This is set here rather than up there so that changing it would
+ # not rebuild the manual
+ system.nixos.label = mkDefault (maybeEnv "NIXOS_LABEL"
+ (concatStringsSep "-" ((sort (x: y: x < y) cfg.tags)
+ ++ [ (maybeEnv "NIXOS_LABEL_VERSION" cfg.version) ])));
+ };
+
+}