mirror of
https://github.com/NixOS/nix
synced 2025-07-07 01:51:47 +02:00
Source complete env in nix-shell
with __structuredAttrs = true;
This is needed to push the adoption of structured attrs[1] forward. It's now checked if a `__json` exists in the environment-map of the derivation to be openend in a `nix-shell`. Derivations with structured attributes enabled also make use of a file named `.attrs.json` containing every environment variable represented as JSON which is useful for e.g. `exportReferencesGraph`[2]. To provide an environment similar to the build sandbox, `nix-shell` now adds a `.attrs.json` to `cwd` (which is mostly equal to the one in the build sandbox) and removes it using an exit hook when closing the shell. To avoid leaking internals of the build-process to the `nix-shell`, the entire logic to generate JSON and shell code for structured attrs was moved into the `ParsedDerivation` class. [1] https://nixos.mayflower.consulting/blog/2020/01/20/structured-attrs/ [2] https://nixos.org/manual/nix/unstable/expressions/advanced-attributes.html#advanced-attributes
This commit is contained in:
parent
4b23bf797a
commit
3b5429aec1
9 changed files with 227 additions and 145 deletions
19
tests/structured-attrs-shell.nix
Normal file
19
tests/structured-attrs-shell.nix
Normal file
|
@ -0,0 +1,19 @@
|
|||
with import ./config.nix;
|
||||
let
|
||||
dep = mkDerivation {
|
||||
name = "dep";
|
||||
buildCommand = ''
|
||||
mkdir $out; echo bla > $out/bla
|
||||
'';
|
||||
};
|
||||
in
|
||||
mkDerivation {
|
||||
name = "structured2";
|
||||
__structuredAttrs = true;
|
||||
outputs = [ "out" "dev" ];
|
||||
my.list = [ "a" "b" "c" ];
|
||||
exportReferencesGraph.refs = [ dep ];
|
||||
buildCommand = ''
|
||||
touch ''${outputs[out]}; touch ''${outputs[dev]}
|
||||
'';
|
||||
}
|
|
@ -8,3 +8,9 @@ nix-build structured-attrs.nix -A all -o $TEST_ROOT/result
|
|||
|
||||
[[ $(cat $TEST_ROOT/result/foo) = bar ]]
|
||||
[[ $(cat $TEST_ROOT/result-dev/foo) = foo ]]
|
||||
|
||||
export NIX_BUILD_SHELL=$SHELL
|
||||
[[ ! -e '.attrs.json' ]]
|
||||
env NIX_PATH=nixpkgs=shell.nix nix-shell structured-attrs-shell.nix \
|
||||
--run 'test -e .attrs.json; test "3" = "$(jq ".my.list|length" < .attrs.json)"'
|
||||
[[ ! -e '.attrs.json' ]]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue