From 1181ddb755a8d9207a2809eac4814af71389311d Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Wed, 1 Nov 2023 19:26:23 +0000 Subject: [PATCH] Modify --version flag to show debugging information --- default.nix | 9 +++++---- nix-alien.nix | 16 +++++++++------- nix_alien/_impl.py | 4 ++-- nix_alien/_version.py | 18 +++++++++++++++++- 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/default.nix b/default.nix index 813c294..283cdec 100644 --- a/default.nix +++ b/default.nix @@ -3,16 +3,17 @@ }: let - inherit (pkgs) lib; - dirty = lib.optionalString (!(self ? rev)) "_dirty"; - version = "0.1.0+git${self.lastModifiedDate}${dirty}"; + shortRev = self.shortRev or "dirty"; + version = "0.1.0+git_${shortRev}"; in { nix-alien = pkgs.callPackage ./nix-alien.nix { inherit version; inherit (self.inputs) nix-filter; nix-index = self.inputs.nix-index-database.packages.${pkgs.system}.nix-index-with-db; - nixpkgs-src = self.inputs.nix-index-database.inputs.nixpkgs.sourceInfo; + nix-index-database-src = self.inputs.nix-index-database; + nixpkgs-build-src = self.inputs.nixpkgs; + nixpkgs-src = self.inputs.nix-index-database.inputs.nixpkgs; }; # For backwards compat, may be removed in the future diff --git a/nix-alien.nix b/nix-alien.nix index 14fc77a..8365439 100644 --- a/nix-alien.nix +++ b/nix-alien.nix @@ -1,12 +1,10 @@ { lib , fzf -, nix-index , nix-filter -, nixpkgs-src ? { - lastModifiedDate = "19700101000000"; - rev = "nixpkgs-unstable"; - narHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; - } +, nix-index +, nix-index-database-src +, nixpkgs-build-src +, nixpkgs-src , python3 , version }: @@ -50,7 +48,11 @@ python3'.pkgs.buildPythonApplication { ] ++ (lib.attrVals deps python3'.pkgs); preBuild = '' - echo "__version__ = \"${version}\"" > nix_alien/_version.py + substituteInPlace nix_alien/_version.py \ + --subst-var-by version ${version} \ + --subst-var-by nixIndexDatabaseRev ${nix-index-database-src.rev} \ + --subst-var-by nixpkgsRev ${nixpkgs-src.rev} \ + --subst-var-by nixpkgsBuildRev ${nixpkgs-build-src.rev} substituteInPlace {nix_alien,tests}/*.{py,nix} \ --subst-var-by nixpkgsLastModifiedDate ${nixpkgs-src.lastModifiedDate} \ --subst-var-by nixpkgsRev ${nixpkgs-src.rev} \ diff --git a/nix_alien/_impl.py b/nix_alien/_impl.py index fe92206..d1736a4 100644 --- a/nix_alien/_impl.py +++ b/nix_alien/_impl.py @@ -9,7 +9,7 @@ from platform import machine from typing import Callable, Optional -from ._version import __version__ +from ._version import version from .helpers import edit_file, get_dest_path, get_print, read_template from .libs import find_libs, get_unique_packages @@ -160,7 +160,7 @@ def main( parser = argparse.ArgumentParser() parser.add_argument("program", help="Program to run") - parser.add_argument("--version", action="version", version=__version__) + parser.add_argument("--version", action="version", version=version) parser.add_argument( "-l", "--additional-libs", diff --git a/nix_alien/_version.py b/nix_alien/_version.py index 36554d2..5dc85f5 100644 --- a/nix_alien/_version.py +++ b/nix_alien/_version.py @@ -1 +1,17 @@ -__version__ = "0.1.0+unknown" +__version__ = "@version@" +__nix_index_database_rev__ = "@nixIndexDatabaseRev@" +# They should always be the same unless the user overrides them +__nixpkgs_rev__ = "@nixpkgsRev@" +__nixpkgs_build_rev__ = "@nixpkgsBuildRev@" + +if __nixpkgs_rev__ != __nixpkgs_build_rev__: + nixpkgs_build_rev = f"nixpkgs-build={__nixpkgs_build_rev__}" +else: + nixpkgs_build_rev = "" + +version = f""" +version={__version__} +nix-index-database={__nix_index_database_rev__} +nixpkgs={__nixpkgs_rev__} +{nixpkgs_build_rev} +"""