diff options
author | Arseniy Seroka <jagajaga@users.noreply.github.com> | 2016-01-09 20:52:08 +0300 |
---|---|---|
committer | Arseniy Seroka <jagajaga@users.noreply.github.com> | 2016-01-09 20:52:08 +0300 |
commit | c03fe792656b506b40e18d9c070d0bad8f7f1c3e (patch) | |
tree | fa3b8e6d5bf875f30a5629f72d76a87e0d67944a /nixos/modules/misc | |
parent | 84631f32276a86a1748effc7399c8c0ea97500ba (diff) | |
parent | 119c8f91e7f17d2cb95f42985816820600c389cf (diff) | |
download | nixlib-c03fe792656b506b40e18d9c070d0bad8f7f1c3e.tar nixlib-c03fe792656b506b40e18d9c070d0bad8f7f1c3e.tar.gz nixlib-c03fe792656b506b40e18d9c070d0bad8f7f1c3e.tar.bz2 nixlib-c03fe792656b506b40e18d9c070d0bad8f7f1c3e.tar.lz nixlib-c03fe792656b506b40e18d9c070d0bad8f7f1c3e.tar.xz nixlib-c03fe792656b506b40e18d9c070d0bad8f7f1c3e.tar.zst nixlib-c03fe792656b506b40e18d9c070d0bad8f7f1c3e.zip |
Merge pull request #10996 from oxij/nixos-label
nixos: introduce system.nixosLabel support
Diffstat (limited to 'nixos/modules/misc')
-rw-r--r-- | nixos/modules/misc/version.nix | 72 |
1 files changed, 51 insertions, 21 deletions
diff --git a/nixos/modules/misc/version.nix b/nixos/modules/misc/version.nix index b4b0281fe587..18f270cd531b 100644 --- a/nixos/modules/misc/version.nix +++ b/nixos/modules/misc/version.nix @@ -2,13 +2,21 @@ with lib; +let + cfg = config.system; + + releaseFile = "${toString pkgs.path}/.version"; + suffixFile = "${toString pkgs.path}/.version-suffix"; + revisionFile = "${toString pkgs.path}/.git-revision"; +in + { - options = { + options.system = { - system.stateVersion = mkOption { + stateVersion = mkOption { type = types.str; - default = config.system.nixosRelease; + default = cfg.nixosRelease; description = '' Every once in a while, a new NixOS release may change configuration defaults in a way incompatible with stateful @@ -22,38 +30,63 @@ with lib; ''; }; - system.nixosVersion = mkOption { + nixosLabel = 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 option is for you. + + Can be set directly or with <envar>NIXOS_LABEL</envar> + environment variable for <command>nixos-rebuild</command>, + 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="$today.$branch-''${revision:0:7}" + nixos-rebuild switch</screen> + ''; + }; + + nixosVersion = mkOption { internal = true; type = types.str; description = "NixOS version."; }; - system.nixosRelease = mkOption { + nixosRelease = mkOption { readOnly = true; type = types.str; - default = readFile "${toString pkgs.path}/.version"; + default = readFile releaseFile; description = "NixOS release."; }; - system.nixosVersionSuffix = mkOption { + nixosVersionSuffix = mkOption { internal = true; type = types.str; + default = if pathExists suffixFile then readFile suffixFile else "pre-git"; description = "NixOS version suffix."; }; - system.nixosRevision = mkOption { + nixosRevision = mkOption { internal = true; type = types.str; + default = if pathExists revisionFile then readFile revisionFile else "master"; description = "NixOS Git revision hash."; }; - system.nixosCodeName = mkOption { + nixosCodeName = mkOption { readOnly = true; type = types.str; description = "NixOS release code name."; }; - system.defaultChannel = mkOption { + defaultChannel = mkOption { internal = true; type = types.str; default = https://nixos.org/channels/nixos-unstable; @@ -64,18 +97,15 @@ with lib; config = { - system.nixosVersion = mkDefault (config.system.nixosRelease + config.system.nixosVersionSuffix); - - system.nixosVersionSuffix = - let suffixFile = "${toString pkgs.path}/.version-suffix"; in - mkDefault (if pathExists suffixFile then readFile suffixFile else "pre-git"); + system = { + # These defaults are set here rather than up there so that + # changing them would not rebuild the manual + nixosLabel = mkDefault (maybeEnv "NIXOS_LABEL" cfg.nixosVersion); + nixosVersion = mkDefault (maybeEnv "NIXOS_VERSION" (cfg.nixosRelease + cfg.nixosVersionSuffix)); - system.nixosRevision = - let fn = "${toString pkgs.path}/.git-revision"; in - mkDefault (if pathExists fn then readFile fn else "master"); - - # Note: code names must only increase in alphabetical order. - system.nixosCodeName = "Emu"; + # Note: code names must only increase in alphabetical order. + nixosCodeName = "Emu"; + }; # Generate /etc/os-release. See # http://0pointer.de/public/systemd-man/os-release.html for the |