nixos: cleanup version module, allow setting nixosVersion with env variable
This commit is contained in:
parent
a99a634acf
commit
732eb3c4cc
|
@ -2,13 +2,21 @@
|
||||||
|
|
||||||
with lib;
|
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;
|
type = types.str;
|
||||||
default = config.system.nixosRelease;
|
default = cfg.nixosRelease;
|
||||||
description = ''
|
description = ''
|
||||||
Every once in a while, a new NixOS release may change
|
Every once in a while, a new NixOS release may change
|
||||||
configuration defaults in a way incompatible with stateful
|
configuration defaults in a way incompatible with stateful
|
||||||
|
@ -22,38 +30,40 @@ with lib;
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
system.nixosVersion = mkOption {
|
nixosVersion = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
type = types.str;
|
type = types.str;
|
||||||
description = "NixOS version.";
|
description = "NixOS version.";
|
||||||
};
|
};
|
||||||
|
|
||||||
system.nixosRelease = mkOption {
|
nixosRelease = mkOption {
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = types.str;
|
type = types.str;
|
||||||
default = readFile "${toString pkgs.path}/.version";
|
default = readFile releaseFile;
|
||||||
description = "NixOS release.";
|
description = "NixOS release.";
|
||||||
};
|
};
|
||||||
|
|
||||||
system.nixosVersionSuffix = mkOption {
|
nixosVersionSuffix = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
type = types.str;
|
type = types.str;
|
||||||
|
default = if pathExists suffixFile then readFile suffixFile else "pre-git";
|
||||||
description = "NixOS version suffix.";
|
description = "NixOS version suffix.";
|
||||||
};
|
};
|
||||||
|
|
||||||
system.nixosRevision = mkOption {
|
nixosRevision = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
type = types.str;
|
type = types.str;
|
||||||
|
default = if pathExists revisionFile then readFile revisionFile else "master";
|
||||||
description = "NixOS Git revision hash.";
|
description = "NixOS Git revision hash.";
|
||||||
};
|
};
|
||||||
|
|
||||||
system.nixosCodeName = mkOption {
|
nixosCodeName = mkOption {
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = types.str;
|
type = types.str;
|
||||||
description = "NixOS release code name.";
|
description = "NixOS release code name.";
|
||||||
};
|
};
|
||||||
|
|
||||||
system.defaultChannel = mkOption {
|
defaultChannel = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
type = types.str;
|
type = types.str;
|
||||||
default = https://nixos.org/channels/nixos-unstable;
|
default = https://nixos.org/channels/nixos-unstable;
|
||||||
|
@ -64,18 +74,14 @@ with lib;
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
|
|
||||||
system.nixosVersion = mkDefault (config.system.nixosRelease + config.system.nixosVersionSuffix);
|
system = {
|
||||||
|
# This is set here rather than up there so that changing this
|
||||||
system.nixosVersionSuffix =
|
# env variable will not rebuild the manual
|
||||||
let suffixFile = "${toString pkgs.path}/.version-suffix"; in
|
nixosVersion = mkDefault (maybeEnv "NIXOS_VERSION" (cfg.nixosRelease + cfg.nixosVersionSuffix));
|
||||||
mkDefault (if pathExists suffixFile then readFile suffixFile else "pre-git");
|
|
||||||
|
|
||||||
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.
|
# Note: code names must only increase in alphabetical order.
|
||||||
system.nixosCodeName = "Emu";
|
nixosCodeName = "Emu";
|
||||||
|
};
|
||||||
|
|
||||||
# Generate /etc/os-release. See
|
# Generate /etc/os-release. See
|
||||||
# http://0pointer.de/public/systemd-man/os-release.html for the
|
# http://0pointer.de/public/systemd-man/os-release.html for the
|
||||||
|
|
Loading…
Reference in New Issue