nix-required-mounts: handle __structuredAttrs
This commit is contained in:
parent
6859a2dabc
commit
6662b09941
@ -14,7 +14,8 @@ in
|
||||
system.extraDependencies = [ (pkgs.runCommand "deps" { } "mkdir $out").inputDerivation ];
|
||||
nix.nixPath = [ "nixpkgs=${../../..}" ];
|
||||
nix.settings.substituters = lib.mkForce [ ];
|
||||
nix.settings.system-features = [ "supported-feature" ]; nix.settings.experimental-features = [ "nix-command" ];
|
||||
nix.settings.system-features = [ "supported-feature" ];
|
||||
nix.settings.experimental-features = [ "nix-command" ];
|
||||
programs.nix-required-mounts.enable = true;
|
||||
programs.nix-required-mounts.allowedPatterns.supported-feature = {
|
||||
onFeatures = [ "supported-feature" ];
|
||||
@ -40,5 +41,7 @@ in
|
||||
person_do("nix-build ${./ensure-path-not-present.nix} --argstr feature supported-feature")
|
||||
person_do("nix-build ${./test-require-feature.nix} --argstr feature supported-feature")
|
||||
person_do("nix-build ${./test-require-feature.nix} --argstr feature unsupported-feature", succeed=False)
|
||||
person_do("nix-build ${./test-structured-attrs.nix} --argstr feature supported-feature")
|
||||
person_do("nix-build ${./test-structured-attrs-empty.nix}")
|
||||
'';
|
||||
}
|
||||
|
@ -0,0 +1,10 @@
|
||||
{ pkgs ? import <nixpkgs> { } }:
|
||||
|
||||
pkgs.runCommandNoCC "nix-required-mounts-structured-attrs-no-features"
|
||||
{
|
||||
__structuredAttrs = true;
|
||||
} ''
|
||||
touch $out
|
||||
''
|
||||
|
||||
|
15
nixos/tests/nix-required-mounts/test-structured-attrs.nix
Normal file
15
nixos/tests/nix-required-mounts/test-structured-attrs.nix
Normal file
@ -0,0 +1,15 @@
|
||||
{ pkgs ? import <nixpkgs> { }, feature }:
|
||||
|
||||
pkgs.runCommandNoCC "${feature}-present-structured"
|
||||
{
|
||||
__structuredAttrs = true;
|
||||
requiredSystemFeatures = [ feature ];
|
||||
} ''
|
||||
if [[ -e /${feature}-files ]]; then
|
||||
touch $out
|
||||
else
|
||||
echo "The host declares ${feature} support, but doesn't expose /${feature}-files" >&2
|
||||
echo "Do we fail to parse __structuredAttrs=true derivations?" >&2
|
||||
fi
|
||||
''
|
||||
|
@ -47,6 +47,13 @@ def symlink_parents(p: Path) -> List[Path]:
|
||||
return out
|
||||
|
||||
|
||||
def get_strings(drv_env: dict, name: str) -> List[str]:
|
||||
if "__json" in drv_env:
|
||||
return list(json.loads(drv_env["__json"]).get(name, []))
|
||||
else:
|
||||
return drv_env.get(name, "").split()
|
||||
|
||||
|
||||
def entrypoint():
|
||||
args = parser.parse_args()
|
||||
drv_path = args.derivation_path
|
||||
@ -71,7 +78,7 @@ def entrypoint():
|
||||
capture_output=True,
|
||||
)
|
||||
try:
|
||||
drv = json.loads(proc.stdout)
|
||||
parsed_drv = json.loads(proc.stdout)
|
||||
except json.JSONDecodeError:
|
||||
print(
|
||||
"[E] Couldn't parse the output of"
|
||||
@ -85,7 +92,7 @@ def entrypoint():
|
||||
)
|
||||
print("[I] Exiting the nix-required-binds hook", file=stderr)
|
||||
return
|
||||
[canon_drv_path] = drv.keys()
|
||||
[canon_drv_path] = parsed_drv.keys()
|
||||
|
||||
allowed_patterns = config["allowedPatterns"]
|
||||
known_features = set(
|
||||
@ -94,11 +101,9 @@ def entrypoint():
|
||||
)
|
||||
)
|
||||
|
||||
drv_env = drv[canon_drv_path].get("env", {})
|
||||
features = drv_env.get("requiredSystemFeatures", [])
|
||||
if isinstance(features, str):
|
||||
features = features.split()
|
||||
|
||||
parsed_drv = parsed_drv[canon_drv_path]
|
||||
drv_env = parsed_drv.get("env", {})
|
||||
features = get_strings(drv_env, "requiredSystemFeatures")
|
||||
features = list(filter(known_features.__contains__, features))
|
||||
|
||||
patterns = list(
|
||||
|
Loading…
Reference in New Issue
Block a user