Commit graph

15021 commits

Author SHA1 Message Date
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
John Ericson
ea2f74cbe1
Merge pull request #9022 from hercules-ci/fix-issue-8838-pathExists-isDir-slash-dot
pathExists: isDir when endswith /.
2023-09-30 00:49:17 -04:00
Robert Hensing
f8a3893e8d pathExists: isDir when endswith /. 2023-09-30 02:35:26 +01:00
Robert Hensing
9c84054f97
Merge pull request #9073 from fricklerhandwerk/pr-guidelines
contributor guide: emphasize solving a well-specified problem with each pull request
2023-09-29 18:11:54 +01:00
John Ericson
461902b860
Merge pull request #9069 from obsidiansystems/libfetchers-prep-0
`libfetchers` improvements without `libflake`
2023-09-29 10:39:45 -04:00
Valentin Gagarin
08145a5be5 contributor guide: emphasize solving a well-specified problem with each pull request
this moves the orientation step to the beginning, and adds notes how to
make sure that a problem is well-spefified and the according change more
likely to get accepted

Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2023-09-29 16:19:14 +02:00
Théophane Hufschmitt
784c7df5bf
Merge pull request #9004 from fricklerhandwerk/release-support
add information on release cycle and backports
2023-09-29 15:04:00 +02:00
Théophane Hufschmitt
a66bd8f1f2
Merge pull request #9065 from fricklerhandwerk/testing-hints
add hint for troubleshooting tests
2023-09-29 13:52:54 +02:00
Valentin Gagarin
1dd03c62ad add hint for troubleshooting tests 2023-09-29 10:46:42 +02:00
John Ericson
89b3952063 Make the indirect fetcher input scheme part of the Flakes XP feature
I don't know much about it, but by the number of times "flake" appears
in the code it seems like is part of flakes, at least for now.
2023-09-28 21:35:36 -04:00
John Ericson
bfe1308d3f Add infra for InputSchemes to be experimental 2023-09-28 21:35:30 -04:00
John Ericson
c816c67eed Reword some comments/API docs to reflect libfetcher's multiple users
It's not just flakes, but also `builtins.fetchTree`. Also try to provide
some more info in general.
2023-09-28 21:10:51 -04:00
John Ericson
b912f3a937 Move flakeIdRegex{,S} from libutil to flakeref.{cc,hh
It isn't used, and doesn't belong in `libutil`.
2023-09-28 20:55:41 -04:00
John Ericson
cede94dbf7 builtins.fetchTree: Mark experimental the new way
This helps ensure uniform docs/error message.
2023-09-28 20:51:25 -04:00
John Ericson
b7e712f9fd
Merge pull request #8509 from wentasah/fetch-tree-doc
Document fetchTree
2023-09-28 15:13:53 -04:00
Andrea Bedini
add7c99c3b Include "original" and "locked" in nix flake prefetch --json 2023-09-28 12:34:06 -04:00
Robert Hensing
62ddb6851f
Merge pull request #8852 from flox/tomberek.absolute.attrpath.notation
Absolute attrPath notation ("flakeref#.attrPath")
2023-09-28 15:52:39 +01:00
tomberek
976f596579
Merge branch 'master' into tomberek.absolute.attrpath.notation 2023-09-28 10:01:57 -04:00
Robert Hensing
13a9090ffc
Merge pull request #9047 from flox/tomberek.string_refactor
string Value refactor
2023-09-28 02:58:57 +01:00
Ilan Joselevich
13ed5d7106 flakes: adopt repl-flake behavior as default 2023-09-27 20:47:10 -04:00
Robert Hensing
ea2fa8b6f3
Merge pull request #8241 from Luabee/patch-1
Mention `$DRV_PATH` in post-build-hook docs
2023-09-28 00:11:00 +01:00
Robert Hensing
11a3dc99b2
Merge pull request #7003 from SuperSandro2000/patch-1
Improve experimental-features error wording
2023-09-27 23:26:27 +01:00
Robert Hensing
dafa38213b
Update doc/manual/src/advanced-topics/post-build-hook.md
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-09-27 23:10:39 +01:00
Robert Hensing
16a6ea7249
Merge pull request #9049 from inclyc/users/inclyc/move-path
libexpr: construct ExprPath by move ctor, not copy cotr
2023-09-27 22:30:44 +01:00
Robert Hensing
4b78a66bc5
Merge pull request #9056 from aakropotkin/patch-1
Respect `NOCOLOR`
2023-09-27 22:29:09 +01:00
Alex Ameen
5bc540a8ca
Respect NOCOLOR
While `nix` has always been respectful towards requests for `NO_COLOR=1`, this change asks represents a new stage of maturity for `nix` - making it also respect quests for `NOCOLOR=1`.

This ideally makes the tool more accessible to folks like me, who are exhausted by guessing whether `NO_COLOR` or `NOCOLOR` is the right environment variable to set.

<3
2023-09-27 14:49:52 -05:00
Valentin Gagarin
57eb62d230
Merge pull request #9051 from cafkafk/patch-2 2023-09-27 07:19:00 +02:00
Tom Bereknyei
399ef84420 refactor: use string accessors
Create context, string_view, and c_str, accessors throughout in order to
better support improvements to the underlying string representation.
2023-09-27 00:33:01 -04:00
Christina Sørensen
1eeea01931
Fix repl.md duplicate typo
Seems like `legacyPackages.x86_64-linux.emacs.name` is accidentally shown twice.
2023-09-27 02:07:43 +00:00
Yingchi Long
5b902ce9d6 libexpr: construct ExprPath by move ctor, not copy cotr 2023-09-26 23:30:32 +08:00
Théophane Hufschmitt
c6faef61a6
Merge pull request #8923 from obsidiansystems/test-proto
Unit test some worker protocol serializers
2023-09-26 17:12:24 +02:00
Robert Hensing
57202969d0
Merge pull request #9040 from waalge/waalge/tail-docstr
fix docstring
2023-09-26 15:32:00 +01:00
Eelco Dolstra
706b91ef62
Merge pull request #9044 from fricklerhandwerk/doc-realise
realisation: reformat for readability
2023-09-26 15:28:20 +02:00
Théophane Hufschmitt
1da1642527
Merge pull request #9041 from trofi/profiles-sign
src/libstore/profiles.cc: fix comparison of sign difference
2023-09-26 07:50:17 +02:00
Valentin Gagarin
a757749fcf reword for readability 2023-09-26 06:28:17 +02:00
Valentin Gagarin
9428d7dcd1
Merge pull request #9045 from fricklerhandwerk/fix-redirects
fix broken redirects script
2023-09-26 04:27:33 +02: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
Tom Bereknyei
7e24dc606b fix(tests): fix assumption that string.s is a char* 2023-09-25 21:37:32 -04:00
Valentin Gagarin
c6f8247032 fix broken reference link 2023-09-26 03:10:12 +02:00
Théophane Hufschmitt
9a78d87bc0
Merge pull request #6614 from RasmusRendal/spaces
Implement support for percent encoded filepaths for flakerefs
2023-09-26 02:27:09 +02:00
Valentin Gagarin
b7d88fe56a
Merge pull request #7320 from fricklerhandwerk/doc-derivation
restructure attribute listing to `derivation`
2023-09-26 01:42:07 +02:00
Valentin Gagarin
45de35bcf1 fix broken redirects script 2023-09-26 01:24:07 +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