-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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. Internally, the following things changed: * The logic which generates both `.attrs.json` & `.attrs.sh` used to be tied to `LocalDerivationGoal`, the representation of a derivation's build on the local store. This was e.g. necessary to resolve references to input derivations for `exportReferencesGraph`[2]. * To make sure that the logic is actually usable for `nix-shell`, the behavior had to be moved to the parent-struct `DerivationGoal` to support `nix-shell --store`. For this reason (I assume), the worker doesn't return a `LocalDerivationGoal` by default when passing a `Derivation` to it. * However the `inputRewrites` - used to provide placeholders even if the output path isn't known - aren't part of a (remote) `DerivationGoal` and thus input rewriting is optional in the structured-attrs generator of `DerivationGoal`. Currently, `LocalDerivationGoal` passes the hash rewrites to `DerivationGoal` (i.e. the behavior remains equal), but for a `nix-shell` this behavior is entirely omitted, from my understanding this isn't a problem since a `nix-shell` isn't actually supposed to be used for creating store-paths. * The `nix-shell` now emulates the first step of a derivation's build using a `DerivationGoal` struct in order to retrieve both the raw JSON values for `.attrs.json` and the shell code for the rcfile. As this is practically a no-op for non-structured-attrs builds, this code-path is only reached if `__json` is part of the environment. In a quick, pretty unscientific performance measuring I observed a (reproducible) performance increase of 0.2s for opening a `nix-shell` which is probably related to the way this is implemented. While I'm open for suggestions for alternative implementations, I'd consider this to be OK as long as it's not really noticeable for an end-user. [1] https://nixos.mayflower.consulting/blog/2020/01/20/structured-attrs/ [2] https://nixos.org/manual/nix/unstable/expressions/advanced-attributes.html#advanced-attributes
- Loading branch information
Showing
6 changed files
with
187 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]} | ||
''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters