Skip to content

Commit

Permalink
Allow running nix with --impure
Browse files Browse the repository at this point in the history
  • Loading branch information
ndam-hexagon committed Jan 27, 2025
1 parent 79f5f02 commit 1a33125
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def exit_unless_nix_artifact(path, force_realise=False):
sys.exit(1)


def try_resolve_flakeref(flakeref, force_realise=False):
def try_resolve_flakeref(flakeref, force_realise=False, impure=False):
"""
Resolve flakeref to out-path, force-realising the output if `force_realise`
is True. Returns resolved path if flakeref can be resolved to out-path,
Expand All @@ -181,7 +181,8 @@ def try_resolve_flakeref(flakeref, force_realise=False):
LOG.info("Evaluating '%s'", flakeref)
exp = "--extra-experimental-features flakes "
exp += "--extra-experimental-features nix-command"
cmd = f"nix eval --raw {flakeref} {exp}"
extra_args = "--impure" if impure else ""
cmd = f"nix eval --raw {flakeref} {exp} {extra_args}"
ret = exec_cmd(cmd.split(), raise_on_error=False)
if not ret:
LOG.debug("not a flakeref: '%s'", flakeref)
Expand All @@ -191,7 +192,7 @@ def try_resolve_flakeref(flakeref, force_realise=False):
if not force_realise:
return nixpath
LOG.info("Try force-realising flakeref '%s'", flakeref)
cmd = f"nix build --no-link {flakeref} {exp}"
cmd = f"nix build --no-link {flakeref} {exp} {extra_args}"
ret = exec_cmd(cmd.split(), raise_on_error=False, return_error=True)
if not ret:
LOG.fatal("Failed force_realising %s: %s", flakeref, ret.stderr)
Expand Down
4 changes: 3 additions & 1 deletion src/sbomnix/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def getargs():
group.add_argument("--cdx", nargs="?", help=helps, default="sbom.cdx.json")
helps = "Path to spdx json output file (default: ./sbom.spdx.json)"
group.add_argument("--spdx", nargs="?", help=helps, default="sbom.spdx.json")
helps = "Run nix command with --impure"
parser.add_argument("--impure", help=helps, action="store_true")

return parser.parse_args()

Expand All @@ -72,7 +74,7 @@ def main():
set_log_verbosity(args.verbose)
runtime = args.buildtime is False
flakeref = None
target_path = try_resolve_flakeref(args.NIXREF, force_realise=runtime)
target_path = try_resolve_flakeref(args.NIXREF, force_realise=runtime, impure=args.impure)
if target_path:
flakeref = args.NIXREF
else:
Expand Down

0 comments on commit 1a33125

Please sign in to comment.