1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-14 14:32:42 +01:00
Commit graph

5028 commits

Author SHA1 Message Date
Sergei Zimmerman
1ca1882e8c libstore: Reallow unbracketed IPv6 addresses in store references
This implements a special back-compat shim to specifically allow
unbracketed IPv6 addresses in store references. This is something
that is relied upon in the wild and the old parsing logic accepted
both ways (brackets were optional). This patch restores this behavior.
As always, we didn't have any tests for this.

Addresses #13937.

(cherry picked from commit 7cc654afa9)
2025-09-08 23:22:41 +00:00
Sergei Zimmerman
bbbb4ce330
libstore: Do not normalize daemon -> unix://, local -> local://
This is relied upon (specifically the `local` store) by existing
tooling [1] and we broke this in 3e7879e6df (which
was first released in 2.31).

To lessen the scope of the breakage we should not normalize "auto" references
and explicitly specified references like "local" or "daemon". It also makes
sense to canonicalize local://,daemon:// to be more compatible with prior
behavior.

[1]: 05e1b3cba2/lib/NOM/Builds.hs (L60-L64)

(cherry picked from commit 3513ab13dc)
2025-09-07 23:38:14 +03:00
John Ericson
702112a41c Fix downstream MinGW build by not looking for Boost Regex
(cherry picked from commit 6bdb5e8e09)
2025-09-05 01:07:02 +00:00
Eelco Dolstra
8e46456dfe SQLite: fsync db.sqlite-shm before opening the database
This is a workaround for https://github.com/NixOS/nix/issues/13515
(opening the SQLite DB randomly taking a couple of seconds on ZFS).

(cherry picked from commit a7fceb5eec)
(cherry picked from commit e492c64c8e)
2025-08-25 22:06:21 +00:00
John Ericson
ec6ba866d1 Limit to lenient parsing of non-standard URLs only where needed
This allows us to put `parseURL` in more spots without furthering
technical debt.

(cherry picked from commit 72a548ed6a)
2025-08-23 12:03:01 -04:00
Eelco Dolstra
615b10cb44
Merge pull request #13800 from NixOS/concurrent-eval-cache
Use WAL mode for SQLite cache databases
2025-08-21 11:42:15 +02:00
John Ericson
4c76db8e7c Make sure settings.sandboxedPaths is closed outside DerivationBuilder
This is a nicer separation of concerns --- `DerivationBuilder` just
mounts the extra paths you tell it too, and the outside world is
responsible for making sure those extra paths make sense.

Since the closure only depends on global settings, and not
per-derivation information, we also have the option of moving this up
further and caching it across all local builds. (I only just realized
this after having done this refactor. I am not doing that change at this
time, however.)
2025-08-20 18:49:11 -04:00
John Ericson
1d3ddb21fa Further consolidate environment variable processing outside DerivationBuilder
Now, `DerivationBuilder` only concerns itself with `finalEnv` and
`extraFiles`, in straightforward unconditional code. All the fancy
desugaring logic is consolidated in `DerivationBuildingGoal`.

We should better share the pulled-out logic with `nix-shell`/`nix
develop`, which would fill in some missing features, arguably fixing
bugs.
2025-08-20 16:54:17 -04:00
John Ericson
e3c74f5a13 Desugar structured attrs, "export reference graph" outside DerivationBuilder
I think this is a better separation of concerns. `DerivationBuilder`
doesn't need to to the final, query-heavy details about how these things
are constructed. It just operates on the level of "simple, stupid" files
and environment variables.
2025-08-20 16:54:17 -04:00
John Ericson
92b10cf3f5 DerivationBuilderImpl::writeStructuredAttrs remove a rewrite
As much as I prefer rewriting the parsed rather than unparsed JSON for
elegance, this gets in the way of the separation of concerns that I am
trying to do.

As a practical matter, any rewriting that this did will also be done by
the second round of rewriting that remains below, so removing this code
should have no effect.
2025-08-20 16:54:17 -04:00
John Ericson
2767ae35d9 Deduplicate "export reference graph" logic a bit
The first part on `drvOptions.exportReferencesGraph` is the same in both
cases. It is just how the information is finally rendered that is
different.
2025-08-20 16:54:17 -04:00
John Ericson
a712445a7a Make Settings::sandboxPaths well-typed
Parsing logic is moved from `DerivationBuilder`, where is doesn't
belong, to `Settings` itself, where it does.
2025-08-20 16:24:37 -04:00
John Ericson
52212635db No more globals.hh in headers
This is needed to rearrange include order, but I also think it is a good
thing anyways, as we seek to reduce the use of global settings variables
over time.
2025-08-20 16:24:37 -04:00
John Ericson
bce29ab2cf Move header outside Unix-only portion
We'll neeed some definitions elsewhere
2025-08-20 16:24:37 -04:00
John Ericson
8463fef161 Expose ChrootPath, PathsInChroot
Will want these for settings in a moment.
2025-08-20 16:24:37 -04:00
John Ericson
d53c7b816b Push #include down to .cc file
That is where it should be.
2025-08-20 16:24:37 -04:00
John Ericson
4ab579b469 Remove constructor from ChrootPath
I rather use designated initializers.
2025-08-20 16:24:36 -04:00
Eelco Dolstra
0df147b145 Bump the version of the SQLite caches
This avoids problems with older versions of Nix that don't put the
caches in WAL mode. That's generally not a problem, until you do something like

  nix build --print-out-paths ... | cachix

which deadlocks because cachix tries to switch the caches to truncate
mode, which requires exclusive access. But the first process cannot
make progress because the cachix process isn't reading from the pipe.
2025-08-20 20:44:58 +02:00
Eelco Dolstra
4ab8ff5b4c SQLite: Use std::filesystem::path 2025-08-20 20:44:21 +02:00
Eelco Dolstra
349d2c58e5 Use WAL mode for SQLite cache databases
With "truncate" mode, if we try to write to the database while another
process has an active write transaction, we'll block until the other
transaction finishes. This is a problem for the evaluation cache in
particular, since it uses long-running transactions.

WAL mode does not have this issue: it just returns "busy" right away,
so Nix will print

  error (ignored): SQLite database '/home/eelco/.cache/nix/eval-cache-v5/...' is busy

and stop trying to write to the evaluation cache. (This was the
intended/original behaviour, see AttrDb::doSQLite().)
2025-08-20 20:34:43 +02:00
John Ericson
088cc176f1
Merge pull request #13795 from xokdvium/factor-out-s3url
libstore: Introduce ParsedS3URL type
2025-08-19 17:28:52 -04:00
Sergei Zimmerman
69fcc2cfc1
libstore: Introduce ParsedS3URL type
This systematizes the way our s3:// URLs are parsed in filetransfer.cc.
Yoinked out and refactored out of [1].

[1]: https://github.com/NixOS/nix/pull/13752

Co-authored-by: Bernardo Meurer Costa <beme@anthropic.com>
2025-08-19 23:39:18 +03:00
John Ericson
a92a996dba
Merge pull request #13793 from xokdvium/c++23
treewide: Bump C++ standard version to C++23
2025-08-19 12:37:17 -04:00
Jörg Thalheim
5c0eff24d5
Merge pull request #13784 from NixOS/queryPathInfo-dont-disconnect
Fix client disconnect when queryPathInfo() returns a negative result
2025-08-19 17:16:47 +02:00
Sergei Zimmerman
03101cc839
treewide: Bump C++ standard version to C++23
Compilers in nixpkgs have caught up and major distros
should also have recent enough compilers. It would be
nice to have newer features like more full featured
ranges and deducing this.
2025-08-19 15:33:27 +03:00
Sergei Zimmerman
62018b3a7f
libstore: Fix formatting
Wasn't caught by CI because the PR wasn't fresh enough
and didn't have formatting checks enabled.
2025-08-18 23:24:10 +03:00
tomberek
dc2478fe79
Merge pull request #13340 from mkenigs/better-error
Improve error when can't acquire db lock
2025-08-18 15:27:58 -04:00
Sergei Zimmerman
1d943f5819
flake: Apply nixfmt 1.0.0 2025-08-18 20:29:45 +03:00
Eelco Dolstra
f51779ee25 RemoteStore::addToStoreFromDump(): Invalidate cache entry for added path 2025-08-18 18:12:42 +02:00
Eelco Dolstra
c82b67fa05 BasicClientConnection::queryPathInfo(): Don't throw exception for invalid paths
This caused RemoteStore::queryPathInfoUncached() to mark the
connection as invalid (see
RemoteStore::ConnectionHandle::~ConnectionHandle()), causing it to
disconnect and reconnect after every lookup of an invalid path. This
caused huge slowdowns in conjunction with
19f89eb684 and lazy-trees.
2025-08-18 18:12:42 +02:00
John Ericson
048cfb9cd6 Delete dangling declaration
There is no definition associated with this.
2025-08-16 11:27:10 -04:00
John Ericson
3b03872ebf
Merge pull request #13766 from obsidiansystems/more-store-dir
Make a few more things use `StoreDirConfig` instead of `Store`
2025-08-15 16:20:39 -04:00
John Ericson
9ccbe23056 DerivationBuilder Change missing initialOutput if..throw to assert
Since this goal has no (goal-wide) notion of "wanted outputs" (we're
building the derivation, and thus making all outputs), we should have
`initialOutputs` for all outputs, and if we're missing one that's an
internal error caused by a bug in Nix.

Concretely, `DerivationBuildingGoal::gaveUpOnSubstitution` now clearly
does create `initialOutputs` for all outputs, whereas a few commits ago
that was not obvious, so I feel confident in saying that this invariant
that should be upheld, in fact is upheld.

`scatchOutputs` is initialized for every initial output, so the same
change to it follows for the same reasons.
2025-08-15 15:50:46 -04:00
John Ericson
870bb68d38 DerivationBuilder::registerOutputs: Inline checkSuffix
It is a simple constant that is only used once.
2025-08-15 15:50:41 -04:00
John Ericson
4bc9ae67c7 Give DerivationBuilder a LocalStore not Store
This is just more honest, since we downcasted it to `LocalStore` in many
places. We had the downcast before because it wasn't needed in the hook
case, just the local building case, but now that `DerivationBuilder` is
separated and just does the building case, we have formalized the
boundary where the single downcast should occur.
2025-08-15 15:50:36 -04:00
John Ericson
14e355d87d Remove InitialOutput::wanted
No derivation goal type has a notion of variable wanted outputs any
more. They either want them all, or they just care about a single
output, in which case we would just store this information for the one
output in question.
2025-08-15 15:50:35 -04:00
John Ericson
79fb9b0d3c Make a few more things use StoreDirConfig instead of Store 2025-08-15 15:35:51 -04:00
John Ericson
64c2ee3f45 Simplify "Store dir" superclass
We can cut out some gratuitous inhertence as follows:

- `MixStoreDirMethods` -> `StoreDirConfig`

- `StoreDirConfig` deleted because no longer needed. It is just folded
  into `StoreConfig`.

- `StoreDirConfigBase` -> `StoreConfigBase` same trick still needed, but
  now is for `StoreConfig` not `StoreDirConfig`

Here's how we got here:

1. I once factored out `StoreDirConfig` in #6236.

2. I factored out `MixStoreDirMethods` in #13154.

But, I didn't realize at point (2) that we didn't need `StoreDirConfig`
anymore, all uses of `StoreDirConfig` could instead be uses of
`MixStoreDirMethods`. Now I am doing that, and renaming
`MixStoreDirMethods` to just `StoreDirConfig` to reduce churn.
2025-08-15 14:12:37 -04:00
Sergei Zimmerman
cea85e79ee
libstore: Fix dangling pointers in DerivationGoal constructors
This leads to a use-after free, because staticOutputHashes returns a temporary
object that dies before we can do a `return *mOutputHash`.

This is most likely the cause for random failures in Hydra [1].

[1]: https://hydra.nixos.org/build/305091330/nixlog/2
2025-08-15 16:39:28 +03:00
Jörg Thalheim
4e776a5be8
Merge pull request #13753 from obsidiansystems/simplify-derivation-goal
Simplify `DerivationGoal` in many ways
2025-08-15 08:25:47 +02:00
Sergei Zimmerman
e74ef417db
libstore: Fix makeCopyPathMessage
Old code completely ignored query parameters and it seems ok to keep
that behavior. There's a lot of code out there that parses nix code
like nix-output-monitor and it can't parse messages like:

> copying path '/nix/store/wha2hi4yhkjmccqhivxavbfspsg1wrsj-source' from 'https://cache.nixos.org' to 'local://'...

Let's not break these tools without a good reason. This goes in line
with what other code does by ignoring parameters in logs.

The issue is just in detecting the shorthand notations for the store
reference - not in printing the url in logs.

By default the daemon opens a local store with ?path-info-cache-size=0,
so that leads to the erronenous 'local://'.
2025-08-15 00:55:03 +03:00
Sergei Zimmerman
1b7ffa53af
treewide: Remove getUri and replace with getHumanReadableURI where appropriate
The problem with old code was that it used getUri for both the `diskCache`
as well as logging. This is really bad because it mixes the textual human
readable representation with the caching.

Also using getUri for the cache key is really problematic for the S3 store,
since it doesn't include the `endpoint` in the cache key, so it's totally broken.

This starts separating the logging / cache concerns by introducing a
`getHumanReadableURI` that should only be used for logging. The caching
logic now instead uses `getReference().render(/*withParams=*/false)` exclusively.
This would need to be fixed in follow-ups, because that's really fragile and
broken for some store types (but it was already broken before).
2025-08-14 16:47:05 +03:00
Sergei Zimmerman
e6f3a193d8
libstore: Fix makeCopyPathMessage after config getUri refactor 2025-08-14 15:52:24 +03:00
John Ericson
4a2de1dbab DerivationGoal Make some fields immutable
We can set both during construction, yay!
2025-08-14 00:39:00 -04:00
John Ericson
f155dffe59 DerivationGoal::done Clean up parameter types
We don't need to ask all these callers to build these single-entry maps
for us.
2025-08-14 00:35:52 -04:00
John Ericson
c940283750 DerivationBuilder
Move output result filtering logic and assert just into the branch where
it is not obviously a no op / meeting the assertion.

Add a comment too, while we are at it.
2025-08-14 00:35:34 -04:00
John Ericson
14441f9382 DerivationGoal inline gaveUpOnSubstitution lambda
We can shuffle around control flow so it's only called once. You'll
definitely want to review this diff ignoring whitespace.
2025-08-14 00:35:24 -04:00
John Ericson
88275e5723 DerivationGoal slight cleanup of some impure drv logic 2025-08-14 00:16:26 -04:00
John Ericson
7707d0acad Get rid of filterDrvOutputs
We don't need it any more, because we only used it in the
single-wanted-output `DerivationGoal`.
2025-08-14 00:09:08 -04:00
John Ericson
766a52ce87 DerivationOutput: Remove outputKnown state
Now that `DerivationGoal::checkPathValidity` is legible, we can see that
it only sets `outputKnown`, and doesn't read it. Likewise, with
co-routines, we don't have tiny scopes that make local variables
difficult. Between these two things, we can simply have
`checkPathValidity` return what it finds, rather than mutate some state,
and update everyting to use local variables.

The same transformation could probably be done to the other derivation
goal types (which currently, unfortunately, contain their own
`checkPathValidity`s, though they are diverging, and we hope and believe
that they continue to diverge).
2025-08-13 23:59:06 -04:00