aboutsummaryrefslogtreecommitdiff
path: root/src/nix-build
AgeCommit message (Collapse)Author
2021-07-12Merge branch 'master' into structured-attrs-shellMaximilian Bosch
Conflicts: src/nix/develop.cc src/nix/get-env.sh tests/shell.nix
2021-06-24Perform input rewrites only in LocalDerivationGoalMaximilian Bosch
2021-06-22Move `writeStructuredAttrsShell` out of `ParsedDerivation` classMaximilian Bosch
2021-06-22Prefix env vars for attrs.* files with NIX_Maximilian Bosch
2021-06-22Split shell & json creation for build environments with structured attrsMaximilian Bosch
2021-06-22Set environment variables for .attrs.json & .attrs.shMaximilian Bosch
This way no derivation has to expect that these files are in the `cwd` during the build. This is problematic for `nix-shell` where these files would have to be inserted into the nix-shell's `cwd` which can become problematic with e.g. recursive `nix-shell`. To remain backwards-compatible, the location inside the build sandbox will be kept, however using these files directly should be deprecated from now on.
2021-06-22Source complete env in `nix-shell` with `__structuredAttrs = true;`Maximilian Bosch
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
2021-06-22nix-shell: Replace resolving failure error by an assertionregnat
This shouldn’t happen in practice, so better make it explicit
2021-06-11Make `nix-shell` support content-addressed derivationsregnat
Resolve the derivation before trying to load its environment − essentially reproducing what the build loop does − so that we can effectively access our dependencies (and not just their placeholders). Fix #4821
2021-04-07restoreSignals() + restoreAffinity() -> restoreProcessContext()Eelco Dolstra
2021-04-05Rename BuildableJohn Ericson
2021-04-05Use `BuildableReq` for `buildPaths` and `ensurePath`John Ericson
This avoids an ambiguity where the `StorePathWithOutputs { drvPath, {} }` could mean "build `brvPath`" or "substitute `drvPath`" depending on context. It also brings the internals closer in line to the new CLI, by generalizing the `Buildable` type is used there and makes that distinction already. In doing so, relegate `StorePathWithOutputs` to being a type just for backwards compatibility (CLI and RPC).
2021-03-04nix-build: set execfailBernardo Meurer
When starting a nix-shell with `-i` it was previously possible for it to silently fail in the scenario where the specified interpreter didn't exist. This happened due to the `exec` call masking the issue. With this change we enable `execfail`, which causes the script using `nix-shell` as interpreter to correctly exit with code 127. Fixes: #4598
2021-02-24Initialize plugins after handling initial command line flagsShea Levy
This is technically a breaking change, since attempting to set plugin files after the first non-flag argument will now throw an error. This is acceptable given the relative lack of stability in a plugin interface and the need to tie the knot somewhere once plugins can actually define new subcommands.
2021-02-19Don't crash nix-build when not all outputs are realisedregnat
Change the `nix-build` logic for linking/printing the output paths to allow for some outputs to be missing. This might happen when the toplevel derivation didn't have to be built, either because all the required outputs were already there, or because they have all been substituted.
2021-01-26Move command plugin interface to libnixcmdShea Levy
2021-01-21Improve error formattingEelco Dolstra
Changes: * The divider lines are gone. These were in practice a bit confusing, in particular with --show-trace or --keep-going, since then there were multiple lines, suggesting a start/end which wasn't the case. * Instead, multi-line error messages are now indented to align with the prefix (e.g. "error: "). * The 'description' field is gone since we weren't really using it. * 'hint' is renamed to 'msg' since it really wasn't a hint. * The error is now printed *before* the location info. * The 'name' field is no longer printed since most of the time it wasn't very useful since it was just the name of the exception (like EvalError). Ideally in the future this would be a unique, easily googleable error ID (like rustc). * "trace:" is now just "…". This assumes error contexts start with something like "while doing X". Example before: error: --- AssertionError ---------------------------------------------------------------------------------------- nix at: (7:7) in file: /home/eelco/Dev/nixpkgs/pkgs/applications/misc/hello/default.nix 6| 7| x = assert false; 1; | ^ 8| assertion 'false' failed ----------------------------------------------------- show-trace ----------------------------------------------------- trace: while evaluating the attribute 'x' of the derivation 'hello-2.10' at: (192:11) in file: /home/eelco/Dev/nixpkgs/pkgs/stdenv/generic/make-derivation.nix 191| // (lib.optionalAttrs (!(attrs ? name) && attrs ? pname && attrs ? version)) { 192| name = "${attrs.pname}-${attrs.version}"; | ^ 193| } // (lib.optionalAttrs (stdenv.hostPlatform != stdenv.buildPlatform && !dontAddHostSuffix && (attrs ? name || (attrs ? pname && attrs ? version)))) { Example after: error: assertion 'false' failed at: (7:7) in file: /home/eelco/Dev/nixpkgs/pkgs/applications/misc/hello/default.nix 6| 7| x = assert false; 1; | ^ 8| … while evaluating the attribute 'x' of the derivation 'hello-2.10' at: (192:11) in file: /home/eelco/Dev/nixpkgs/pkgs/stdenv/generic/make-derivation.nix 191| // (lib.optionalAttrs (!(attrs ? name) && attrs ? pname && attrs ? version)) { 192| name = "${attrs.pname}-${attrs.version}"; | ^ 193| } // (lib.optionalAttrs (stdenv.hostPlatform != stdenv.buildPlatform && !dontAddHostSuffix && (attrs ? name || (attrs ? pname && attrs ? version)))) {
2020-11-24Escape filename given to nix-shell in shebang modeLily Ballard
This prevents spaces or other metacharacters from causing nix-shell to execute the wrong path. Fixes #4229.
2020-11-13nix-build: Fix #4197 output order regressionRobert Hensing
2020-10-09Split out `local-fs-store.hh`John Ericson
This matches the already-existing `local-fs-store.cc`.
2020-10-06Remove static variable name clashesEelco Dolstra
This was useful for an experiment with building Nix as a single compilation unit. It's not very useful otherwise but also doesn't hurt...
2020-09-15Merge remote-tracking branch 'upstream/master' into single-ca-drv-buildJohn Ericson
2020-09-04Add `nix-shell` support for preserving PS1Gabriel Gonzalez
Fixes https://github.com/NixOS/nix/issues/1268 `nix-shell` will now preserve `PS1` if the `NIX_SHELL_PRESERVE_PROMPT` environment variable is set.
2020-09-03Merge remote-tracking branch 'upstream/master' into single-ca-drv-buildJohn Ericson
2020-09-03addPermRoot(): Remove indirect flagEelco Dolstra
2020-08-20Rename drv output querying functions, like masterJohn Ericson
- `queryDerivationOutputMapAssumeTotal` -> `queryPartialDerivationOutputMap` - `queryDerivationOutputMapAssumeTotal` -> `queryDerivationOutputMap
2020-08-07Squashed get CA derivations buildingJohn Ericson
2020-07-30unsigned long long -> uint64_tEelco Dolstra
2020-07-29Prevent nix-build from accepting --run/--commandMat Marini
2020-07-29Prevent nix-build from accepting --packagesMat Marini
2020-06-17appended ' __attribute__((weak)); ' to 'extern char * * environ 'p01arst0rm
2020-06-16Remove StorePath::clone() and related functionsEelco Dolstra
2020-06-15Get rid of explicit ErrorInfo constructorsEelco Dolstra
2020-06-11Merge remote-tracking branch 'upstream/master' into errors-phase-2Ben Burdette
2020-06-08Make the logger customisableregnat
Add a new `--log-format` cli argument to change the format of the logs. The possible values are - raw (the default one for old-style commands) - bar (the default one for new-style commands) - bar-with-logs (equivalent to `--print-build-logs`) - internal-json (the internal machine-readable json format)
2020-05-11switch from printError warnings to logWarningsBen Burdette
2020-05-07pretending to be constBen Burdette
2020-05-03convert some printError calls to logErrorBen Burdette
2020-03-30Remove global -I flagsEelco Dolstra
(cherry picked from commit 2c692a3b144523bca68dd6de618124ba6c9bb332)
2020-03-24findAlongAttrPath(): Return positionEelco Dolstra
(cherry picked from commit 0b013a54dc570395bed887369f8dd622b8ce337b)
2020-03-04nix-build: Fix !<output> handlingEelco Dolstra
This was broken by 22a754c091f765061f59bef5ce091268493bb138. https://hydra.nixos.org/eval/1573669
2020-02-19Merge pull request #3325 from xzfc/clean-tmpdirEelco Dolstra
nix-shell: clean up the tmpDir and escape variables
2020-02-19nix-shell: clean up the tmpDir and escape variablesAlbert Safin
The problem fixed: each nix-shell invocation creates a new temporary directory (`/tmp/nix-shell-*`) and never cleans up. And while I'm here, shellescape all variables inlined into the rcfile. See what might happen without escaping: $ export TZ="';echo pwned'" $ nix-shell -p hello --run hello pwned Hello, world!
2020-02-14Pass through http proxy env vars in pure shellCarlos D
2019-12-14nix-shell: don't check for "nix-shell" in shebang script nameAlbert Safin
2019-12-10Make the Store API more type-safeEelco Dolstra
Most functions now take a StorePath argument rather than a Path (which is just an alias for std::string). The StorePath constructor ensures that the path is syntactically correct (i.e. it looks like <store-dir>/<base32-hash>-<name>). Similarly, functions like buildPaths() now take a StorePathWithOutputs, rather than abusing Path by adding a '!<outputs>' suffix. Note that the StorePath type is implemented in Rust. This involves some hackery to allow Rust values to be used directly in C++, via a helper type whose destructor calls the Rust type's drop() function. The main issue is the dynamic nature of C++ move semantics: after we have moved a Rust value, we should not call the drop function on the original value. So when we move a value, we set the original value to bitwise zero, and the destructor only calls drop() if the value is not bitwise zero. This should be sufficient for most types. Also lots of minor cleanups to the C++ API to make it more modern (e.g. using std::optional and std::string_view in some places).
2019-11-22getEnv(): Return std::optionalEelco Dolstra
This allows distinguishing between an empty value and no value.
2019-10-27SimplificationEelco Dolstra
2019-10-27Add inNixShell = true to nix-shell auto-callRobert Hensing
This is an alternative to the IN_NIX_SHELL environment variable, allowing the expression to adapt itself to nix-shell without triggering those adaptations when used as a dependency of another shell. Closes #3147
2019-10-09nix-build: Fix compilationEelco Dolstra