version.nix: extract revision-fetching function
This commit is contained in:
parent
730dac1d7b
commit
4312cfdbda
|
@ -105,6 +105,16 @@ rec {
|
||||||
then lib.strings.fileContents suffixFile
|
then lib.strings.fileContents suffixFile
|
||||||
else "pre-git";
|
else "pre-git";
|
||||||
|
|
||||||
|
# Attempt to get the revision nixpkgs is from
|
||||||
|
revisionWithDefault = default:
|
||||||
|
let
|
||||||
|
revisionFile = "${toString ./..}/.git-revision";
|
||||||
|
gitRepo = "${toString ./..}/.git";
|
||||||
|
in if lib.pathIsDirectory gitRepo
|
||||||
|
then lib.commitIdFromGitRepo gitRepo
|
||||||
|
else if lib.pathExists revisionFile then lib.fileContents revisionFile
|
||||||
|
else default;
|
||||||
|
|
||||||
nixpkgsVersion = builtins.trace "`lib.nixpkgsVersion` is deprecated, use `lib.version` instead!" version;
|
nixpkgsVersion = builtins.trace "`lib.nixpkgsVersion` is deprecated, use `lib.version` instead!" version;
|
||||||
|
|
||||||
# Whether we're being called by nix-shell.
|
# Whether we're being called by nix-shell.
|
||||||
|
|
|
@ -5,7 +5,6 @@ with lib;
|
||||||
let
|
let
|
||||||
cfg = config.system.nixos;
|
cfg = config.system.nixos;
|
||||||
|
|
||||||
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);
|
||||||
in
|
in
|
||||||
|
@ -37,9 +36,7 @@ in
|
||||||
nixos.revision = mkOption {
|
nixos.revision = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
type = types.str;
|
type = types.str;
|
||||||
default = if pathIsDirectory gitRepo then commitIdFromGitRepo gitRepo
|
default = lib.trivial.revisionWithDefault "master";
|
||||||
else if pathExists revisionFile then fileContents revisionFile
|
|
||||||
else "master";
|
|
||||||
description = "The Git revision from which this NixOS configuration was built.";
|
description = "The Git revision from which this NixOS configuration was built.";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue