Commit Graph
57 Commits
Author SHA1 Message Date
skye be34bc0481 testing: migrate and expand import-derivation.sh and warn-import-from-derivation.sh
This started by noticing that the coverage report generated by cl/5489
showed that the error message for when allow-import-from-derivation is
disabled appeared to be not covered by any tests. Since the existing
tests for IFD were in functional, which is deprecated, I migrated those
into functional2 and added a test for erroring when IFD is disabled.

Change-Id: I565674de3dd693e023ec99d501adc4706a6a6964
2026-04-22 10:26:15 -04:00
skye eeac529d5e libexpr/primops: Suppress deprecation warning in prim_importNative
as of cl/5456 prim_importNative default constructs a `Value` in order to
pass as an out parameter to a ValueInitializer function. Default
construction is deprecated, but there isn't a meaningful value to
initialize it to instead. After cl/5357 this will give a deprecation
warning (which in an asanBuild will be an error), so this commit
suppresses that warning for that `Value` construction.

Change-Id: Ie567a6e81b5753672001320e9fc816c56a6a6964
2026-04-22 08:39:55 -04:00
skye 47c9f73d36 doc/manual: Update signature of primop fn in hacking.md
This should have been part of cl/5456, but I didn't notice it at the time.

Change-Id: I3afe75c5862ecd3ce2f616a2ae30aff96a6a6964
2026-04-22 08:39:49 -04:00
skye 84347f94da libexec/kill-user: suppress syscall deprecation warning on darwin
The existing function is used with good reason as explained by its
comment. This suppresses the warning it creates.

Change-Id: I58b0de3f5854266fa77b6a06b7821a636a6a6964
2026-04-22 08:37:17 -04:00
skye cda9e01053 nix-eval-jobs: Remove Value default construction from releaseExprTopLevelValue
Change-Id: I7461323771a50729c66d9e3160c4768f6a6a6964
2026-04-22 08:37:17 -04:00
skye c40afdea73 libexpr/eval-expr: extract makeThunk function that constructs and increments counters
Motivated by needing to remove a Value default construction from
`ExprVar::maybeThunk`, so part of #744

Change-Id: Ia12b5b019e49055ebd7ffa0cc39a59c06a6a6964
2026-04-22 08:37:17 -04:00
skye 0e971cddee libexpr: Delete EvalState::mkSingleDerivedPathString dead function with Value& out param
Part of #1136, I believe this cleans up the final instance of `Value&`
used as an out parameter.

Change-Id: I40153b1f11d5ca9af06cd427f22896d06a6a6964
2026-04-19 12:45:56 -04:00
skye 1e986c81ab Add test for duplicate JSON keys for builtins.fromJSON
Related to #1162
Currently if JSON with duplicate object keys is passed into `builtins.toJSON`,
it will silently drop all but the last value, keeping only the last.
This may be surprising, but as this has been consistent reliable behavior that
users might depend on, we should test for it.

Change-Id: Icc2adefabb161530e7cbfa7330919bab6a6a6964
2026-04-18 17:04:48 -04:00
skye 01f2fabe14 doc: Update Nix Resources link in Quick Start chapter of manual (#1179)
This applies the suggested change in #1179, replacing a dead link with a
link to the content's new location. Closes #1179.

Change-Id: I543e3308516218e224e495b8cf14a7c06a6a6964
2026-04-13 14:18:09 -04:00
skye e79278b4fc Check for throw while evaluating throw message
This is a small tweak to the logic added in cl/1511 to detect explicit
throws when printing stack traces. Now when deciding whether to print
"caused by explicit throw", it checks not only that the error is a
ThrowError and that we are in a throw, but also that the ThrowError was
thrown by *this* throw, and not by another while in the process of
evaluating this throw's operand.

It turns this:

```
let
  set = {
    inner = throw "nested throw";
  };
in
throw set.inner

error:
       … caused by explicit throw
         at /pwd/in.nix:6:1:
            5| in
            6| throw set.inner
             | ^
            7|

       … while evaluating the attribute 'inner'
         at /pwd/in.nix:3:5:
            2|   set = {
            3|     inner = throw "nested throw";
             |     ^
            4|   };

       … caused by explicit throw
         at /pwd/in.nix:3:13:
            2|   set = {
            3|     inner = throw "nested throw";
             |             ^
            4|   };

       error: nested throw
```

into this:

```
error:
       … while calling the 'throw' builtin
         at /pwd/in.nix:6:1:
            5| in
            6| throw set.inner
             | ^
            7|

       … while evaluating the attribute 'inner'
         at /pwd/in.nix:3:5:
            2|   set = {
            3|     inner = throw "nested throw";
             |     ^
            4|   };

       … caused by explicit throw
         at /pwd/in.nix:3:13:
            2|   set = {
            3|     inner = throw "nested throw";
             |             ^
            4|   };

       error: nested throw
```

Notice the difference in the top context frame. Before it incorrectly
attributed the throw error to the both throws instead of just the one
that actually threw.

Change-Id: If3b0b8311f1ae2ff1471e260fe59d9166a6a6964
2026-04-11 12:46:24 -04:00
skye fce5777f9c libexpr/primops: Migrate primops to return Values
A significant part of #1136.
This is a rather large cl, because all of the primops need to be changed
together.

Change-Id: I7d92698d5344bd6186ee4fa47f5c21966a6a6964
2026-04-07 23:38:08 -04:00
skye bc9fb560ac libexpr/primops: Migrate addPath to return a Value
Part of #1136

Change-Id: I079da96c1ed7e7396e5f71b444e4e7b66a6a6964
2026-04-07 23:36:12 -04:00
skye 50aeb770e5 libexpr/primops: Migrate derivationStrictInternal to return a Value
Part of #1136

Change-Id: If00bc51c7ebd5ccd99a883788bc1ec506a6a6964
2026-04-07 23:35:12 -04:00
skye fe38b58e50 libexpr/primops: Migrate helper fn fetch to return a Value
Part of #1136

Change-Id: I5b21998d437aa82fb89e75b0b645269a6a6a6964
2026-04-07 22:40:04 -04:00
skye a1f52a1ce6 libexpr/primops: Migrate helper fn fetchTree to return a Value
Part of #1136

Change-Id: Icb79dfc99f530a2965199954ce784e166a6a6964
2026-04-07 22:39:30 -04:00
skye 6640ba572f libexpr/primops: Migrate helper fn anyorall to return a Value
Part of #1136

Change-Id: Id1aa3225d7c337dee72d070ef764c6006a6a6964
2026-04-07 22:38:52 -04:00
skye aed5b5cbce libexpr: Migrate EvalState::concatLists to return a Value
Part of #1136

Change-Id: Ie28ee8456191b3da20d53e95ea49e0ec6a6a6964
2026-04-07 22:38:24 -04:00
skye c01bd37a8d libexpr/primops: Migrate helper fn elemAt to return a Value
Part of #1136

Change-Id: Ib3c7040c7df729737643d3a9b833773d6a6a6964
2026-04-07 22:38:02 -04:00
skye 658404c2a0 libexpr/json-to-value: Migrate parseJSON to return a Value
Part of #1136

Change-Id: I5ac23ce461a106360b150e64a6bc0f2f6a6a6964
2026-04-07 22:37:44 -04:00
skye bb9f9cf553 lixexpr/primops: Migrate import helper fn to return a Value
Part of #1136

Change-Id: Ia2cdd540a105ae874430c0f6ba456d4d6a6a6964
2026-04-07 22:37:25 -04:00
skye 86126d6c89 libexpr: Migrate EvalPaths::allowAndSetStorePathString to return a Value
Part of #1136

Change-Id: Icf16109a63f1b8114e0af9db0a9213c46a6a6964
2026-04-07 22:35:12 -04:00
skye 03ab7b4a76 package.nix: Remove unused linuxPackages input
This input was added in cl/2884, but was unused even then. The
`linuxPackages` within `buildPackages` is used instead.

Change-Id: I71c522ef683aa098eac0b356b22007ba6a6a6964
2026-03-24 11:43:30 -04:00
skye b94d615baa libexpr/json-to-value: Replace add with addValue and define TopLevelJSONValue
Calls to JSONState::add() always followed an assignment to
JSONState::value(), resulting in the new value going through
JSONState::v for no good reason. The only use of `v` outside of a
pointless stepping stone for `add` was to store the final top-level
Value before it is read out by JSONSax::result(), so it really only
makes sense for the top level JSONState to contain Value field.

Change-Id: I1758c7b770eb4b0c122e501b764dd42b6a6a6964
2026-03-23 19:37:27 -04:00
skye 774f957599 libexpr/attr-set.hh: Deprecate Attr default constructor
The default constructor of Attr default constructs a Value, which is
itself deprecated. Therefore the default constructor of Attr must
itself be either deprecated in turn or removed. The default can't be
trivially deleted because Bindings::EMPTY depends on the default
constructor of Bindings which depends on Attr's default constructor, so
I'm settling for deprecating it for now.

Part of work towards #744

Change-Id: Ie34b08788780615c5478a0354122530b6a6a6964
2026-03-18 22:03:33 -04:00
skye 83bca23d4a libexpr/primops: Avoid Value default construction in primop_removeAttrs
This makes the removal vector a vector of Symbols instead of Attrs, and
uses a custom Compare to still be able to std::set_difference them.

std::ranges::set_difference **should** be the perfect function for this,
but because for some reason it spuriously requires
`std::indirectly_copyable<I2, Out>`, I can't use it here. This
defficiency has bee recognized before [here](https://github.com/cplusplus/papers/issues/1021),
but no one has driven the fix forward.

Part of #744

Change-Id: I6d2c016ea41e033bf38836f859541b506a6a6964
2026-03-18 22:03:33 -04:00
skye cf5e5f599e libexpr/nixexpr: Move backing fields of ExprLiteral subclasses into new
base classes

`ExprLiteral::v` needs to be initialized in ExprLiteral's constructor,
but at the time that it gets initialized subclass fields don't yet exist
so it can't reference them. Previously, `v` was default constructed and
then later assigned a proper value, but this creates a problem when
attempting to remove all default constructions of `Value` from the
codebase. This commit moves the backing fields of each of the subclasses
into new base classes, which exist just to make sure they get
initialized before the `ExprLiteral` base class.

Work towards #744

Change-Id: Ic6d24cab474460b113f2fbcc8d92ad266a6a6964
2026-03-17 15:48:12 -04:00
skye 51c6d6a2e8 libexpr: Remove various default constructions of Values
Progress towards #744

Change-Id: I138ecf7ab712ea570ecbf506c7b6f6be6a6a6964
2026-03-17 15:48:12 -04:00
skye 8b99b75698 libexpr: Push Values onto vectors instead of default constructing
ahead of time

Rather than creating fixed size vectors of default constructed Values
before assigning to those elements, reserve the desired capacity and
then push created values onto the vector. This avoids default
constructing any Values.

Part of fixing #744

Change-Id: I36eff4275a893b181eaf3ce145b1ee446a6a6964
2026-03-17 15:48:12 -04:00
skye 179164cffc libexpr: Migrate EvalState::mkPos to return a Value
Part of #1136 and progress towards #744

Change-Id: I31d0169077954ea82c9c7d341afdccd76a6a6964
2026-03-17 15:48:12 -04:00
skye 810a3bad11 libexpr: replace BindingsBuilder::alloc with insert
Progress towards #744
`alloc` default constructed a `Value` which is a problem because the
defaut constructor of `Value` is deprecated

Change-Id: I789cba20bd98728758395080a3a9cf6e6a6a6964
2026-03-17 15:48:12 -04:00
skye f0891b440f libexpr/primops/fromTOML: Migrate visit lambda to return a value
Necessary step to replace BindingsBuilder::alloc uses with insert

Arguably part of #1136

Change-Id: I72acdd1676cf2dda69bce39e9b7feb656a6a6964
2026-03-17 15:48:12 -04:00
skye 570357c733 libexpr: Replace Value::mkNull with Value::VNULL
A small step towards fixing #744

Change-Id: If8304d4de20bae07b33eb7825f781e0f6a6a6964
2026-03-17 15:48:12 -04:00
skye c452341b39 libexpr: Replace Value::mkExternal with constructor call
Change-Id: I7f92a91f6510be8948dfe0765b3fec6f6a6a6964
2026-03-14 13:55:59 -04:00
skye 3c9f42443e libexpr: Migrate mkStorePathString to return a Value
part of #1136

Change-Id: I32ba0f8ef369a82ceb8f75816a2ce6dc6a6a6964
2026-03-14 13:55:59 -04:00
skye 72a456210e libexpr: Migrate makePositionThunks to return Value tuple
part of #1136 and a step towards #744

Change-Id: Ib2ccea4c098bbb66eaa47645b6fa59e56a6a6964
2026-03-14 13:55:59 -04:00
skye 3a18ed52e2 libexpr: Migrate EvalState::mkOutputString to return a Value
part of #1136 and a small step toward resolving #744

Change-Id: I4e1602b37c40517a92cbab8fe4074d7e6a6a6964
2026-03-14 13:55:59 -04:00
skye 8b38edaf1e libexpr: Migrate emitTreeAttrs to return a Value
Part of #1136 and progress towards #744

Change-Id: Iaa011161b26bda237bcf4424bf8262726a6a6964
2026-03-04 11:53:34 -05:00
skye 9a408cbeb7 libexpr: Replace Value::mkPrimOp with constructor calls
Change-Id: I19b05e260945e237f7856b5d644a43076a6a6964
2026-03-01 18:02:58 -05:00
skye 12cee5cb22 libcmd/repl: Migrate evalString to return a Value
Change-Id: I41cd79b71106474d048d447befac16676a6a6964
2026-03-01 01:01:47 -05:00
skye 8623dade34 libexpr: Migrate callFlake to return a Value
Change-Id: Ibdac6eb1c9dfda894d783a7b6e333f486a6a6964
2026-03-01 01:01:47 -05:00
skye 2be998eeb4 libexpr: Migrate Evaluator::evalLazily to return a Value
Change-Id: I9f778407d454e141cb9b7959bbc02ed26a6a6964
2026-03-01 01:01:47 -05:00
skye c6b4f30be9 libexpr: Migrate EvalState::autoCallFunction to return a Value
Change-Id: I426c3d413b18848090dd05674a08e5fb6a6a6964
2026-03-01 01:01:47 -05:00
skye 27bf276304 legacy/nix-env: Migrate loadSourceExpr to return a Value
Change-Id: Ia1e1ac6fe9fd00d7a2fa4a39a3ce21e86a6a6964
2026-03-01 00:04:28 -05:00
skye f856d4fd25 libexpr: Migrate EvalState::evalFile to return a Value
Change-Id: I19ce8623477dd96628476b3e3dd58cfd6a6a6964
2026-02-28 15:53:10 -05:00
skye debf5554e0 libexpr: Consolidate implementation between Value string constructors
Change-Id: I5bf8d58b534cd652d89f7b93019378b66a6a6964
2026-02-28 15:53:10 -05:00
skye be3a40e5dc libexpr: Replace Value::mkString with constructor calls
Change-Id: I55bba546eb090728a71734450a2a5f496a6a6964
2026-02-28 15:53:10 -05:00
skye 53c0e884d8 Migrate EvalState::eval from out param to return a Value
Instead of taking in a final argument `Value &` out parameter which it
writes to, it now returns its result

Change-Id: Iab6bc3a3ac6a4b17c6d31115a766a6ea6a6a6964
2026-02-24 13:00:30 -05:00
skye d14613459b libexpr: Migrate EvalState::callFunction to return a Value
Previously it had an out parameter. Now it has a return value.

Change-Id: I9ec465a7d23b99da9132f1ab0fcc5cf16a6a6964
2026-02-24 13:00:30 -05:00
skye 1ef7ccfc72 libexpr: migrate Expr::eval to return a Value, take 2
This is a rebase of CL 1626 after the performance problems that blocked
that change are no longer an issue.

Change-Id: I4a17f7606c5fdc9a924933a860eb401f6a6a6964
2026-02-23 18:11:47 -05:00
skye 62a2663436 libexpr: Replace Value::mkBool with constructor calls
Change-Id: I714271f6cbd2f5b2d6e1e7fe7eb7feab6a6a6964
2026-02-23 15:12:35 -05:00
skye 864c5e7507 libexpr: Replace Value::mkInt with constructor calls
Change-Id: I09b8e3aa61042a60c2ae767fc44c26b66a6a6964
2026-02-23 11:55:02 -05:00
skye 23a0b78a16 libexpr: Replace Value::mkFloat with constructor calls
The pseudo-constructor `Value::mkFloat` would previously be called on an
default-constructed (under-initialized) `Value` to create a properly
initialized `Value` that represents a float. This change removes mkFloat
and constructs float `Value`s directly.

Change-Id: I48ae3a836842ce5e5eda6323404ba7576a6a6964
2026-02-23 11:51:29 -05:00
skye 492d7bbe1f libexpr: Convert Value::mkStringMove to a constructor
The pseudo-constructor `Value::mkStringMove` would previously be called
on a default-constructed (under-initialized) `Value` to create a
properly initialized `Value` that represents a string, reusing an
existing GC allocated Str. This change turns that method into a proper
constructor

Change-Id: I8d7a97e2afce231a04ecf56fdd6d22d06a6a6964
2026-02-23 11:40:02 -05:00
skye e8f161ead1 libexpr: Replace Value::mkPath with constructor calls
The pseudo-constructor `Value::mkPath` would previously be called on an
default-constructed (under-initialized) `Value` to create a properly
initialized `Value` that represents a path. This change
removes mkPath and constructs path `Value`s directly.

Change-Id: I9021de1ff59490828f9fec6866e083996a6a6964
2026-02-23 09:37:40 -05:00
skye d07bbb109e libexpr: Replace Value::mkAttrs with constructor calls
The pseudo-constructor `Value::mkAttrs` would previously be called on an
default-constructed (under-initialized) `Value` to create a properly
initialized `Value` that represents an attribute set. This change
removes mkAttrs and constructs attr `Value`s directly.

Change-Id: I11cd801eefecd454a7a5b6229d6770d06a6a6964
2026-02-23 03:54:35 +00:00
SkyeandLix Systems Gerrit 73114a1b8b Merge "Clean up includes" into main 2025-04-09 18:00:08 +00:00
skyrelia ba1c9d52ec Clean up includes
This cleans up includes that clangd reports as unused, usually by deleting the offending include. The process was to delete an include and see if it still builds. If not, try to find a more specific include(s) that works, that was previously transitively included. If the original include seems intended to re-export said transitive include, mark the transitive include as `// IWYU pragma: export`. Otherwise, replace the original include with the transitive include(s). If none of the above applies, because the original file depends on code directly in the include somehow, or the direct include is an external dependency that cannot be modified, restore the original include and mark it as `// IWYU pragma: keep`.

Change-Id: I5ce3d34dad76b0cad0a6a7990fea13add393aad3
2025-04-08 12:13:42 +00:00