Merge branch 'nixpkgs-git-revision-fix'

Addresses #17218 in a better way in that it doesn't create a
".git-revision" file on every nixos-rebuild, because we already have
".git" available. Even if we don't nixos-rebuild can't create the
"git-revision" file.

Tested via:

nix-build -E '(import ./nixos/tests/make-test.nix {
  name = "foo";
  machine = {};
  testScript = "startAll; $machine->execute(\"nixos-version >&2\");";
})'

Closes: #17610
Acked-by: @bennofs
This commit is contained in:
aszlig 2016-08-09 17:34:35 +02:00
commit f8fad62c8e
No known key found for this signature in database
GPG Key ID: 1DE8E48E57DB5436
3 changed files with 7 additions and 6 deletions

View File

@ -17,6 +17,6 @@ getVersion() {
if nixpkgs=$(nix-instantiate --find-file nixpkgs "$@"); then
getVersion $nixpkgs
if [ -n "$rev" ]; then
echo "$rev"
echo ".git.$rev"
fi
fi

View File

@ -311,10 +311,9 @@ fi
# nixos-version shows something useful).
if [ -n "$canRun" ]; then
if nixpkgs=$(nix-instantiate --find-file nixpkgs "${extraBuildFlags[@]}"); then
revision=$($SHELL $nixpkgs/nixos/modules/installer/tools/get-git-revision "${extraBuildFlags[@]}" || true)
if [ -n "$revision" ]; then
echo -n ".git.$revision" > "$nixpkgs/.version-suffix" || true
echo -n "$revision" > "$nixpkgs/.git-revision" || true
suffix=$($SHELL $nixpkgs/nixos/modules/installer/tools/get-version-suffix "${extraBuildFlags[@]}" || true)
if [ -n "$suffix" ]; then
echo -n "$suffix" > "$nixpkgs/.version-suffix" || true
fi
fi
fi

View File

@ -63,7 +63,9 @@ in
nixosRevision = mkOption {
internal = true;
type = types.str;
default = if pathExists revisionFile then fileContents revisionFile else "master";
default = if pathIsDirectory gitRepo then commitIdFromGitRepo gitRepo
else if pathExists revisionFile then fileContents revisionFile
else "master";
description = "The Git revision from which this NixOS configuration was built.";
};