Skip to content

Commit

Permalink
Add extra-experimental-feature to nix commands
Browse files Browse the repository at this point in the history
Signed-off-by: Henri Rosten <[email protected]>
  • Loading branch information
henrirosten committed Dec 26, 2023
1 parent 9e5ca03 commit 6e316f5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ test-ci: check ## Run CI tests
$(call target_success,$@)

check: clean
nix --extra-experimental-features flakes flake check
nix --extra-experimental-features 'flakes nix-command' flake check

test: ## Run tests
pytest -vx tests/
Expand All @@ -40,11 +40,11 @@ format: clean ## Reformat with black

release-asset: clean ## Build release asset
mkdir -p build/
nix run .#sbomnix -- . \
nix run --extra-experimental-features 'flakes nix-command' .#sbomnix -- . \
--cdx=./build/sbom.runtime.cdx.json \
--spdx=./build/sbom.runtime.spdx.json \
--csv=./build/sbom.runtime.csv
nix run .#sbomnix -- --buildtime . \
nix run --extra-experimental-features 'flakes nix-command' .#sbomnix -- --buildtime . \
--cdx=./build/sbom.buildtime.cdx.json \
--spdx=./build/sbom.buildtime.spdx.json \
--csv=./build/sbom.buildtime.csv
Expand Down
6 changes: 4 additions & 2 deletions src/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ def try_resolve_flakeref(flakeref, force_realise=False):
otherwise, returns None.
"""
LOG.info("Evaluating '%s'", flakeref)
cmd = f"nix eval --raw {flakeref}"
exp = "--extra-experimental-features flakes "
exp += "--extra-experimental-features nix-command"
cmd = f"nix eval --raw {flakeref} {exp}"
ret = exec_cmd(cmd.split(), raise_on_error=False)
if not ret:
LOG.debug("not a flakeref: '%s'", flakeref)
Expand All @@ -195,7 +197,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}"
cmd = f"nix build --no-link {flakeref} {exp}"
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/nixmeta/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ def _get_flake_metadata(flakeref):
if m_nixpkgs:
flakeref = m_nixpkgs.group(1)
# Read nix flake metadata as json
cmd = f"nix flake metadata {flakeref} --json"
exp = "--extra-experimental-features flakes "
exp += "--extra-experimental-features nix-command"
cmd = f"nix flake metadata {flakeref} --json {exp}"
ret = exec_cmd(cmd.split(), raise_on_error=False, return_error=True)
if ret is None or ret.returncode != 0:
LOG.warning("Failed reading flake metadata: %s", flakeref)
Expand Down
7 changes: 4 additions & 3 deletions src/sbomnix/nix.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ def find_deriver(path):
if path.endswith(".drv"):
return path
# Deriver from QueryValidDerivers
ret = exec_cmd(
["nix", "derivation", "show", path], raise_on_error=False, loglevel=LOG_SPAM
)
exp = "--extra-experimental-features flakes "
exp += "--extra-experimental-features nix-command"
cmd = f"nix derivation show {path} {exp}"
ret = exec_cmd(cmd.split(), raise_on_error=False, loglevel=LOG_SPAM)
if not ret:
LOG.log(LOG_SPAM, "Deriver not found for '%s'", path)
return None
Expand Down

0 comments on commit 6e316f5

Please sign in to comment.