aboutsummaryrefslogtreecommitdiff
path: root/src/libutil
AgeCommit message (Collapse)Author
2023-08-19Merge pull request #8812 from tweag/fix-clang-tidyRobert Hensing
Fix some warnings/bugs found by clang-tidy
2023-08-18Merge pull request #8839 from obsidiansystems/string-context-7479John Ericson
Refactor Raw pattern, part of #7479
2023-08-18Fixing #7479John Ericson
Types converted: - `NixStringContextElem` - `OutputsSpec` - `ExtendedOutputsSpec` - `DerivationOutput` - `DerivationType` Existing ones mostly conforming the pattern cleaned up: - `ContentAddressMethod` - `ContentAddressWithReferences` The `DerivationGoal::derivationType` field had a bogus initialization, now caught, so I made it `std::optional`. I think #8829 can make it non-optional again because it will ensure we always have the derivation when we construct a `DerivationGoal`. See that issue (#7479) for details on the general goal. `git grep 'Raw::Raw'` indicates the two types I didn't yet convert `DerivedPath` and `BuiltPath` (and their `Single` variants) . This is because @roberth and I (can't find issue right now...) plan on reworking them somewhat, so I didn't want to churn them more just yet. Co-authored-by: Eelco Dolstra <edolstra@gmail.com>
2023-08-17libutil: fix double-encoding of URLsCole Helbling
If you have a URL that needs to be percent-encoded, such as `http://localhost:8181/test/+3d.tar.gz`, and try to lock that in a Nix flake such as the following: { inputs.test = { url = "http://localhost:8181/test/+3d.tar.gz"; flake = false; }; outputs = { test, ... }: { t = builtins.readFile test; }; } running `nix flake metadata` shows that the input URL has been incorrectly double-encoded (despite the flake.lock being correctly encoded only once): [...snip...] Inputs: └───test: http://localhost:8181/test/%252B3d.tar.gz?narHash=sha256-EFUdrtf6Rn0LWIJufrmg8q99aT3jGfLvd1//zaJEufY%3D (Notice the `%252B`? That's just `%2B` but percent-encoded again) With this patch, the double-encoding is gone; running `nix flake metadata` will show the proper URL: [...snip...] Inputs: └───test: http://localhost:8181/test/%2B3d.tar.gz?narHash=sha256-EFUdrtf6Rn0LWIJufrmg8q99aT3jGfLvd1//zaJEufY%3D --- As far as I can tell, this happens because Nix already percent-encodes the URL and stores this as the value of `inputs.asdf.url`. However, when Nix later tries to read this out of the eval state as a string (via `getStrAttr`), it has to run it through `parseURL` again to get the `ParsedURL` structure. Now, this itself isn't a problem -- the true problem arises when using `ParsedURL::to_string` later, which then _re-escapes the path_. It is at this point that what would have been `%2B` (`+`) becomes `%252B` (`%2B`).
2023-08-11SimpleLogger::log: fix unintended fallthroughYorick van Pelt
2023-08-11MultiCommand::toJSON: Fix use-after-moveYorick van Pelt
2023-08-10Make the Derived Path family of types inductive for dynamic derivationsJohn Ericson
We want to be able to write down `foo.drv^bar.drv^baz`: `foo.drv^bar.drv` is the dynamic derivation (since it is itself a derivation output, `bar.drv` from `foo.drv`). To that end, we create `Single{Derivation,BuiltPath}` types, that are very similar except instead of having multiple outputs (in a set or map), they have a single one. This is for everything to the left of the rightmost `^`. `NixStringContextElem` has an analogous change, and now can reuse `SingleDerivedPath` at the top level. In fact, if we ever get rid of `DrvDeep`, `NixStringContextElem` could be replaced with `SingleDerivedPath` entirely! Important note: some JSON formats have changed. We already can *produce* dynamic derivations, but we can't refer to them directly. Today, we can merely express building or example at the top imperatively over time by building `foo.drv^bar.drv`, and then with a second nix invocation doing `<result-from-first>^baz`, but this is not declarative. The ethos of Nix of being able to write down the full plan everything you want to do, and then execute than plan with a single command, and for that we need the new inductive form of these types. Co-authored-by: Robert Hensing <roberth@users.noreply.github.com> Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-08-07Stabilize `discard-references`Théophane Hufschmitt
It has been there for a few releases now (landed in 2.14.0), doesn't seem to cause any major issue and is wanted in a few places (https://github.com/NixOS/nix/pull/7087#issuecomment-1544471346).
2023-08-05Fix derivation load assertion errorsFelix Uhl
When loading a derivation from a JSON, malformed input would trigger cryptic "assertion failed" errors. Simply replacing calls to `operator []` with calls to `.at()` was not enough, as this would cause json.execptions to be printed verbatim. Display nice error messages instead and give some indication where the error happened. *Before:* ``` $ echo 4 | nix derivation add error: [json.exception.type_error.305] cannot use operator[] with a string argument with number $ nix derivation show nixpkgs#hello | nix derivation add Assertion failed: (it != m_value.object->end()), function operator[], file /nix/store/8h9pxgq1776ns6qi5arx08ifgnhmgl22-nlohmann_json-3.11.2/include/nlohmann/json.hpp, line 2135. $ nix derivation show nixpkgs#hello | jq '.[] | .name = 5' | nix derivation add error: [json.exception.type_error.302] type must be string, but is object $ nix derivation show nixpkgs#hello | jq '.[] | .outputs = { out: "/nix/store/8j3f8j-hello" }' | nix derivation add error: [json.exception.type_error.302] type must be object, but is string ``` *After:* ``` $ echo 4 | nix derivation add error: Expected JSON of derivation to be of type 'object', but it is of type 'number' $ nix derivation show nixpkgs#hello | nix derivation add error: Expected JSON object to contain key 'name' but it doesn't $ nix derivation show nixpkgs#hello | jq '.[] | .name = 5' | nix derivation add error: Expected JSON value to be of type 'string' but it is of type 'number' $ nix derivation show nixpkgs#hello | jq '.[] | .outputs = { out: "/nix/store/8j3f8j-hello" }' | nix derivation add error: … while reading key 'outputs' error: Expected JSON value to be of type 'object' but it is of type 'string' ```
2023-06-21Merge pull request #8374 from obsidiansystems/improve-path-settingJohn Ericson
Split `OptionalPathSetting` from `PathSetting`
2023-06-20Support opening local store with database on read-only filesystem (#8356)Ben Radford
Previously it was not possible to open a local store when its database is on a read-only filesystem. Obviously a store on a read-only filesystem cannot be modified, but it would still be useful to be able to query it. This change adds a new read-only setting to LocalStore. When set to true, Nix will skip operations that fail when the database is on a read-only filesystem (acquiring big-lock, schema migration, etc), and the store database will be opened in immutable mode. Co-authored-by: Ben Radford <benradf@users.noreply.github.com> Co-authored-by: cidkidnix <cidkidnix@protonmail.com> Co-authored-by: Dylan Green <67574902+cidkidnix@users.noreply.github.com> Co-authored-by: John Ericson <git@JohnEricson.me> Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-06-19Split out worker protocol template definitions from declarationsJohn Ericson
This is generally a fine practice: Putting implementations in headers makes them harder to read and slows compilation. Unfortunately it is necessary for templates, but we can ameliorate that by putting them in a separate header. Only files which need to instantiate those templates will need to include the header with the implementation; the rest can just include the declaration. This is now documenting in the contributing guide. Also, it just happens that these polymorphic serializers are the protocol agnostic ones. (Worker and serve protocol have the same logic for these container types.) This means by doing this general template cleanup, we are also getting a head start on better indicating which code is protocol-specific and which code is shared between protocols.
2023-06-19Merge pull request #8483 from edolstra/save-rootEelco Dolstra
restoreMountNamespace(): Restore the original root directory
2023-06-18Split `OptionalPathSetting` from `PathSetting`John Ericson
Rather than doing `allowEmpty` as boolean, have separate types and use `std::optional`. This makes it harder to forget the possibility of an empty path. The `build-hook` setting was categorized as a `PathSetting`, but actually it was split into arguments. No good! Now, it is `Setting<Strings>` which actually reflects what it means and how it is used. Because of the subtyping, we now also have support for `Setting<std::optional<String>>` in general. I imagine this can be used to clean up many more settings also.
2023-06-18Create nlohmann serializers for `std::optional` and useJohn Ericson
This is somewhat tricky.
2023-06-15Don't assume the type of string::size_typeThéophane Hufschmitt
The code accidentally conflated `std::string::size_type` and `long unsigned int`. This was fine on 64bits machines where they are apparently the same in practice, but not on 32bits. Fix that by using `std::string::size_type` everywhere.
2023-06-14Remove dead code (#8504)Daniel Asaturov
`filesystem.cc` is the only place where `createSymlink()` is used with three arguments: in the definition of `replaceSymlink()` with three parameters that _is not used at all_. Closes #8495
2023-06-14Merge pull request #4282 from tweag/fix-ca-hash-rewritingJohn Ericson
fix the hash rewriting for ca-derivations
2023-06-09restoreMountNamespace(): Restore the original root directoryEelco Dolstra
This is necessary when we're in a chroot environment, where the process root is not the same as the root of the mount namespace (e.g. in nixos-enter). Fixes #7602.
2023-06-09Parse TOML timestamps (#8120)Andrea Bedini
Currently `fromTOML` throws an exception when encountering a timestamp since the Nix language lacks a way to represent them. This patch changes this beaviour and makes `fromTOML` parse timestamps as attrsets of the format { _type = "timestamp"; value = "1979-05-27T07:32:00Z"; } This is guarded by an experimental feature flag to leave room for iterating on the representation.
2023-05-31Merge pull request #8318 from fricklerhandwerk/doc-currentTimeValentin Gagarin
document `builtins.currentTime`
2023-05-26create pathAccessible, use it to infer default dirsYorick van Pelt
2023-05-26ci: Always run with sandbox, even on DarwinSilvan Mosberger
And fix a test failure in the sandbox due to /home existing on Darwin but not being accessible in the sandbox since it's a symlink to /System/Volumes/Data/home, see https://github.com/NixOS/nix/actions/runs/4205378453/jobs/7297384658#step:6:2127: C++ exception with description "error: getting status of /home/schnitzel/darmstadt/pommes: Operation not permitted" thrown in the test body. On Linux this wasn't a problem because there /home doesn't exist in the sandbox
2023-05-24Make `RewritingSink` accept a map of rewritesThéophane Hufschmitt
Giving it the same semantics as `rewriteStrings`. Also add some tests for it
2023-05-19Merge pull request #8354 from KasyanDiGris/git-fetcher-ask-credentialsEelco Dolstra
Ask for git credentials in fetcher
2023-05-18Add option isInteractiveKonstantin Vukolov
2023-05-17Upgrade `downstreamPlaceholder` to a type with methodsJohn Ericson
This gets us ready for dynamic derivation dependencies (part of RFC 92).
2023-05-17add cross-references to pure evaluation modeValentin Gagarin
use consistent wording everywhere. add some details on the configuration option documentation.
2023-05-15Delete commited build artifactsJohn Ericson
They were improperly added in 8a93b5a55184d9d34effdd94d58429c9ad1a3d14. They were not `.gitignore`d because they were stale in that commit -- build artifacts no longer used that name by then and so `.gitignore` was updated accordingly.
2023-05-15Merge pull request #8141 from tweag/user-files-docJohn Ericson
Document user files of nix
2023-05-10Merge pull request #3959 from obsidiansystems/ca-drv-exoticJohn Ericson
Derivations can output "text-hashed" data
2023-04-26Document user files of nixAlexander Bantyev
2023-04-25TarArchive: Remove a duplicate constant and increase the buffer sizeEelco Dolstra
2023-04-24Merge remote-tracking branch 'origin/master' into source-pathEelco Dolstra
2023-04-17`TextHashMethod` -> `TextIngestionMethod`, gate with XP featureJohn Ericson
I suppose we can use `dynamic-derivations` for the few things we neeed.
2023-04-17Merge pull request #8230 from obsidiansystems/daemon-trust-overrideRobert Hensing
Experimentally allow forcing `nix-daemon` trust; use this to test
2023-04-17Experimentally allow forcing `nix-daemon` trust; use this to testJohn Ericson
We finally test the status quo of remote build trust in a number of ways. We create a new experimental feature on `nix-daemon` to do so. PR #3921, which improves the situation with trustless remote building, will build upon these changes. This code / tests was pull out of there to make this, so everything is easier to review, and in particular we test before and after so the new behavior in that PR is readily apparent from the testsuite diff alone.
2023-04-17Fix some issues with experimental config settingsJohn Ericson
Issues: 1. Features gated on disabled experimental settings should warn and be ignored, not silently succeed. 2. Experimental settings in the same config "batch" (file or env var) as the enabling of the experimental feature should work. 3. For (2), the order should not matter. These are analogous to the issues @roberth caught with my changes for arg handling, but they are instead for config handling. Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2023-04-17Merge pull request #7732 from hercules-ci/make-initLibStore-viable-alternativeJohn Ericson
Make `initLibStore` a viable alternative
2023-04-17Merge remote-tracking branch 'upstream/master' into source-pathRobert Hensing
2023-04-16Mark experimental configuration settings programmaticallyJohn Ericson
Fix #8162 The test is changed to compare `nlohmann::json` values, not strings of dumped JSON, which allows us to format things more nicely.
2023-04-14Merge pull request #8176 from tweag/rename-confusing-write-methodEelco Dolstra
Rename and protect `BufferedSink::write`
2023-04-11Do not gate or hide experimental settingsJohn Ericson
This is somewhat hacky fix just for 2.15. I unintentionally hid them from the manual, when no one wanted to hide them that (including myself). I also required the experimental feature to be enabled in an order-dependent way, which is not good. The simplest fix for this immanent release is just to always show them, and always allow them to be set. Effectively undoes some changes from aa663b7e89d3d02248d37ee9f68b52770b247018
2023-04-11Merge pull request #7798 from peeley/list-experimental-featuresEelco Dolstra
Documentation: list experimental features in manual
2023-04-11NitpicksEelco Dolstra
2023-04-07Merge pull request #8179 from tweag/disable-gc-on-coroutineRobert Hensing
disable gc on coroutine
2023-04-07Require openssl >= 1.1.1Robert Hensing
Versions older this are sufficiently old that we don't want to support them, and they require extra support code.
2023-04-07libutil: Provide alternatives to startSignalHandlerThreadRobert Hensing
How signals should be handled depends on what kind of process Nix is integrated into. The signal handler thread used by the stand-alone Nix commands / processes may not work well in the context of other runtime systems, such as those of Python, Perl, or Haskell.
2023-04-07Move OpenSSL init to initLibUtilRobert Hensing
Part of an effort to make it easier to initialize the right things, by moving code into the appropriate libraries.
2023-04-07Finish converting existing comments for internal API docs (#8146)John Ericson
* Finish converting existing comments for internal API docs 99% of this was just reformatting existing comments. Only two exceptions: - Expanded upon `BuildResult::status` compat note - Split up file-level `symbol-table.hh` doc comments to get per-definition docs Also fixed a few whitespace goofs, turning leading tabs to spaces and removing trailing spaces. Picking up from #8133 * Fix two things from comments * Use triple-backtick not indent for `dumpPath` * Convert GNU-style `\`..'` quotes to markdown style in API docs This will render correctly.