Commit Graph
100 Commits
Author SHA1 Message Date
eldritch horrors 484319fd2d libstore: remove unused Derivation::tryResolve
Change-Id: Ia36b066badf60b3727ec6c6a04057c3c97461e2c
2025-05-20 17:43:46 +00:00
eldritch horrors 01dcbf3359 libstore: remove Derivation::hasKnownOutputPaths
it's always true now that floating and deferred outputs are gone.

Change-Id: Ie694b9af4d2c247c0fb4fdebadd55a0a487b9828
2025-05-20 17:43:46 +00:00
eldritch horrors e543ac686f libstore: remove DerivationOutput::Deferred
we can't create these any more except by reading an old json-formatted
derivation that used them. since we cannot do anything with a deferred
derivation even when read we will remove json support for them as well

Change-Id: I4f9ea0b7c6469f57977784037f7710f939e40a2c
2025-05-20 17:43:46 +00:00
eldritch horrors d03be35c44 libstore: remove DrvHash::Kind
now that we have no deferred hashes (since floating ca derivations were
the only way to create them) we can safely remove this enumeration too.

Change-Id: Ic72ed90500fcee7aa5b3b5a302477fa515acf1be
2025-05-20 17:43:46 +00:00
eldritch horrors e3717b728c libstore: trivialize DerivationType::ContentAddressed
only FODs can be content-addressed now, and those are always fixed.
FODs are also never sandboxed, so we do not need that field either.

Change-Id: I1be62b3ec85e08ec003cc8769723328d19777728
2025-05-20 17:43:46 +00:00
eldritch horrors bfd10db217 libstore: remove DerivationOutput::CAFloating
nothing can create floating ca outputs any more.

Change-Id: Ic69f4a22066e1f5c0837f44e8d4fa2d93ca20ff6
2025-05-20 17:43:46 +00:00
eldritch horrors a7866d56b8 cli: remove ca support from commands
this mostly takes the form of removes feature checks and the associated
"ca derivations enabled" branches, but for the realisation info command
turns into a stub. we keep it around for compatibility, but from now on
it will always throws "ca derivations not implemented" errors when run.

Change-Id: I0abea5f76262013415330adcca2b498c6dca555b
2025-05-20 17:43:46 +00:00
eldritch horrors 6567707dc1 libstore: remove DrvOutputSubstitutionGoal
this goal is only involved for output paths that aren't known at initial
build time, which in turn can only happen if they are ca paths. since we
can no longer create ca derivations during eval *or* read them from disk
we can now assume that we will never run this goal. there are still some
vestiges like output known-ness we can't remove yet, so those must stay.

Change-Id: I989e5ad4600c628bcbe8e17e1b082ce8d73a3bd9
2025-05-20 11:28:12 +00:00
eldritch horrors b60735791e libstore: remove unused drvOutputReferences
ca derivation build was the last remaining user.

Change-Id: Ib0e6d954e7802a53d1328c4c18f5f12dddeb838a
2025-05-20 13:27:04 +02:00
eldritch horrors d4e88b98e9 libstore: remove ca derivation build support
we remove not only support for *building* a ca derivation, but also
support for *resolving* ca derivations as part of a build. we never
have to resolve derivations from here on, so this code is now dead.

Change-Id: I0346442d5fa00eb927177545ae61315f588477cc
2025-05-20 13:27:04 +02:00
eldritch horrors 2cc420c1e5 libstore: remove ca derivation read support
we can now no longer read ca store derivations from disk.

Change-Id: I233edea597b550dd7e8c78a555b7f12760a993dd
2025-05-20 13:27:04 +02:00
eldritch horrors 8d5bc9ed48 libexpr: remove ca derivation eval support
Change-Id: I8c06825d0fa7544b8bc9e3bda948e84a5f21ee16
2025-05-20 13:27:04 +02:00
eldritch horrors dad28eca75 cli: disallow ca derivations
we no longer have any experimental features depending on ca derivations,
so we can start removing them. since ca derivations are very invasive we
will need a while to remove all of the explicitly experimental code, and
even then we will not have removed *all* code related to ca derivations.
especially in the derivation goals there is a lot of code that is not as
easy to disentangle from experimental features as some would have hoped.

Change-Id: Ia456aadc6164613ded343f571318494d9310a549
2025-05-20 13:27:04 +02:00
eldritch horrors 8029cec3c0 libstore: remove some unused code
these must've been left around by accident if past cleanups.

Change-Id: I3458ae45e362e7912a6bbe1f31956c41094144d3
2025-05-16 13:16:27 +02:00
eldritch horrors 3684c2f8a0 libutil: remove dynamic derivations feature
Change-Id: Id48c775197e89bfda711c5cb03752980785c3d26
2025-05-12 13:37:54 +02:00
eldritch horrors ccdd916226 libstore: de-ref {Derived,Built}Path::Built drvPath
they're no longer recursive, so this is perfectly fine.

Change-Id: If565a557f2c2074e2a96a7f89c51ff1c51146b36
2025-05-12 13:37:54 +02:00
eldritch horrors 84c1df46ea libstore: remove DerivedPathMap
single-level maps suffice now that dynamic derivations are gone.

Change-Id: If29998b104b31255292ab0c789622d7d27040f69
2025-05-12 13:37:54 +02:00
eldritch horrors 68dfcfc6a4 treewide: don't resolveDerivedPath opaque paths
resolution of opaque paths is just an expensive `->path`.

Change-Id: I0c8d8b908f358d0bd26d1dcba84b2de6cbdc7c29
2025-05-12 13:37:54 +02:00
eldritch horrors f5e2e78266 libexpr: remove more obsolete DerivedPath methods
split from the prior commit for easier review.

Change-Id: Iabf1bc759cb56a04211d4cb07769f53b0f302b39
2025-05-12 13:37:54 +02:00
eldritch horrors 5f723e96e6 libstore: flatten {,Single}{Built,Derived}Path
only dynamic derivations could produce a non-opaque drvPath. since
dynamic derivations are no longer supported we can have drvPath be
opaque at all times, simplifying downstream code significantly and
making quite a few methods unnecessary. discardOutputPath was only
called on drvPath members anyway and thus reduces to a copy, other
operations at the very least are no longer recursive. some vestige
of dynamic derivations remains in DerivedPathMap though (for now).

Change-Id: Ifb4ad53a3c67800be5a62540068c8279d4ae0046
2025-05-12 13:37:54 +02:00
eldritch horrors 8a539424c8 libexpr: drop support for dyn-drv string context
string context doesn't need any tests because it's never persisted or
shown to the user. getting rid of recursive string context means that
the context string parsers can be a lot simpler from here on forward.

Change-Id: I58443679ad76c0f28ea5f4eb8bfb3874f270e764
2025-05-12 13:37:54 +02:00
eldritch horrors a490e2d946 libstore: remove ability to read or write dyn-drvs
as with impure derivations it is still possible to garbage-collect
existing xp-dyn-drv derivations. we once again don't introduce any
new kinds of errors, we only change the dynamic type of exceptions
from MissingExperimentalFeature to UnimplementedError (although we
do throw FormatError when reading xp-dyn-drv derivations now, that
seems to make a little more sense than "feature not implemented").

Change-Id: Ic26e5b6c9c9e2533093e27f6cf901dc9db57c83e
2025-05-12 13:37:54 +02:00
eldritch horrors 5ae8ac84ea libstore: remove dyn-drvs remote store error hack
with dynamic derivations gone this code will never run again.

Change-Id: I7673a81269c33e62c6c184d33cbc9f3ba0079bee
2025-05-12 13:37:54 +02:00
eldritch horrors 936ac14f1a libexpr: disallow creation of text-hashed derivation outputs
only dynamic derivation produce text-hashed derivation outputs. toFile
produces text-hashed store paths, so we cannot remove text hashing now
without breaking stores, but we can disallow it in derivation outputs.

Change-Id: I95ff9882a59153a7d5fd509f5c9fd85925f30d02
2025-05-12 13:37:54 +02:00
eldritch horrors b8b05d4da4 libexpr: remove dynamic derivation eval support
Change-Id: I8bbdaa280f634bafd5abd7034a605564f45978c0
2025-05-12 13:37:54 +02:00
eldritch horrors 540071dd77 cli: disallow dynamic derivations
with impure derivations gone we move on to dynamic derivations. this too
is not done in a single commit because dynamic derivations are invasive,
modifying semantics of all references to derivation output paths and all
derivation dependency calculations. removing dynamic derivations cleanly
is made significantly harder by the multiple did-you-mean-sum types, aka
"wrappers for std::variant", holding all derivation outpath information.

Change-Id: Ice7a7700c7b54c6a6061d4beb322b4175923d27a
2025-05-12 13:37:54 +02:00
eldritch horrors 18aebab9b6 libstore: remove unused resolveDerivedPath overload
Change-Id: Iaaeb688d601a21c817fb0449faf9541ea8e0301a
2025-05-11 21:16:36 +00:00
eldritch horrors 7bbe6fc47f libstore: remove impure-drvs feature
no documentation seems to have existed for this feature.

Change-Id: I3ec8afd9aeedbff1cc5edabc9074df33dae7d357
2025-05-11 17:27:05 +02:00
eldritch horrors be07629820 libstore: remove DerivationType::Impure
all derivations are now pure again, making isPure a constant function.

Change-Id: I2c65a7b6c8255beb97e2bdd280e4b11e39cb4387
2025-05-11 17:27:05 +02:00
eldritch horrors ae98420772 libstore: drop support for representing impure outputs
nothing can create, or even handle, them any more.

Change-Id: I5ef80129d6b734e65633df6eb9f161ffd31d1327
2025-05-11 17:27:05 +02:00
eldritch horrors 2f9a4a71aa libstore: drop support for reading impure derivations
writing them is technically still supported because what makes a
derivation impure is entirely specified by magically named data,
but without derivationStrict being able to pass these through to
libstore there is no way (besides reading existing files) to get
any new impure derivations into an existing store. it will still
be possible to garbage-collect existing impure derivations since
the gc process does not need to read them as derivations, and we
are not introducing any new kinds of unsupported-feature errors.

Change-Id: I648f53129ce67ee2b48d0591219759812dd557da
2025-05-11 17:27:05 +02:00
eldritch horrors 75f234d84b libexpr: remove impure derivation creation support
Change-Id: I58f481c188c6a6e99d226b4862508cef853b7571
2025-05-11 17:27:05 +02:00
eldritch horrors 6599be1a9f cli: disallow impure derivations
we don't remove the entire feature in one go to make review easier.
impure derivations are rather unintrusive on their own, at least if
we compare them to dynamic or ca derivations in general, so we will
be done with this soon. as it stands impure derivations cannot work
without ca derivations, and those we *really* want to leave behind.

Change-Id: I4f01d8d758b2c85dcd6c3078304b5ee1b52f65b0
2025-05-11 17:26:55 +02:00
eldritch horrors d8e2f53d07 deprecate CA, dynamic, and impure derivations
ca derivations are what we're really after, but dynamic derivations
must also go because they depend on ca derivations. we can't easily
implement dynamic derivations any other way, so we remove them too.
impure derivations build on the content-addressed infrastructure in
ways we cannot easily detangle, so they too must go for time being.

see #815

Change-Id: If61371736dfd89cc71a1b2ae5a005757c3cb9484
2025-05-10 17:15:26 +00:00
eldritch horrors 5917db84aa nix: don't send tarballTtl to the daemon
it's an eval-time only setting, the daemon doesn't use it anywhere. this
is a hack, but until we have a much better settings system we are stuck.

fixes #680

Change-Id: I532088b0279f13da0a0a65c2bd2e5f9d1dfb39da
2025-05-10 12:20:09 +00:00
eldritch horrors 294c55026c libcmd: don't mention debug env values when added
this can be extremely distracting when running in a repl that has access
to all of nixpkgs from its static env. not only do we print all bindings
in the stack trace, we also print them *again* every time we enter *any*
but the outermost frames. duplicating this environment information isn't
all that useful and mostly just flushes useful information out of sight.

fixes #816

Change-Id: I027e6a565e82663275e21333bb1d00d498cd4127
2025-05-09 11:51:39 +00:00
eldritch horrors 8a76db3ab7 libmain: tell kj to use SIGUSR2
fixes #679

Change-Id: Ib7c8afd0192c7329ab3ca90925b1b756b6918c7a
2025-05-08 10:50:10 +00:00
eldritch horrors c88ce60e25 libexpr: remove unnecessary position parameters
all of these are noPos in all call sites.

Change-Id: I2b74942483cd68dab8cc7c30f582a45a69598c4a
2025-05-02 10:57:15 +00:00
eldritch horrors 2059ccaad3 libexpr: remove positions from primops
they're always noPos and have caused quite some confusion.

fixes #781

Change-Id: I15d4210b1aab6ef5d1caabe2e10b45cf98cc4d47
2025-05-02 10:57:15 +00:00
eldritch horrors 6bd6a2416b libexpr: turn debug frames into exprs
this way we don't have to even check whether we need a debug frame when
the debugger isn't enabled. not doing this gives us an eval performance
improvement of roughly 7% on nixos system eval and 2% for `nix search`.

Change-Id: I1cdad3de61f865ea54d6e09d63a281688e828768
2025-05-01 14:28:05 +00:00
eldritch horrors dd2c54d9ad libexpr: generate debug info from a new visitor
Change-Id: I757a9e49dee99b27b0f153ca520c71ee3ecd347f
2025-05-01 14:28:05 +00:00
eldritch horrors 8145c2f5fe libexpr: implement bindVars with a visitor
we can now move debug info generation out of bindVars itself.

Change-Id: I54c88e14d030d2a19f16b57099990f2c3b4334aa
2025-05-01 14:28:05 +00:00
eldritch horrors a91efd63aa libexpr: add an expression visitor
we'll use this to implement bindVars better.

Change-Id: I620d9d1972acdeeee6e345c3128813e53d2074c6
2025-05-01 14:28:05 +00:00
eldritch horrors 8b619b134d libexpr: store inherit source exprs in a list, not vec
it's a surprise tool that will help us later!

Change-Id: Ieac785b00b3d14e5937c03fb2c97c918f4646e56
2025-05-01 14:28:05 +00:00
eldritch horrors 558d921dac libexpr: don't dynamic_cast Exprs after parsing is done
we'll want to wrap some exprs for debug purposes, and dynamic casts
cannot look through such wrappers. dedicated casting functions can.

Change-Id: I1fba0ec52d281a1b8de85a62e4948bfae536bcfc
2025-05-01 14:28:05 +00:00
eldritch horrors 2b4ef8dc11 libexpr: deduplicate set and let recursive env calculation
Change-Id: Ia7f066e1c02f99f071d10e00020869fac9a13db7
2025-05-01 14:28:05 +00:00
eldritch horrors 811542bb5f libexpr: remove COMMON_METHODS macro
it just pollutes the namespace.

Change-Id: Ib191f139916a03e5a56a07638cc5da6c80a87043
2025-05-01 14:28:05 +00:00
eldritch horrors 275b95c873 libexpr: make ExprInheritFrom not be an ExprVar
this was only a convenient fiction when it was introduced, but it is no longer.

Change-Id: I72c50e7774c75408c1a40aee7da22059474ba01d
2025-05-01 14:28:05 +00:00
eldritch horrors dad17a54f7 libexpr: remove Value::determinePos
it was mostly useless, and now it's entirely unused.

Change-Id: I015c83779a7f860e325796684639f05083a50676
2025-04-27 17:38:57 +00:00
eldritch horrors c068aeaf61 treewide: don't determinePos in autoCallFunction
add a position parameter to the autocaller instead, and pass it much
more accurate position information where we have it easily available

Change-Id: If2f1c3006ca3f2b413492842905d079a8b752542
2025-04-27 17:38:57 +00:00
eldritch horrors db738ddb14 libexpr: don't determinePos in derivationStrictInternal
errors for individual attrs should report the position of the attribute,
not the position of the set they were taken from (which we'll assume was
the intent here). this is already the case for most attributes, only the
the extra-special __structuredAttrs and __ignoreNulls weren't annotated.

this includes not calling atPos(v) on errors builders since the position
of v is always invalid. error messages are unchanged by this part of the
patch (and the caller adds a trace pointing to the derivation name too).

Change-Id: Ia3540f9ce1f2505275e49dd4e4336b2a59d5b336
2025-04-27 17:38:57 +00:00
eldritch horrors abc26ca0d2 libexpr: don't determinePos in ExprBlackHole::eval
`v` is invalid, its position (if it exists at all) will be stale.

Change-Id: I79147c92fe6b2b077a9aa4783231b7aac05ef9d2
2025-04-27 17:38:57 +00:00
eldritch horrors 859c8caae2 libcmd: don't determinePos in repl
replInitFilesFunction is always valid, but pointing to it is misleading
because the source is inaccessible. every replInit is better identified
by its path if it isn't a lambda; determinePos will return noPos anyway

Change-Id: I0b6fcd2f95f121a802c87cb1085d3a0b1c585aeb
2025-04-27 17:38:57 +00:00
eldritch horrors ff776f5091 libexpr: don't determinePos for primop calls
it's pointless, they don't have position information.

Change-Id: I21f49e4d26f9ed7bc3772157882c84447f8e6387
2025-04-27 17:38:57 +00:00
eldritch horrors bdebc3797b cmd/libexpr: don't determinePos in value-to-json
it's not useful. nix-instantiate will always point to the wrong location
because "at the toplevel" is not a position we can point to. all nesting
conversions will point to strange places: the *original* definition of a
lambda value (or partial applications thereof), or nowhere at all (since
only lambda values can have their positions determined in the formatter)

Change-Id: I56bd9e1cf3cae11b4198f148a141ca758e4fe8ac
2025-04-27 17:38:57 +00:00
eldritch horrors eb0280f715 libexpr: add set-to-string error frame
this is much more useful than a frame pointing to the set but claiming
it as a function being called. if the function is actually at fault we
will now point to its attribute, although the position may be slightly
wrong if __toString was defined from set updates or builtin functions.

Change-Id: Ib3eb237a276d94426d9c6fc0e26eea72382d34a2
2025-04-27 11:01:22 +00:00
eldritch horrors 9d761ed5c1 nix: don't determinePos in flake check
by the time enumerateOutputs is called we've already established that
vFlake will evaluate to an attrset (as a locked flake it can't be any
other kind of value). the outputs attribute is likewise already a set
because the nix code that builds it says so. adding positions here is
merely an unnecessary debugging aid for developers working on flakes.

Change-Id: I2a10ddf1400f7650c6e303433f9fee8813f0188d
2025-04-26 22:14:05 +02:00
eldritch horrors 8a1b86631c treewide: don't determinePos for forcing
only attrsets, lambdas, and app nodes can have positions determined, and
none of these three types are incomplete. calling determinePos before we
force a value is thus only a convoluted copy operation for its argument.

Change-Id: I7e647aacca1fc8250f7bb11bb0071a4f7186047f
2025-04-26 22:14:05 +02:00
eldritch horrors feebecd60b treewide: wrap std::regex_error
otherwise lix may crash when e.g. nix search receives invalid regex.
we now also give better error messages for regex errors during eval.

fixes #803

Change-Id: Icc7c578ff488ba520efac5d898572ccf4486e9a8
2025-04-24 13:48:15 +00:00
eldritch horrors 9bb24a5cdb libstore: SSHMaster master -> SSH ssh
we no longer explicitly configure these ssh options, so we now
have *even less* reason to stick to old and awful terminology.

Change-Id: I8f38f5486e6918f69c61ddc2d6882b6bb50554c6
2025-04-21 13:43:44 +00:00
eldritch horrors f92235e1d2 libstore: stop using ssh connection sharing
our implementation is mostly unused, completely untested, and simply
breaks when users configure connection sharing independently. we can
safely delete this "feature" and inherit user configuration instead.

also have the remote build test check that connection sharing works.

fixes #304, fixes #644

Change-Id: Iea44cc0f8e51a1d231ad186a95c7e310bbfeb303
2025-04-21 13:43:44 +00:00
eldritch horrorsandLix Systems Gerrit 350bf7e42d Revert "libstore: don't use curl decompression support"
This reverts commit bba678e5c5.

Reason for revert: didn't fix the bug and created new ones (fj#794)

Change-Id: I0450205d3041b6c876737151a4051081c1366f1d
2025-04-09 11:28:50 +00:00
eldritch horrors 2ef4b69760 libutil: disallow implicit ref creations
448c7d50e1 was a bit over-eager and didn't
make the `ref(enable_shared_from_this &)` constructor explicit. this has
confused hydra maintainers, and is just generally bad practice since any
reference is allowed to implicitly convert, even if those references are
not associated with an active control block. we can't avoid this problem
entirely, but we can make what happens more explicit by ... well, making
the involved constructor explicit. enable_shared_from_this is statically
unsafe in principle and we really have to get rid of this nonsense soon.

Change-Id: I8b48ef4353e6301b61af3569083f42bc7379b0a4
2025-04-06 20:29:25 +02:00
eldritch horrors b4c6bfd72a libutil: trace unwinding through async tasks
this gives us a semblance of a stack trace if async tasks fail, like:

    Async task trace (probably incomplete):
    #0: virtual kj::Promise<Result<Goal::WorkResult>> nix::LocalDerivationGoal::tryLocalBuild() (lix/libstore/build/local-derivation-goal.cc:257:33)
    	building of '//0ppb5aj4p3vp0icnkq4yibajw1czvdja-bash52-009.drv^out' from .drv file
    #1: kj::Promise<Result<Goal::WorkResult>> nix::DerivationGoal::outputsSubstitutionTried() (lix/libstore/build/derivation-goal.cc:381:47)
    	building of '//0ppb5aj4p3vp0icnkq4yibajw1czvdja-bash52-009.drv^out' from .drv file
    #2: kj::Promise<Result<Goal::WorkResult>> nix::DerivationGoal::loadDerivation() (lix/libstore/build/derivation-goal.cc:213:41)
    	building of '//0ppb5aj4p3vp0icnkq4yibajw1czvdja-bash52-009.drv^out' from .drv file
    #3: kj::Promise<Result<Goal::WorkResult>> nix::DerivationGoal::gaveUpOnSubstitution() (lix/libstore/build/derivation-goal.cc:453:62)
    	building of '//f8rkb1vam9y9vi9scsm1v213b01rm72h-bash-5.2p37.drv^out' from .drv file
    #4: kj::Promise<Result<Goal::WorkResult>> nix::DerivationGoal::outputsSubstitutionTried() (lix/libstore/build/derivation-goal.cc:381:47)
    	building of '//f8rkb1vam9y9vi9scsm1v213b01rm72h-bash-5.2p37.drv^out' from .drv file
    #5: kj::Promise<Result<Goal::WorkResult>> nix::DerivationGoal::loadDerivation() (lix/libstore/build/derivation-goal.cc:213:41)
    	building of '//f8rkb1vam9y9vi9scsm1v213b01rm72h-bash-5.2p37.drv^out' from .drv file
    #6: kj::Promise<Result<Goal::WorkResult>> nix::DerivationGoal::gaveUpOnSubstitution() (lix/libstore/build/derivation-goal.cc:453:62)
    	building of '//qa9jvc4j6fphzwr63k5c829b2hr04q6z-foo.drv^*' from .drv file
    #7: kj::Promise<Result<Goal::WorkResult>> nix::DerivationGoal::outputsSubstitutionTried() (lix/libstore/build/derivation-goal.cc:381:47)
    	building of '//qa9jvc4j6fphzwr63k5c829b2hr04q6z-foo.drv^*' from .drv file
    #8: kj::Promise<Result<Goal::WorkResult>> nix::DerivationGoal::loadDerivation() (lix/libstore/build/derivation-goal.cc:213:41)
    	building of '//qa9jvc4j6fphzwr63k5c829b2hr04q6z-foo.drv^*' from .drv file
    #9: virtual kj::Promise<Result<void>> nix::Store::buildPaths(const std::vector<DerivedPath> &, BuildMode, std::shared_ptr<Store>) (lix/libstore/build/entry-points.cc:20:11)

it's not much, but it's a lot better than nothing. sadly we're forced
to disable another clang-tidy warning now, but since that one's about
assert side effects being compiled out in release mode and we've long
since decided to just not do that we are not affected by this at all.

also see #724 for a related but different approach to origin tracing.

Change-Id: I8161f82ca39d0b271316ea4df80513acc1b06a03
2025-04-06 12:14:51 +02:00
eldritch horrors 8d8bb60796 treewide: lint against non-lix exceptions
we generally do not want to catch or throw these. catching them to print
and discard is fine, tests are largely exempt, and cases in which we can
be certain where the exception came from are also fine to *catch*. we'll
try to never *throw* (or rethrow) these if possible though because doing
so will make it impossible to construct async traces for the exceptions.

Change-Id: I3b71c32ecd16afc2246c946472f5629a1fa31f2c
2025-04-06 12:14:38 +02:00
eldritch horrors 63d550938b treewide: derive all lix exceptions from BaseError
even the non-errors. we should probably insert a BaseException here.

Change-Id: I1b1af8ba0bf49251fe9d1a24c6559db3ef4a59d2
2025-04-06 11:52:32 +02:00
eldritch horrors 8506a2aa00 libutil: add ForeignException
this wraps a non-lix exception so we'll be able to add async traces. to
not interfere with existing infrastructure we also add a BaseException,
deriving from BaseError would have foreign exceptions match on the very
broad catches we have in libmain even though we want these logged only.

Change-Id: I5545788c299e9bbdb4d730458914bfd816870794
2025-04-06 11:52:30 +02:00
eldritch horrors 949a561540 libutil: explicitly mark ref(shared_ptr) as unsafe
we'll also assert instead of throwing an exception because that just
seems more useful. this should never *ever* happen, and it is on the
callers of such conversions to ensure that the conversion *is* safe.

Change-Id: Ib0696af4f037046f2d45bf5b1b255393ea9b5f05
2025-04-05 21:57:45 +02:00
eldritch horrors dd8dbb56fc libutil: make ref casts safer
don't throw if a downcast fails, have that particular casting method
return an optional instead and check the result at the call site. we
also rename dynamic_pointer_cast to try_cast_shared for consistency.

Change-Id: I65ee0fb498b1b2b8b418935fce4358a654f984e5
2025-04-05 21:57:45 +02:00
eldritch horrors 448c7d50e1 libutil: add shared_from_this support to ref
we don't need to unsafely cast a shared_from_this pointer to create a
ref (the pointer must be non-null to not invoke nasal demons anyway).

Change-Id: I133fe5f07b2cff8ec2c925f0528f4c5288827261
2025-04-05 21:57:45 +02:00
eldritch horrors aa358eac91 libutil: remove unused ref constructor
this one is dangerous anyway.

Change-Id: Id4fb777fff516cdb6a6e8e0b2fd7611418ae2e49
2025-04-05 21:57:45 +02:00
eldritch horrors c4b8b92904 treewide: store optional refs as exactly this
don't store them as shared_ptrs and cast them back to ref when needed.
we have sufficiently few instances of this pattern that we can spare a
few bytes to make the code less implicitly unsafe (and a bit clearer).

Change-Id: Ied573ab2e116ae228730390ff4c6b0469c59ff6a
2025-04-05 21:57:45 +02:00
eldritch horrors 14db530ac0 libexpr: restrict EvalErrorBuilder to building EvalErrors
Change-Id: Iadd0fee4c12c5d0b6ee74dccbf8785c829d20d95
2025-04-05 21:57:45 +02:00
eldritch horrors 15a85a936b libexpr: fix :edit crashing on huge line numbers
this affects both :edit in the repl and the `nix edit` command. given a
huge line number they'd previously crash with a stack trace because the
conversion to int would throw out_of_range instead of invalid_argument.

Change-Id: I4ea1a6e65a83373d54aae72839a9b017df076006
2025-04-05 21:57:45 +02:00
eldritch horrors b918f1c307 tidy: add a lint to forbid nlohmann::json::parse
Change-Id: I165c7330d7ea7f17522ade8a0666d0d7d86b9d38
2025-03-27 08:56:14 +00:00
eldritch horrors 0d47773d76 treewide: handle JSON parse errors
or more accurately, wrap them in a nix::Error subclass so we can display
them properly without crashing, and add some error context if available.

fixes #642
fixes #753
fixes #759
fixes #769

Change-Id: I1aad0c0501fea83f9de3a1335eaa6adc20721616
2025-03-27 08:56:14 +00:00
eldritch horrors fc58e7b217 libexpr: mark eval error handling NeverAsync
technically it doesn't *have* to be NeverAsync, but not marking it as
such unconditionally requires templating DebugState over asyncness of
its callback (which then requires templating EvalState, which, *NO*.)

Change-Id: I4980d45b541c2e40328beac139b18c6c1ba0957c
2025-03-25 21:26:47 +01:00
eldritch horrors 8a90195cdb libexpr: don't debugThrow from async code
running a debugger is never-async since it holds an EvalState reference.

fixes #761

Change-Id: Ie1b4df6f81bb5614f11ea183eb9d1058fde73121
2025-03-25 21:23:05 +01:00
eldritch horrors d2f4b4042d libexpr: move realiseContext back to EvalState
throwing debuggable errors is effectively never-async, and realising a
context requires acquiring a context first, i.e. evaluating something.
since realiseContext is only used by primops the effect is very minor.

Change-Id: I73b3b277188700e5cdf6f30599fb6674ec1ab753
2025-03-25 20:14:45 +01:00
eldritch horrors 0ff8c2b06f libexpr: make undefined var errors non-debuggable in the parser
this only affects undefined names outside of with scopes. sending those
errors to the debugger when enabled seems rather less useful; unlike in
the case of with scopes there's nothing meaningful to inspect. avoiding
the debugger also lets us avoid marking the entire parser `NeverAsync`.

cf #761

Change-Id: I3599b826ff5b101acf9a3ba70dcdf9e8e02067f0
2025-03-25 20:14:45 +01:00
eldritch horrors 6bf8c8a4f2 nix-eval-jobs: fix a clang-tidy lint
we don't run clang-tidy on nej in ci, but it's annoying locally.

Change-Id: I6f0ae3220425ac9e9f20adaf492873f8b27a630f
2025-03-25 20:14:45 +01:00
eldritch horrors c3929c78f3 libutil: disallow enum serialization by default
allow opting in to serialization as integers via a trait type instead,
and add string-list serializers for the feature flag set enumerations.

fixes #738

Change-Id: I2746eb5ef1f15c01b4e681f9ba1615b6c6e64f44
2025-03-25 10:44:52 +01:00
eldritch horrors e5b9c86e59 libutil: remove *-json.hh headers
we can inline them into their parents now.

fixes #598

Change-Id: I7bc9371885cc0adde11da1e2c67bf0a4cf833a98
2025-03-25 10:44:50 +01:00
eldritch horrors 56df5ba164 libutil: remove json-utils.hh
we can merge it into json.hh instead.

Change-Id: Ic40c25fa759bf52bb69eae5d7c0597f260fd94a6
2025-03-23 22:29:58 +00:00
eldritch horrors dd7cb01708 libutil: remove json-impls.hh
we can do this much better now that we own the serializers.

Change-Id: I531ed44a7b6feac42ffd76719002b78488317d1a
2025-03-23 22:29:58 +00:00
eldritch horrors 45017f7508 libutil: specialize nix::JSON
we want to own this specialization fully so we can change the default
serializer behavior without also forcing downstream users of our code
to use the same behavior. it'll also let us do things we cannot do in
regular nlohmann::json, such as selectively enabling serialization of
enums as integral types, or using `to_json`/`from_json` overloads for
not-default-constructible types instead of serializer specializations

Change-Id: I91a1db362e37d654090f1824b1cd3ce783d32134
2025-03-23 22:16:30 +00:00
eldritch horrors f7d1a6ba8b libutil: extend json_avoids_null to floats and enums
Change-Id: Ief80c03ca244fa4d3fd9dc1792f49b8b2802839e
2025-03-23 20:42:39 +00:00
eldritch horrors 19d7c8352e treewide: add nix::JSON
this will become a proper specialization of `nlohmann::basic_json` soon.
specialing basic_json will let us get rid of our `adl_serializer` hacks,
and it'll open the door to better enum serializing behavior without also
forcing all those who use lix as a library to set certain defines (which
may not even be possible depending on how those users use json already).

Change-Id: I5228d2b9df581a189552c993363207cfbd20f445
2025-03-23 20:42:39 +00:00
eldritch horrors a186bc5021 treewide: add json forwarder headers
this doesn't do much, just wrap a few nlohmann headers in headers of our
own (and delete includes we don't need because they're transitively seen
by other includes). doing this now will make the next change much nicer.

Change-Id: I166933102ea86bb5322ebbf9ba9411f96032a53b
2025-03-23 20:42:39 +00:00
eldritch horrors 09769bbf41 treewide: remove unused nlohmann includes
Change-Id: I261e4bd4c859eb3924202e690331c05887aa26b0
2025-03-23 20:42:39 +00:00
eldritch horrors 27d5209f4d libutil: fix copyNAR not reading the whole nar when dropped early
if a copyNAR generator was not drained to completion it would not read
the full nar data from its source. this could happen if the copier was
passed to parseAndDump wrapped as a source because copyNAR would yield
nar metadata *before* it had read it, and GeneratorSource will drain a
generator fully *only* if the source is allowed to throw EndOfFile. in
the parseAndDump case this never happened because parseAndDump expects
to be given an unterminated stream, and thus the combination left some
nar metadata in the input Source, breaking the remote store protocols.

fixes #732

Change-Id: Ia59a53375992bfcdb7bc6b37764ca779622bc8f7
2025-03-18 19:32:58 +00:00
eldritch horrors 3ed99ad26e n-e-j: use full lix warning config
this would've caught the missing aio await. also disable some rather
annoying deprecation and missing initializer warnings in dev builds.

Change-Id: Ibbb9dfc67eada0e7843081b669b7c8726a02ec29
2025-03-18 09:13:11 +00:00
eldritch horrors 274933c729 n-e-j: add missing aio block on Store::queryMissing
Change-Id: I7c2350d2bf0d729d26f67a2b2181b2ebc7efb4f8
2025-03-18 09:13:11 +00:00
eldritch horrors 6aff96d9cd fix uint64_t-to-size_t narrowing for 32bit systems
fixes #733

Change-Id: Ib0f4d90e32c81f0bd1b7ccacb576b867bfa59690
2025-03-17 23:11:58 +01:00
eldritch horrors cbf7929277 libstore: use thread pools for remote stderr handling
spawning threads is not free. reusing threads is also not free, but a
lot cheaper than spawning now ones. the difference can add up quite a
bit on nixos system evaluation; we've seen 20k threads cycled through
on even modestly sized configurations, and at 20µs per thread just to
launch and tear down (excluding any work done) that's potentially not
insignificant. in our test config this was a 3% eval time difference.

Change-Id: I40f901813e700fb99f5def82da54ca969711961b
2025-03-14 09:39:09 +00:00
eldritch horrors a60a362d8a libstore: correctly move remote connection exception info
Change-Id: I264dab54502c178a362593b3c757110588e0548a
2025-03-11 16:15:20 +00:00
eldritch horrors ba9ab0c855 libutil: add in-place construction to Sync
only then can we Sync<> non-movable types.

Change-Id: I7835cdaf9fd2b90c842c9e054942524f36515d5a
2025-03-11 16:15:20 +00:00
eldritch horrors f21fd6b7e6 libstore: fix substitution failures on racy builds
if two derivations have different outputs of the same other derivation
as inputs there's a race window in which wanted output tracking broke:

 - start building depender-a
 - schedule dependency^a for depender-a
 - substitute dependency^a
 - dependency runs path validity checks, yields
 - start building depender-b
   - depender-b adds b to the wanted set of dependency
 - dependency resumes from validity checks with allValid
 - depender-b is unblocked, but dependency^b is not in the store

Change-Id: Id4dba517bbbdbae96bf430d2c68f63eccd3b99dd
2025-03-10 21:18:22 +00:00
eldritch horrors bba678e5c5 libstore: don't use curl decompression support
it's broken with http2 and transfer flow control. cf fj#662

Change-Id: Iaf6312bfcefa18d168faef47f57481199dd30b8d
2025-03-08 20:58:34 +01:00
eldritch horrors 93c3ca4e92 libutil: fix async copyNAR failing on slow io
well, oops. on slow io (as can happen with ssh remote builders) we could
have extended a nar read buffer past what was actually read, injecting a
span of zeroes into the read buffer where we requested some data but got
a partial result instead. also add some tests that would've caught this.

Change-Id: I67aa06b4715aeec6a5bdacaafa9b79849e664e2f
2025-03-07 15:45:51 +01:00