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