Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify --version flag to show debugging information #96

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions nix-alien.nix
Original file line number Diff line number Diff line change
@@ -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
}:
Expand Down Expand Up @@ -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} \
Expand Down
4 changes: 2 additions & 2 deletions nix_alien/_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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",
Expand Down
18 changes: 17 additions & 1 deletion nix_alien/_version.py
Original file line number Diff line number Diff line change
@@ -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}
"""
Loading