2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.system.nixos;
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
options.system = {
|
|
|
|
|
|
|
|
nixos.label = mkOption {
|
2022-07-18 16:21:45 +00:00
|
|
|
type = types.strMatching "[a-zA-Z0-9:_\\.-]*";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
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.
|
|
|
|
|
2022-07-18 16:21:45 +00:00
|
|
|
It can only contain letters, numbers and the following symbols:
|
2022-09-09 14:08:57 +00:00
|
|
|
`:`, `_`, `.` and `-`.
|
2022-07-18 16:21:45 +00:00
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
The default is {option}`system.nixos.tags` separated by
|
|
|
|
"-" + "-" + {env}`NIXOS_LABEL_VERSION` environment
|
2020-04-24 23:36:52 +00:00
|
|
|
variable (defaults to the value of
|
2022-09-09 14:08:57 +00:00
|
|
|
{option}`system.nixos.version`).
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-12-28 21:21:41 +00:00
|
|
|
Can be overridden by setting {env}`NIXOS_LABEL`.
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
Useful for not loosing track of configurations built from different
|
|
|
|
nixos branches/revisions, e.g.:
|
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
```
|
2020-04-24 23:36:52 +00:00
|
|
|
#!/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}"
|
2022-09-09 14:08:57 +00:00
|
|
|
nixos-rebuild switch
|
|
|
|
```
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
nixos.tags = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
example = [ "with-xen" ];
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Strings to prefix to the default
|
2022-09-09 14:08:57 +00:00
|
|
|
{option}`system.nixos.label`.
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
Useful for not loosing track of configurations built with
|
|
|
|
different options, e.g.:
|
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
```
|
2020-04-24 23:36:52 +00:00
|
|
|
{
|
|
|
|
system.nixos.tags = [ "with-xen" ];
|
|
|
|
virtualisation.xen.enable = true;
|
|
|
|
}
|
2022-09-09 14:08:57 +00:00
|
|
|
```
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
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) ])));
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|