1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 10:41:16 +02:00
Commit graph

980 commits

Author SHA1 Message Date
Eelco Dolstra
efcb9e36a9 Remove global fetcher cache
The cache is now part of fetchers::Settings.
2025-05-17 19:54:32 +02:00
Sergei Zimmerman
d8c97d8073
treewide: Use StringSet alias consistently instead of std::set<std::string>
The intention is to switch to transparent comparators from N3657 for
ordered set containers for strings and using the alias consistently
would simplify things.
2025-05-02 17:40:29 +00:00
Eelco Dolstra
4966217b6a Move the InputCache to EvalState 2025-04-14 14:29:14 +02:00
Eelco Dolstra
9d3595646d nix shell: Resolve symlinks in storeFS
`storeFS` is the `MountedSourceAccessor` that wraps `store->getFSAccessor()`.
2025-04-09 17:34:19 -04:00
John Ericson
eb643d034f Store::getFSAccessor: Do not include the store dir
Rather than "mounting" the store inside an empty virtual filesystem,
just return the store as a virtual filesystem. This is more modular.

(FWIW, it also supports two long term hopes of mind:

1. More capability-based Nix language mode. I dream of a "super pure
   eval" where you can only use relative path literals (See #8738), and
   any `fetchTree`-fetched stuff + the store are all disjoint (none is
   mounted in another) file systems.

2. Windows, where the store dir may include drive letters, etc., and is
   thus unsuitable to be the prefix of any `CanonPath`s.

)

Co-authored-by: Eelco Dolstra <edolstra@gmail.com>
2025-04-09 17:34:18 -04:00
Eelco Dolstra
67e957b636 Apply makeNotAllowedError to empty repos 2025-04-02 19:57:49 +02:00
John Ericson
cc24766fa6 Expose the nix component in header include paths
For example, instead of doing

    #include "nix/store-config.hh"
    #include "nix/derived-path.hh"

Now do

    #include "nix/store/config.hh"
    #include "nix/store/derived-path.hh"

This was originally planned in the issue, and also recent requested by
Eelco.

Most of the change is purely mechanical. There is just one small
additional issue. See how, in the example above, we took this
opportunity to also turn `<comp>-config.hh` into `<comp>/config.hh`.
Well, there was already a `nix/util/config.{cc,hh}`. Even though there
is not a public configuration header for libutil (which also would be
called `nix/util/config.{cc,hh}`) that's still confusing, To avoid any
such confusion, we renamed that to `nix/util/configuration.{cc,hh}`.

Finally, note that the libflake headers already did this, so we didn't
need to do anything to them. We wouldn't want to mistakenly get
`nix/flake/flake/flake.hh`!

Progress on #7876
2025-04-01 11:40:42 -04:00
John Ericson
c204e307ac Cleanup config headers
There are two big changes:

1. Public and private config is now separated. Configuration variables
   that are only used internally do not go in a header which is
   installed.

   (Additionally, libutil has a unix-specific private config header,
   which should only be used in unix-specific code. This keeps things a
   bit more organized, in a purely private implementation-internal way.)

2. Secondly, there is no more `-include`. There are very few config
   items that need to be publically exposed, so now it is feasible to
   just make the headers that need them just including the (public)
   configuration header.

And there are also a few more small cleanups on top of those:

- The configuration files have better names.

- The few CPP variables that remain exposed in the public headers are
  now also renamed to always start with `NIX_`. This ensures they should
  not conflict with variables defined elsewhere.

- We now always use `#if` and not `#ifdef`/`#ifndef` for our
  configuration variables, which helps avoid bugs by requiring that
  variables must be defined in all cases.
2025-03-31 23:28:36 -04:00
John Ericson
f3e1c47f47 Separate headers from source files
The short answer for why we need to do this is so we can consistently do
`#include "nix/..."`. Without this change, there are ways to still make
that work, but they are hacky, and they have downsides such as making it
harder to make sure headers from the wrong Nix library (e..g.
`libnixexpr` headers in `libnixutil`) aren't being used.

The C API alraedy used `nix_api_*`, so its headers are *not* put in
subdirectories accordingly.

Progress on #7876

We resisted doing this for a while because it would be annoying to not
have the header source file pairs close by / easy to change file
path/name from one to the other. But I am ameliorating that with
symlinks in the next commit.
2025-03-31 12:20:25 -04:00
Robert Hensing
0c75581d8b Move call-flake.nix to nix-flake
As suggested by Ericson2314 in review
https://github.com/NixOS/nix/pull/12759#issuecomment-2755352343
2025-03-27 14:29:07 +00:00
Robert Hensing
3c4c0953e0 nix-expr: Add primops to EvalSettings 2025-03-26 09:32:43 +00:00
Sergei Zimmerman
adbd08399c {libexpr,libcmd}: Make debugger significantly faster
The underlying issue is that debugger code path was
calling PosTable::operator[] in each eval method.
This has become incredibly expensive since 5d9fdab3de.

While we are it it, I've reworked the code to
not use std::shared_ptr where it really isn't necessary.

As I've documented in previous commits, this is actually
more a workaround for recursive header dependencies now
and is only necessary in `error.hh` code.

Some ad-hoc benchmarking:

After this commit:

```
Benchmark 1: nix eval nixpkgs#hello --impure --ignore-try --no-eval-cache --debugger
  Time (mean ± σ):     784.2 ms ±   7.1 ms    [User: 561.4 ms, System: 147.7 ms]
  Range (min … max):   773.5 ms … 792.6 ms    10 runs
```

On master 3604c7c51:

```
Benchmark 1: nix eval nixpkgs#hello --impure --ignore-try --no-eval-cache --debugger
  Time (mean ± σ):     22.914 s ±  0.178 s    [User: 18.524 s, System: 4.151 s]
  Range (min … max):   22.738 s … 23.290 s    10 runs
```
2025-03-13 16:24:30 +00:00
Brian McKenna
c82ef825d4 coerceToSingleDerivedPathUnchecked: pass through experimental features
This fixes a few of the property tests, now that the property tests
are actually generating arbitrary data - some of that data now
requiring experimental features to function properly.
2025-03-08 19:14:58 +11:00
John Ericson
de22f58dfc Introduce EvalStore::storePath
This abstracts over a common case. Good for brevity, and enabling
further experiments.
2025-02-19 21:24:26 -05:00
Eelco Dolstra
8dc2b2715b In pure eval mode, restrict rootFS to just the Nix store
Note that in pure mode, we don't need to use the union FS even when
using a chroot store, since the user shouldn't have access to the
physical /nix/store.
2025-02-19 23:13:11 +01:00
Eelco Dolstra
99e78c37f7 Use UnionSourceAccessor to mount the chroot store on top of the real store directory 2025-02-19 12:54:09 +01:00
Eelco Dolstra
774b924398 Add a storeFS accessor for paths resulting from IFD
Hopefully fixes #11503.
2025-02-19 12:47:28 +01:00
Eelco Dolstra
e5e0ce2334 Remove redundant call to canonPath()
The CanonPath constructor already does that.
2025-02-19 12:47:28 +01:00
Eelco Dolstra
df08e1e204 resolveLookupPathPath(): Fix caching of negative lookups
This avoids spamming in case the missing search path entry does not
exist (#12480).
2025-02-17 11:50:54 +01:00
Eelco Dolstra
26b87e78b5 copyPathToStore(): Preserve symlinks
E.g. in a derivation attribute `foo = ./bar`, if ./bar is a symlink,
we should copy the symlink to the store, not its target. This restores
the behaviour of Nix <= 2.19.
2025-02-11 20:58:48 +01:00
Eelco Dolstra
00d9e7e1f4 EvalState::resolveLookupPathPath(): Call resolveSymlinks() before pathExists()
Fixes #12339.
2025-01-24 12:15:07 +01:00
Eelco Dolstra
ff9d886f3c Use isAbsolute() 2025-01-14 17:42:26 +01:00
Philipp Otterbein
a44e9dd1ea correctly parse strings with null bytes and throw error 2025-01-04 16:14:06 +01:00
Eelco Dolstra
08361f031d EvalState::realiseContext(): Allow access to the entire closure
Fixes #11030.
2024-12-16 16:16:36 +01:00
Philipp Otterbein
3a9d64b8e3 fromJSON/fromTOML: throw if string contains null byte 2024-12-09 22:04:21 +01:00
Sergei Zimmerman
1800853b2a fix(libexpr/eval-inline): get rid of references to nullptr env
When diagnosing infinite recursion references to nullptr `Env` can be formed.
This happens only with `ExprBlackHole` is evaluated, which always leads to
`InfiniteRecursionError`.

UBSAN log for one such case:

```
../src/libexpr/eval-inline.hh:94:31: runtime error: reference binding to null pointer of type 'Env'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../src/libexpr/eval-inline.hh:94:31 in
```
2024-11-20 17:54:58 +03:00
Robert Hensing
32becc87fe
Merge pull request #11914 from roberth/evalstate-get-builtins
EvalState::getBuiltins
2024-11-19 19:33:37 +01:00
Robert Hensing
5c258d7e25 refactor: Use EvalState::getBuiltins() 2024-11-19 18:45:53 +01:00
Robert Hensing
8a36d2d8a7 Add EvalState::getBuiltins 2024-11-19 18:23:05 +01:00
Eelco Dolstra
af07f33d37 resolveLookupPathPath(): Return a SourcePath instead of a string
Cherry-picked from lazy-trees.
2024-11-19 18:03:31 +01:00
Robert Hensing
a58e38dab7 Make EvalState::getBuiltin safe for missing attr 2024-11-19 17:30:58 +01:00
Eelco Dolstra
3e4a83f53b Use range-based for 2024-11-14 16:12:14 +01:00
Eelco Dolstra
a2e4a4c238 callFunction: Use std::span
This is a bit safer than having a separate nrArgs argument.
2024-11-12 19:26:39 +01:00
Eelco Dolstra
67a42e6240 Merge remote-tracking branch 'origin/master' into flake-substitution 2024-11-11 13:57:24 +01:00
Robert Hensing
a3613f2a3c autoCallFunction: accept const Bindings &
It does not need to mutate the attrs.
`const` is shallow.
Avoids a const_cast in the hercules-ci-cnix-expr bindings.
2024-11-10 20:52:05 +01:00
Eelco Dolstra
4dceca51de Don't allow __final in fetchTree
It's now only allowed in fetchFinalTree, which is not exposed to users
but only to call-flake.nix.
2024-11-08 19:27:54 +01:00
Brian McKenna
d711c7e965 Fix compilation of eval under Windows 2024-11-04 19:32:41 +11:00
Philipp Otterbein
de96f632f8 std::string_view shall not be null terminated 2024-10-08 02:25:14 +02:00
Philipp Otterbein
e21c7895eb MacOS built: add workaround for missing view() member of std::ostringstream 2024-10-07 02:05:53 +02:00
Philipp Otterbein
4c0c8e5428 cleanup: remove superfluous std::string copies 2024-10-06 13:43:29 +02:00
Philipp Otterbein
5cf6b2cb75 eval: remove superfluous strdup 2024-09-30 22:15:04 +02:00
Eelco Dolstra
2f4a7a8301 Add a few more aliases 2024-09-19 21:04:01 +02:00
Eelco Dolstra
589d8f1f2b Move GC-related definitions to eval-gc.hh 2024-09-19 21:04:01 +02:00
Eelco Dolstra
b9f78abb7f Alias traceable_allocator to std::allocator when building without GC
This allows us to get rid of a bunch of #ifdefs.
2024-09-19 21:04:01 +02:00
Robert Hensing
88998fae74
Merge pull request #11304 from hercules-ci/repl-doc-functor
`:doc`: support `__functor`
2024-08-26 17:20:37 +02:00
Robert Hensing
77ddcbe12e
getDoc: Explain why we partially apply __functor 2024-08-26 16:15:13 +02:00
Robert Hensing
72a4d1f52d Add :doc support for __functor 2024-08-15 13:04:34 +02:00
Robert Hensing
6068e32aa7 refactor: Extract EvalState::addCallDepth 2024-08-15 13:04:34 +02:00
Eelco Dolstra
9f6ee93f48 fetchers::downloadTarball(): Return a cacheable accessor
downloadTarball() is used by `-I foo=<url>` etc. fetchToStore() needs
the accessor to have a fingerprint to enable caching.

Fixes #11271.
2024-08-12 15:48:26 +02:00
Robert Hensing
18485d2d53
Merge pull request #11188 from lf-/jade/kill-int-overflow
Ban integer overflow in the Nix language
2024-08-11 04:24:16 +02:00