lib: deduplicate version/suffix references

The logic regarding the generated `.version-suffix` file is already
defined in `lib/trivial.nix` and shouldn't be duplicated in
`nixos/version`.
This commit is contained in:
Maximilian Bosch 2018-04-24 20:33:35 +02:00
parent f66cdc71a3
commit 39909289f4
No known key found for this signature in database
GPG key ID: 091DBF4D1FC46B8E
2 changed files with 7 additions and 8 deletions

View file

@ -58,11 +58,12 @@ rec {
inherit (lib.strings) fileContents; inherit (lib.strings) fileContents;
version = fileContents ../.version;
suffix = let suffixFile = ../.version-suffix; in
if pathExists suffixFile then fileContents suffixFile else "pre-git";
# Return the Nixpkgs version number. # Return the Nixpkgs version number.
nixpkgsVersion = nixpkgsVersion = version + suffix;
let suffixFile = ../.version-suffix; in
fileContents ../.version
+ (if pathExists suffixFile then fileContents suffixFile else "pre-git");
# Whether we're being called by nix-shell. # Whether we're being called by nix-shell.
inNixShell = builtins.getEnv "IN_NIX_SHELL" != ""; inNixShell = builtins.getEnv "IN_NIX_SHELL" != "";

View file

@ -5,8 +5,6 @@ with lib;
let let
cfg = config.system.nixos; cfg = config.system.nixos;
releaseFile = "${toString pkgs.path}/.version";
suffixFile = "${toString pkgs.path}/.version-suffix";
revisionFile = "${toString pkgs.path}/.git-revision"; revisionFile = "${toString pkgs.path}/.git-revision";
gitRepo = "${toString pkgs.path}/.git"; gitRepo = "${toString pkgs.path}/.git";
gitCommitId = lib.substring 0 7 (commitIdFromGitRepo gitRepo); gitCommitId = lib.substring 0 7 (commitIdFromGitRepo gitRepo);
@ -25,14 +23,14 @@ in
nixos.release = mkOption { nixos.release = mkOption {
readOnly = true; readOnly = true;
type = types.str; type = types.str;
default = fileContents releaseFile; default = trivial.version;
description = "The NixOS release (e.g. <literal>16.03</literal>)."; description = "The NixOS release (e.g. <literal>16.03</literal>).";
}; };
nixos.versionSuffix = mkOption { nixos.versionSuffix = mkOption {
internal = true; internal = true;
type = types.str; type = types.str;
default = if pathExists suffixFile then fileContents suffixFile else "pre-git"; default = trivial.suffix;
description = "The NixOS version suffix (e.g. <literal>1160.f2d4ee1</literal>)."; description = "The NixOS version suffix (e.g. <literal>1160.f2d4ee1</literal>).";
}; };