1{ config, lib, ... }:
2let
3 cfg = config.system.nixos;
4in
5
6{
7
8 options.system = {
9
10 nixos.label = lib.mkOption {
11 type = lib.types.strMatching "[a-zA-Z0-9:_\\.-]*";
12 description = ''
13 NixOS version name to be used in the names of generated
14 outputs and boot labels.
15
16 If you ever wanted to influence the labels in your GRUB menu,
17 this is the option for you.
18
19 It can only contain letters, numbers and the following symbols:
20 `:`, `_`, `.` and `-`.
21
22 The default is {option}`system.nixos.tags` separated by
23 "-" + "-" + {env}`NIXOS_LABEL_VERSION` environment
24 variable (defaults to the value of
25 {option}`system.nixos.version`).
26
27 Can be overridden by setting {env}`NIXOS_LABEL`.
28
29 Useful for not loosing track of configurations built from different
30 nixos branches/revisions, e.g.:
31
32 ```
33 #!/bin/sh
34 today=`date +%Y%m%d`
35 branch=`(cd nixpkgs ; git branch 2>/dev/null | sed -n '/^\* / { s|^\* ||; p; }')`
36 revision=`(cd nixpkgs ; git rev-parse HEAD)`
37 export NIXOS_LABEL_VERSION="$today.$branch-''${revision:0:7}"
38 nixos-rebuild switch
39 ```
40 '';
41 };
42
43 nixos.tags = lib.mkOption {
44 type = lib.types.listOf lib.types.str;
45 default = [ ];
46 example = [ "with-xen" ];
47 description = ''
48 Strings to prefix to the default
49 {option}`system.nixos.label`.
50
51 Useful for not losing track of configurations built with
52 different options, e.g.:
53
54 ```
55 {
56 system.nixos.tags = [ "with-xen" ];
57 virtualisation.xen.enable = true;
58 }
59 ```
60 '';
61 };
62
63 };
64
65 config = {
66 # This is set here rather than up there so that changing it would
67 # not rebuild the manual
68 system.nixos.label = lib.mkDefault (
69 lib.maybeEnv "NIXOS_LABEL" (
70 lib.concatStringsSep "-" (
71 (lib.sort (x: y: x < y) cfg.tags) ++ [ (lib.maybeEnv "NIXOS_LABEL_VERSION" cfg.version) ]
72 )
73 )
74 );
75 };
76
77}