Commit graph

106 commits

Author SHA1 Message Date
Valentin Gagarin 8b873edcca
fix anchor link; less weird link texts (#9936) 2024-02-04 21:15:20 +00:00
Rebecca Turner 83bb494a30
Print the value in error: cannot coerce messages
This extends the `error: cannot coerce a TYPE to a string` message
to print the value that could not be coerced. This helps with debugging
by making it easier to track down where the value is being produced
from, especially in errors with deep or unhelpful stack traces.
2024-01-23 15:15:41 -08:00
Brian Le e2399fc949 Change "dervation" typos to "derivation" 2023-12-26 17:12:28 -05:00
Valentin Gagarin 51adfb9b27 reword documentation on settings and attributes related to substitution
- add links
- be more concise
- clarify the distinction between `preferLocalBuild` and `allowSubstitutes`
2023-12-02 02:56:25 +01:00
Jan Tojnar f25c06d7a3 docs: Fix broken link
Link target definitions need to be in a separate paragraph to be collected.

Fixup for 217d863f7a
2023-11-26 19:32:28 +01:00
Robert Hensing 7b0e8c5c2c
Apply suggestions from code review
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-11-17 10:56:23 +01:00
Dominic Shelton c819375769
doc: Add example of inherit in a let expression 2023-11-17 17:50:17 +11:00
Silvan Mosberger 70b396649c doc: logical implication is right-associative
nix-repl> bools = [ false true ]

    nix-repl> combinations = builtins.concatMap (a: builtins.concatMap (b: map (c: { inherit a b c; }) bools) bools) bools

    nix-repl> builtins.all ({ a, b, c }: (a -> b -> c) == (a -> (b -> c))) combinations
    true

    nix-repl> builtins.all ({ a, b, c }: (a -> b -> c) == ((a -> b) -> c)) combinations
    false
2023-11-15 07:04:09 +01:00
Valentin Gagarin 97a0c08873
Expand derivation examples (#9048)
Also use fancier formatting so the example blocks are easier to discern
from the description.

Co-authored-by: John Ericson <git@JohnEricson.me>
2023-10-20 15:17:28 -04:00
Johannes Kirschbauer e58566a057
doc: add reference to hasAttr in ? operator (#9185)
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-10-20 03:11:03 +00:00
Johannes Kirschbauer 42f26eb42e
doc: complexity for '?' operator (#9184)
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2023-10-20 02:45:47 +02:00
Robert Hensing da2b59a088
Merge pull request #8047 from lovesegfault/always-allow-substitutes
feat: add always-allow-substitutes
2023-10-13 15:42:11 +02:00
Ninlives 94e91566ed
Allow CLI to pass environment variables to FOD builder (#8830)
Add a new experimental `impure-env` setting that is a key-value list of
environment variables to inject into FOD derivations that specify the
corresponding `impureEnvVars`.

This allows clients to make use of this feature (without having to change the
environment of the daemon itself) and might eventually deprecate the current
behaviour (pick whatever is in the environment of the daemon) as it's more
principled and might prevent information leakage.
2023-10-11 11:58:42 +00:00
Valentin Gagarin 1e1f08c045 annotate admonitions showing syntax
also fix typos
2023-10-10 00:45:19 +02:00
John Ericson 838be5e4a0
Merge pull request #9114 from fricklerhandwerk/lookup-path
introduce lookup paths as a distinct language construct
2023-10-09 11:28:40 -04:00
John Ericson 217d863f7a Merge branch 'master' into lookup-path 2023-10-09 10:54:54 -04:00
John Ericson 81d3a8542a
doc: Slight reword of "interpolated expression" in paragraph
I was sleepy and confused that "interpolated expression" was a new type of thing at first. This nudges the reader to understand that its just a regular expression, and these conditions are imposed by the interpolation operation.
2023-10-09 10:21:18 -04:00
Valentin Gagarin f00a5eb11b introduce lookup paths as a distinct language construct
so far they did not really have a name, and were at best referred to as
"angle bracket syntax".
2023-10-07 04:44:09 +02:00
Valentin Gagarin a7ba8c3f4a complete example on attribute name interpolation 2023-10-07 02:49:55 +02:00
Valentin Gagarin a67cee965a expand on interpolated expressions 2023-10-07 02:49:55 +02:00
Maximilian Bosch 42e3c6d658 doc: reference NIX_ATTRS_*_FILE vars at the env var reference for drvs 2023-10-01 13:25:29 +01:00
Maximilian Bosch bfdd908f7d structured attrs: improve support / usage of NIX_ATTRS_{SH,JSON}_FILE
In #4770 I implemented proper `nix-shell(1)` support for derivations
using `__structuredAttrs = true;`. Back then we decided to introduce two
new environment variables, `NIX_ATTRS_SH_FILE` for `.attrs.sh` and
`NIX_ATTRS_JSON_FILE` for `.attrs.json`. This was to avoid having to
copy these files to `$NIX_BUILD_TOP` in a `nix-shell(1)` session which
effectively meant copying these files to the project dir without
cleaning up afterwords[1].

On last NixCon I resumed hacking on `__structuredAttrs = true;` by
default for `nixpkgs` with a few other folks and getting back to it,
I identified a few problems with the how it's used in `nixpkgs`:

* A lot of builders in `nixpkgs` don't care about the env vars and
  assume that `.attrs.sh` and `.attrs.json` are in `$NIX_BUILD_TOP`.
  The sole reason why this works is that `nix-shell(1)` sources
  the contents of `.attrs.sh` and then sources `$stdenv/setup` if it
  exists. This may not be pretty, but it mostly works. One notable
  difference when using nixpkgs' stdenv as of now is however that
  `$__structuredAttrs` is set to `1` on regular builds, but set to
  an empty string in a shell session.

  Also, `.attrs.json` cannot be used in shell sessions because
  it can only be accessed by `$NIX_ATTRS_JSON_FILE` and not by
  `$NIX_BUILD_TOP/.attrs.json`.

  I considered changing Nix to be compatible with what nixpkgs
  effectively does, but then we'd have to either move $NIX_BUILD_TOP for
  shell sessions to a temporary location (and thus breaking a lot of
  assumptions) or we'd reintroduce all the problems we solved back then
  by using these two env vars.

  This is partly because I didn't document these variables back
  then (mea culpa), so I decided to drop all mentions of
  `.attrs.{json,sh}` in the  manual and only refer to `$NIX_ATTRS_SH_FILE`
  and `$NIX_ATTRS_JSON_FILE`. The same applies to all our integration tests.
  Theoretically we could deprecated using `"$NIX_BUILD_TOP"/.attrs.sh` in
  the future now.

* `nix develop` and `nix print-dev-env` don't support this environment
  variable at all even though they're supposed to be part of the replacement
  for `nix-shell` - for the drv debugging part to be precise.

  This isn't a big deal for the vast majority of derivations, i.e.
  derivations relying on nixpkgs' `stdenv` wiring things together
  properly. This is because `nix develop` effectively "clones" the
  derivation and replaces the builder with a script that dumps all of
  the environment, shell variables, functions etc, so the state of
  structured attrs being "sourced" is transmitted into the dev shell and
  most of the time you don't need to worry about `.attrs.sh` not
  existing because the shell is correctly configured and the

      if [ -e .attrs.sh ]; then source .attrs.sh; fi

  is simply omitted.

  However, this will break when having a derivation that reads e.g. from
  `.attrs.json` like

      with import <nixpkgs> {};
      runCommand "foo" { __structuredAttrs = true; foo.bar = 23; } ''
        cat $NIX_ATTRS_JSON_FILE # doesn't work because it points to /build/.attrs.json
      ''

  To work around this I employed a similar approach as it exists for
  `nix-shell`: the `NIX_ATTRS_{JSON,SH}_FILE` vars are replaced with
  temporary locations.

  The contents of `.attrs.sh` and `.attrs.json` are now written into the
  JSON by `get-env.sh`, the builder that `nix develop` injects into the
  derivation it's debugging. So finally the exact file contents are
  present and exported by `nix develop`.

  I also made `.attrs.json` a JSON string in the JSON printed by
  `get-env.sh` on purpose because then it's not necessary to serialize
  the object structure again. `nix develop` only needs the JSON
  as string because it's only written into the temporary file.

  I'm not entirely sure if it makes sense to also use a temporary
  location for `nix print-dev-env` (rather than just skipping the
  rewrite in there), but this would probably break certain cases where
  it's relied upon `$NIX_ATTRS_SH_FILE` to exist (prime example are the
  `nix print-dev-env` test-cases I wrote in this patch using
  `tests/shell.nix`, these would fail because the env var exists, but it
  cannot read from it).

[1] https://github.com/NixOS/nix/pull/4770#issuecomment-836799719
2023-10-01 13:22:48 +01:00
Valentin Gagarin 503b02d3f8
Merge pull request #9046 from fricklerhandwerk/fixup-derivation
fix broken reference link
2023-09-26 04:27:23 +02:00
Valentin Gagarin 60a155d01c
Merge pull request #8706 from fricklerhandwerk/doc-system-features
document system features
2023-09-26 04:21:31 +02:00
Valentin Gagarin b17f200b11
Document "Import From Derivation" (#7332)
* document "Import From Derivation"

Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: John Ericson <git@JohnEricson.me>
2023-09-26 01:49:03 +00:00
Valentin Gagarin c6f8247032 fix broken reference link 2023-09-26 03:10:12 +02:00
Valentin Gagarin 5b0336b3b1 reword example for clarity 2023-09-26 00:58:50 +02:00
Valentin Gagarin 7de66f19f8 example: headers -> dev
make the example more realistic, since `headers` is not an output name
used in Nixpkgs

Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2023-09-26 00:46:27 +02:00
Valentin Gagarin 75a231147f be more precise about system semantics 2023-09-26 00:45:00 +02:00
Valentin Gagarin 5e4734a08b reword to avoid saying "build"
derivations are about data transformation, so the term "build" does not
add any information. there was also some feedback that "build task" is
not more helpful than "derivation" if you have no prior experience with
Nix or build systems, while existing associations may be misleading.
2023-09-26 00:45:00 +02:00
Valentin Gagarin 17884f54d1 clarification on extra attributes
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2023-09-26 00:45:00 +02:00
Valentin Gagarin 026c24e378 add example for store path using the given name 2023-09-26 00:45:00 +02:00
Valentin Gagarin d621dd17f2 more precise wording
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2023-09-26 00:45:00 +02:00
Valentin Gagarin e2f118efed restructure and reword input attributes section on derivation 2023-09-26 00:43:58 +02:00
Valentin Gagarin 541890463d make separate section for builder execution 2023-09-26 00:43:58 +02:00
Valentin Gagarin 747b2baf21 fix rendering error for consecutive spaces 2023-09-21 02:51:54 +02:00
Valentin Gagarin 0cd8f36644 add anchor to builder 2023-08-31 21:26:15 +02:00
Théophane Hufschmitt ad410abbe0 Stabilize discard-references
It has been there for a few releases now (landed in 2.14.0), doesn't
seem to cause any major issue and is wanted in a few places
(https://github.com/NixOS/nix/pull/7087#issuecomment-1544471346).
2023-08-07 16:53:37 +02:00
Valentin Gagarin b0173716f6
clarify wording on args@ default handling (#8596)
* clarify wording on args@ default handling

Most importantly use shorter sentences and emphasize the key point that defaults aren't taken into account

Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: John Ericson <git@JohnEricson.me>
2023-07-19 13:07:07 +00:00
Valentin Gagarin 2fa90e5824 add more details on CA derivations 2023-07-19 13:59:18 +02:00
Valentin Gagarin 5f37ebcf83 document all special system features and their behavior 2023-07-19 13:34:03 +02:00
Sinan Mohd a5c88f8609
Nix Reference Manual: keep nix expressions uptodate with nixpkgs (#8703) 2023-07-16 09:25:11 +00:00
Robert Hensing 32c69e2b17 doc: Typo 2023-06-30 18:22:47 +02:00
John Ericson 22b278e011 Automatically document builtin constants
This is done in roughly the same way builtin functions are documented.

Also auto-link experimental features for primops, subsuming PR #8371.

Co-authored-by: Eelco Dolstra <edolstra@gmail.com>
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-06-27 09:37:54 -04:00
John Ericson d40f0e534d Don't say this when we still pollute the global scope
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2023-06-27 09:37:31 -04:00
John Ericson 4da7c86618 Switch example to a primop this is less ill-advised
Any primop will do for this, so might as well use one that isn't impure.

Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2023-06-27 09:34:36 -04:00
Valentin Gagarin c3c4076342 make domain-specificity more specific
also slightly reword the purpose statement to introduce (and explain)
derivations right away.
2023-06-15 03:08:07 +02:00
Valentin Gagarin db680e0e57
refine wording on the purpose of the Nix language
packages and configurations are not really a concept in Nix or the Nix language. the idea of transforming files into other files clearly captures what it's all about, and the new phrasing should make the term "derivation" more obvious both in terms of meaning and origin.
2023-06-08 02:00:05 +02:00
Théophane Hufschmitt 527eb4a99a
Merge pull request #8317 from fricklerhandwerk/doc-identifier
document identifier syntax for attribute sets
2023-06-02 13:10:27 +02:00
Bernardo Meurer bf693319f6
feat: add always-allow-substitutes
This adds a new configuration option to Nix, `always-allow-substitutes`,
whose effect is simple: it causes the `allowSubstitutes` attribute in
derivations to be ignored, and for substituters to always be used.

This is extremely valuable for users of Nix in CI, where usually
`nix-build-uncached` is used. There, derivations which disallow
substitutes cause headaches as the inputs for building already-cached
derivations need to be fetched to spuriously rebuild some simple text
file.

This option should be a good middle-ground, since it doesn't imply
rebuilding the world, such as the approach I took in
https://github.com/NixOS/nixpkgs/pull/221048
2023-05-22 19:42:29 +01:00