diff --git a/nixos/modules/installer/tools/get-git-revision b/nixos/modules/installer/tools/get-version-suffix similarity index 95% rename from nixos/modules/installer/tools/get-git-revision rename to nixos/modules/installer/tools/get-version-suffix index b57d9cf9fa0..b8972cd57d2 100644 --- a/nixos/modules/installer/tools/get-git-revision +++ b/nixos/modules/installer/tools/get-version-suffix @@ -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 diff --git a/nixos/modules/installer/tools/nixos-rebuild.sh b/nixos/modules/installer/tools/nixos-rebuild.sh index 80a4537375c..5ecdcdb3cdb 100644 --- a/nixos/modules/installer/tools/nixos-rebuild.sh +++ b/nixos/modules/installer/tools/nixos-rebuild.sh @@ -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 diff --git a/nixos/modules/misc/version.nix b/nixos/modules/misc/version.nix index 6af310a9d87..2ecdbdbf392 100644 --- a/nixos/modules/misc/version.nix +++ b/nixos/modules/misc/version.nix @@ -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."; };