Compare commits

..
Author SHA1 Message Date
John Ericson 6a839b5f30 Introduce ParsedRelativeUrl
For NAR URLs in libstore, we will want a proper notion of a relative
URL. As such, we are making this type to complement `ParsedURL`.

`parseURLRelative` used to be a relatively black-box function using
Boost, but now that we have this separate type, we can properly
decompose the parsing and the resolving parts into separate functions,
leaving this function a thin wrapper.

The relative URL resolution I tried to continue doing with Boost, but it
prooved difficult --- we were already working around two bugs, and the
rountrip encodings were janks, so I just ended up reimplementing it from
scratch (with the LLM). Since the inputs are both fully decoded abstract
syntax, this ended up making nice readable code.

The existing `parseURLRelative` unit test data is very good, so we just
extended that test suite with new functions to test the round trips on
the constituent parts.
2026-02-26 14:47:15 -05:00
John Ericson 95e647df89 Add a test case for relative ? empty explicit params vs none at all
Unlike with absolute (complete) URLs, with relative URLs, this does make
a difference -- explicit empty overrides, implicit empty does not.
2026-02-26 14:46:15 -05:00
John Ericson 371f017afa Convert parseURLRelative tests to parameters test suite
This will allow extending it further in the next commit
2026-02-26 14:37:27 -05:00
Sergei Zimmerman 128688db63 Merge pull request #15280 from NixOS/local-store-filesystem
libstore: Fix pct-encoding issues in store references
2026-02-26 15:37:50 +00:00
Sergei Zimmerman 224c8182df libstore: Fix pct-encoding issues in store references
When the common pattern for store config constructors is to accept
an arbitrary string it's unclear whether it needs pct-decoding or not.
Prior to c436b7a32a the string passed to
the constructors was a mix of encoded authority and decoded path concatenated
with a `/`. After that commit it accidentally started accepting pct-encoded
result of renderAuthorityAndPath, but only in some code paths. This lead to
file:///tmp/a+b to be created on disk in /tmp/a%2Bb directory. Similar issue
affected the less-known variant with local:///tmp/a+b. Regular store references
that are local paths were not affected.

This patch changes the constructors to accept different types to signify what
is actually needed to let the factory method handle this in a consistent way:

- std::filesystem::path - local binary cache store and local store
- ParsedURL::Authority - for ssh stores
- ParsedURL - for http stores

(Some MinGW build fixes by Amaan Qureshi <git@amaanq.com>)
2026-02-26 16:40:49 +03:00
Sergei Zimmerman db06ac411c Merge pull request #15347 from obsidiansystems/unlink-wrapper
Create two wrappers for `unlink`
2026-02-26 09:20:16 +00:00
John Ericson d9dd677448 Create two wrappers for unlink
See b9ef088e80 for why
`std::filesystem::remove` was no good.
2026-02-25 22:27:59 -05:00
John Ericson ee955b3206 Merge pull request #15346 from obsidiansystems/return-owned-fd
Return `AutoCloseFD` in open-like functions
2026-02-26 02:09:43 +00:00
John EricsonandAmaan Qureshi 89dd96efbf Return AutoCloseFD in open-like functions
This reflects the fact that it is returning a new, "owned" file
descriptor, that it is the caller's responsibility to close.

Co-authored-by: Amaan Qureshi <git@amaanq.com>
2026-02-25 20:17:30 -05:00
John Ericson 6481e75283 Merge pull request #15344 from NixOS/no-filesystem-remove
Revert "libstore: replace unlink() with std::filesystem::remove()"
2026-02-26 00:50:16 +00:00
John Ericson b9ef088e80 Revert "libstore: replace unlink() with std::filesystem::remove()"
This reverts commit b8caabe25f.

`std::filesystem::remove` will actually do a `rmdir` for directories.
Per https://en.cppreference.com/w/cpp/filesystem/remove.html :

> The file or empty directory identified by the path p is deleted as if
> by the POSIX remove. Symlinks are not followed (symlink is removed,
> not its target).

See
https://pubs.opengroup.org/onlinepubs/9699919799/functions/remove.html

This is a behavior change that we can't be sure is fine, so let's revert
for now. We can do an unlink wrapper later to avoid the `.string()`.
2026-02-25 18:59:28 -05:00
John Ericson 02bb3d032d Merge pull request #15336 from NixOS/libcurl-content-encoding
filetransfer: Use libcurl for Content-Encoding/Transfer-Encoding transparent decompression
2026-02-25 23:19:34 +00:00
John Ericson 89a4412673 Merge pull request #15326 from obsidiansystems/no-abs-paths-in-eval
New diagnostics infra
2026-02-25 23:18:21 +00:00
Sergei Zimmerman 06a1511bff Merge pull request #15082 from roberth/issue-15053
repl: support inherit statements and multiple bindings
2026-02-25 23:09:12 +00:00
Sergei Zimmerman f02bc896ef Merge pull request #15254 from roberth/fix-test-nix-shell-in-pwd-with-plus
fix(tests): use glob instead of regex in nix-shell test
2026-02-25 22:59:33 +00:00
Sergei Zimmerman 4cf6843acf Merge pull request #15341 from NixOS/fix-flake-regressions
Fix the nix-community/patsh/0.2.1 flake regression test (again)
2026-02-25 22:47:55 +00:00
John Ericson 5184f844bb New diagnostics infra
- Convert `no-url-literals` from experimental feature to `Diagnose`
  setting

  Replace `Xp::NoUrlLiterals` with a new `lint-url-literals` setting
  that accepts `ignore`, `warn`, or `fatal`. This provides more
  flexibility than the binary experimental feature.

- Convert `warn-short-path-literals` to use new lint infra

  We now have `lint-short-path-literals = ignore | warn | fatal`
  instead.

- Convert some of the tests to lang tests

Fix #10048
Progress on #10281
2026-02-25 17:29:56 -05:00
Sergei Zimmerman fa07d9d055 filetransfer: Use libcurl for Content-Encoding/Transfer-Encoding transparent decompression
Get rid of manual decompression entirely. We can support zstd, br,
deflate (which was broken previously) and gzip/x-gzip encodings via curl
without manual work on our side. This is the same approach that was taken by lix.

Also adds some tests for x-gzip support.
2026-02-26 01:28:46 +03:00
Robert Hensing ca0f40f29e parseReplBindingsFromBuf: assert non-null result 2026-02-25 23:19:37 +01:00
John Ericson ae33d09589 Merge pull request #15339 from obsidiansystems/convert-some-more-path
libstore: convert more `Path` to `std::filesystem::path`
2026-02-25 22:15:32 +00:00
Amaan Qureshi d4b9a81956 libstore: convert more Path to std::filesystem::path
This commit converts local filesystem paths throughout libstore from the
string-based `Path` typedef to `std::filesystem::path`.
2026-02-25 16:26:01 -05:00
Amaan Qureshi 91688d4a34 libstore: use OsStrings for SSH args 2026-02-25 16:25:32 -05:00
Amaan Qureshi b8caabe25f libstore: replace unlink() with std::filesystem::remove() 2026-02-25 16:25:32 -05:00
Sergei Zimmerman 76eca8fef3 Merge pull request #15272 from roberth/eval-warnings
Eval warnings
2026-02-25 21:05:56 +00:00
Eelco Dolstra 2334977863 Fix the nix-community/patsh/0.2.1 flake regression test (again) 2026-02-25 21:49:30 +01:00
Sergei Zimmerman c8b02e6ff3 Merge pull request #15335 from dramforever/jsonlogger-no-interrupts
Don't throw Interrupted from JSONLogger::write
2026-02-25 19:03:42 +00:00
dramforever 1210100421 libutil/logging: Use writeFullLogging in JSONLogger::write
Logging should not check for interrupts. Use the new writeFullLogging
function to write JSON output to get similar behavior to SimpleLogger.

This avoids the logger itself throwing Interrupted exceptions in
handleExceptions.
2026-02-26 01:36:54 +08:00
dramforever 473d54ed5f libutil/logging: Generalize writeToStderr into writeFullLogging
Generalize writeToStderr into writeFullLogging, with similar behavior
but taking an arbitrary fd, and reimplement writeToStderr with it as a
convenient wrapper.
2026-02-26 00:51:31 +08:00
John Ericson 937a076844 Merge pull request #15332 from obsidiansystems/windows-libutil-ci
ci: add Windows nix-util-tests job
2026-02-25 16:35:38 +00:00
John Ericson a2d1346852 Merge pull request #15333 from NixOS/canon-path-from-filename
Introduce `CanonPath::fromFilename`
2026-02-25 15:59:09 +00:00
John EricsonandSergei Zimmerman 7275556d61 Introduce CanonPath::fromFilename
See docs for what it is. Use in DerivationBuilderImpl::writeBuilderFile
and deletePath. Also adds O_DIRECTORY via openDirectory in deletePath.

Co-authored-by: Sergei Zimmerman <sergei@zimmerman.foo>
2026-02-25 13:36:42 +03:00
Amaan QureshiandBrian McKenna 2c6c3864ce libutil: fix unix-domain-socket unlink for Windows (use _wunlink)
Originally by Brian, narrowed to just libutil by Amaan.

Co-Authored-By: Brian McKenna <brian@brianmckenna.org>
2026-02-25 01:44:38 -05:00
Amaan QureshiandBrian McKenna 82f471f48e ci: add Windows nix-util-tests job
Originally by Brian, narrowed to just libutil by Amaan.

Co-Authored-By: Brian McKenna <brian@brianmckenna.org>
2026-02-25 01:41:11 -05:00
John Ericson 16f10c1321 Merge pull request #15329 from obsidiansystems/path-review-followup
file-system: drop redundant quotes around `PathFmt` and assert relative paths
2026-02-25 04:43:04 +00:00
Amaan Qureshi d5dafb35c3 local-fs-store: make toRealPath accept StorePath only 2026-02-24 22:25:28 -05:00
Amaan Qureshi f4dfbca04d Fix issues from #15313
- file-system: drop redundant quotes around `PathFmt` and assert relative paths
- libutil, libstore: fix mingw cross-compilation breakages
2026-02-24 19:00:25 -05:00
John Ericson cf1ead7872 Merge pull request #15330 from NixOS/file-system-get-rid-of-fs-to-string
libutil: Get rid of double-quoting and .string() calls in file-system.cc
2026-02-24 22:23:26 +00:00
John Ericson 56735e9d0f Merge pull request #15328 from NixOS/more-hardening-file-system-at-builders
DerivationBuilderImpl: Add more hardening for writeBuilderFile
2026-02-24 21:57:44 +00:00
Sergei Zimmerman 5b9c41f1b7 libutil: Get rid of double-quoting and .string() calls in file-system.cc
Significantly reduces the amount of churny .string() conversions when
we don't need them and gets rid of annoying double-quoting issues once again.
2026-02-25 00:34:11 +03:00
John Ericson 63845dd9b3 Merge pull request #15313 from obsidiansystems/no-path-libutil
libutil: replace string-based Path with std::filesystem::path across core libraries
2026-02-24 18:56:19 +00:00
John EricsonandAmaan Qureshi b84a42f4cc libutil: replace string-based Path with std::filesystem::path across core libraries
This takes the `std::filesystem::path` migration from the CLI layer into the core libraries (libutil, libstore, libexpr, libfetchers, libflake), converting function signatures, settings fields, and locals throughout `file-system.hh`, `archive.hh`, `configuration.hh`, and their implementations. `PathSetting` becomes `Setting<std::filesystem::path>` in `local-overlay-store.hh` and `local-store.hh` with `.get()` calls at use sites, and several `writeFile` overloads collapse now that the `Path`-based wrappers in `file-system.hh` are gone.

Co-authored-by: Amaan Qureshi <git@amaanq.com>
2026-02-24 13:05:16 -05:00
John Ericson 003b64476e Merge pull request #15312 from obsidiansystems/convert-more-end-exes
cli: continue converting `Path` to `std::filesystem::path` in CLI commands
2026-02-24 17:24:26 +00:00
John Ericson 1e499e616a Merge pull request #15325 from obsidiansystems/rootless-daemon-nixpkgs
tests/functional/unprivileged-daemon: Use nixpkgs unprivileged support
2026-02-24 16:19:36 +00:00
Sergei Zimmerman 246c3fe8d3 DerivationBuilderImpl: Add more hardening for writeBuilderFile
Adds additional layers of hardening for various file-writing utility
functions in the derivation builder. Bad names in non-structured attrs
case are already checked against `[A-Za-z_][A-Za-z0-9_.-]*` regex, so
this isn't an issue, but adding more hardening is good regardless.
2026-02-24 19:15:19 +03:00
Artemis Tosini ade94a5c0e tests/functional/unprivileged-daemon: Use nixpkgs unprivileged support
Nixpkgs recently added support for running the daemon as unprivileged.
Instead of duplicating the test setup, use the upstream module.
2026-02-24 10:35:37 -05:00
siddhantCodesandAmaan Qureshi a5a256265f cli: continue converting Path to std::filesystem::path in CLI commands
Follows previous work by converting more string-based `Path` fields and
locals to `std::filesystem::path` across the CLI layer:
`MixOutLinkBase::outLink`, `CmdAddToStore::path`, `CmdBundle::outLink`,
`CmdDevelop` redirects and shell, `nix-build`, `nix-channel`, `nix-env`,
`nix-instantiate`, `nix-store`, and `upgrade-nix`.

Also, change `runProgram` and friends to use `OsString` for argument
lists, since those will be native strings. This allows us to avoid
(potentially lossy) `std::filesystem::path` (wide chars on windows) ->
`std::string` (narrow) -> `OsString` (i.e. `std::wstring` on Windows,
wide again) round trips. For CLIs with no path arguments, there is a
`toOsStrings` function for convenience, however.

Progress on #9205

Co-authored-by: Amaan Qureshi <git@amaanq.com>
2026-02-23 15:46:31 -05:00
John Ericson be7b9a33ed Replace renderUrlPathEnsureLegal with urlPathToPath
We make `urlPathToPath` support relative paths for of Flakes.

The mercurial fetching got a bit larger of a rework with this, by taking
advantage of `std::variant`.
2026-02-23 15:41:03 -05:00
Sergei Zimmerman d89400d052 libstore/filetransfer: Use bitfields for boolean flags in TransferItem
Wastes slightly less memory. Also gets the doc-comments in order.
2026-02-23 15:48:49 +03:00
Robert Hensing 5c42b84a17 chore(nix): fix evaluation warnings 2026-02-17 16:45:38 +01:00
Robert Hensing a3e99602c0 fix(tests): use glob instead of regex in nix-shell test
The NIX_BUILD_TOP test used regex matching with an unquoted path
variable. When the path contains `+` (or other regex operators),
the test fails because `+` is interpreted as a quantifier rather than
a literal character. Glob matching handles these characters correctly.
2026-02-16 21:06:55 +01:00
Robert Hensing 3083226336 fix(packaging): restrict nix-nswrapper to Linux platforms
It is only supported on that host platform.
This adds a bunch of redundant-ish wiring logic, because the alternative
is accessing `meta.platforms` generically, but that would cause these
flake output attrsets *containing* the packages to be *strict in all
packages*, which is very bad for performance and robustness.

Checked:
- Cross-compilation still works for Linux targets (arm, riscv),
  even when build platform is Darwin
- No attributes for nix-nswrapper for native Darwin
2026-02-16 17:22:19 +01:00
Robert Hensing 5ee5e6e8a0 release notes: repl inherit and multiple bindings 2026-01-28 17:44:51 +01:00
Robert Hensing 0f2754a682 repl: support inherit statements and multiple bindings
Fixes #15053

This adds support for inherit statements and multiple bindings per
line in nix repl:

    nix-repl> a = { x = 1; y = 2; }
    nix-repl> inherit (a) x y
    nix-repl> x + y
    3

    nix-repl> p = 1; q = 2;
    nix-repl> p + q
    3

Design
------

The REPL now uses a parser-based approach instead of ad-hoc regex
matching. It tries parsing input in order:

  1. As an expression (using the regular parser entry point)
  2. As bindings (using a new REPL_BINDINGS entry point)
  3. As bindings with an appended semicolon (for convenience)

The third attempt allows users to omit the trailing semicolon for
single statements like "inherit (a) x" or "foo = 1".

A separate REPL_BINDINGS parser entry point is required because
combining expressions and bindings in the same production causes
reduce/reduce conflicts: "ID ." is ambiguous between attribute access
(a.b) and the start of a nested binding path (a.b = 1).

Alternatives considered
-----------------------

GLR parsing: Would resolve the ambiguity but risks parsing
performance regression for all Nix code, not just the REPL.

Duplicated grammar: A REPL-specific repl_binds production that
duplicates binds1 rules. Rejected to avoid maintenance burden and
grammar drift.

Single binding per line: Simpler but less useful. The current
approach reuses binds1 directly, getting multiple bindings and
nested attribute paths for free.

Tradeoffs
---------

Binding input may be parsed twice (once as expression, then as
bindings). This is acceptable for interactive REPL use where input is
typically small and latency from parsing is negligible.

Error messages preserve the original input even when the semicolon-
appended parse is attempted, so users see "inherit (a) y" in errors
rather than "inherit (a) y;".
2026-01-28 17:44:51 +01:00
223 changed files with 2979 additions and 1857 deletions

No files matched your search

+18
View File
@@ -137,6 +137,24 @@ jobs:
path: out/*
if: ${{ matrix.primary }}
windows_tests:
needs: basic-checks
name: windows unit tests
runs-on: ubuntu-24.04
continue-on-error: true
timeout-minutes: 60
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- uses: ./.github/actions/install-nix-action
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
dogfood: ${{ github.event_name == 'workflow_dispatch' && inputs.dogfood || github.event_name != 'workflow_dispatch' }}
- name: Run Windows unit tests
run: |
nix build --file ci/gha/tests/windows.nix unitTests.nix-util-tests -L
installer_test:
needs: [tests]
strategy:
+30
View File
@@ -0,0 +1,30 @@
{
nixFlake ? builtins.getFlake ("git+file://" + toString ../../..),
system ? builtins.currentSystem,
pkgs ? nixFlake.inputs.nixpkgs.legacyPackages.${system},
}:
let
packages = nixFlake.packages.${system};
fixOutput =
test:
test.overrideAttrs (prev: {
nativeBuildInputs = prev.nativeBuildInputs or [ ] ++ [ pkgs.colorized-logs ];
env.GTEST_COLOR = "no";
# Wine's console emulation wraps every character in ANSI cursor
# hide/show sequences, making logs unreadable in GitHub Actions.
buildCommand = ''
set -o pipefail
{
${prev.buildCommand}
} 2>&1 | ansi2txt
'';
});
in
{
unitTests = {
"nix-util-tests" = fixOutput packages."nix-util-tests-x86_64-w64-mingw32".passthru.tests.run;
};
}
@@ -0,0 +1,10 @@
---
synopsis: Content-Encoding decompression is now handled by libcurl
prs: [15336]
issues: [14324]
---
Transparent decompression of HTTP downloads specifying `Content-Encoding` header now uses libcurl. This adds support for previously advertised, but not supported `deflate` encoding as well as deprecated `x-gzip` alias.
Non-standard `xz`, `bzip2` encodings that were previously advertised are no longer supported, as they do not commonly appear in the wild and should not be sent by compliant servers.
`br`, `zstd`, `gzip` continue to be supported. Distro packaging should ensure that the `libcurl` dependency is linked against required libraries to support these encodings. By default now the build system requires libcurl >= 8.17.0 which is not known to have issues around [pausing and decompression](https://github.com/curl/curl/issues/16280).
+42
View File
@@ -0,0 +1,42 @@
---
synopsis: "New diagnostics infrastructure, with `lint-url-literals` and `lint-short-path-literals` settings"
prs: [15326]
issues: [10048, 10281]
---
A new diagnostics infrastructure has been added for controlling language features that we are considering deprecating.
## [`lint-url-literals`](@docroot@/command-ref/conf-file.md#conf-lint-url-literals)
The `no-url-literals` experimental feature has been stabilized and replaced with a new [`lint-url-literals`](@docroot@/command-ref/conf-file.md#conf-lint-url-literals) setting.
To migrate from the experimental feature, replace:
```
experimental-features = no-url-literals
```
with:
```
lint-url-literals = fatal
```
## [`lint-short-path-literals`](@docroot@/command-ref/conf-file.md#conf-lint-short-path-literals)
The [`warn-short-path-literals`](@docroot@/command-ref/conf-file.md#conf-warn-short-path-literals) boolean setting has been deprecated and replaced with [`lint-short-path-literals`](@docroot@/command-ref/conf-file.md#conf-lint-short-path-literals).
To migrate, replace:
```
warn-short-path-literals = true
```
with:
```
lint-short-path-literals = warn
```
## Setting values
Both settings accept three values:
- `ignore`: Allow the feature without any diagnostic (default)
- `warn`: Emit a warning when the feature is used
- `fatal`: Treat the feature as a parse error
In the future, we may change what the defaults are.
+21
View File
@@ -0,0 +1,21 @@
---
synopsis: "`nix repl` now supports `inherit` and multiple bindings"
prs: [15082]
---
The `nix repl` now supports `inherit` statements and multiple bindings per line:
```
nix-repl> a = { x = 1; y = 2; }
nix-repl> inherit (a) x y
nix-repl> x + y
3
nix-repl> p = 1; q = 2;
nix-repl> p + q
3
nix-repl> foo.bar.baz = 1;
nix-repl> foo.bar
{ baz = 1; }
```
Generated
+4 -4
View File
@@ -63,11 +63,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1771043024,
"narHash": "sha256-WoiezqWJQ3OHILah+p6rzNXdJceEAmAhyDFZFZ6pZzY=",
"rev": "3aadb7ca9eac2891d52a9dec199d9580a6e2bf44",
"lastModified": 1771903837,
"narHash": "sha256-jEA8WggGKtMFeNeCKq3NK8cLEjJmG6/RLUElYYbBZ0E=",
"rev": "e764fc9a405871f1f6ca3d1394fb422e0a0c3951",
"type": "tarball",
"url": "https://releases.nixos.org/nixos/25.11/nixos-25.11.5960.3aadb7ca9eac/nixexprs.tar.xz"
"url": "https://releases.nixos.org/nixos/25.11/nixos-25.11.6495.e764fc9a4058/nixexprs.tar.xz"
},
"original": {
"type": "tarball",
+27 -20
View File
@@ -409,7 +409,9 @@
"nix-cmd" = { };
"nix-nswrapper" = { };
"nix-nswrapper" = {
linuxOnly = true;
};
"nix-cli" = { };
@@ -431,32 +433,37 @@
pkgName:
{
supportsCross ? true,
linuxOnly ? false,
}:
{
# These attributes go right into `packages.<system>`.
"${pkgName}" = nixpkgsFor.${system}.native.nixComponents2.${pkgName};
"${pkgName}-static" = nixpkgsFor.${system}.native.pkgsStatic.nixComponents2.${pkgName};
"${pkgName}-llvm" = nixpkgsFor.${system}.native.pkgsLLVM.nixComponents2.${pkgName};
}
lib.optionalAttrs (linuxOnly -> nixpkgsFor.${system}.native.stdenv.hostPlatform.isLinux) (
{
# These attributes go right into `packages.<system>`.
"${pkgName}" = nixpkgsFor.${system}.native.nixComponents2.${pkgName};
"${pkgName}-static" = nixpkgsFor.${system}.native.pkgsStatic.nixComponents2.${pkgName};
"${pkgName}-llvm" = nixpkgsFor.${system}.native.pkgsLLVM.nixComponents2.${pkgName};
}
// flatMapAttrs (lib.genAttrs stdenvs (_: { })) (
stdenvName:
{ }:
{
# These attributes go right into `packages.<system>`.
"${pkgName}-${stdenvName}" =
nixpkgsFor.${system}.nativeForStdenv.${stdenvName}.nixComponents2.${pkgName};
}
)
)
// lib.optionalAttrs supportsCross (
flatMapAttrs (lib.genAttrs crossSystems (_: { })) (
crossSystem:
{ }:
{
# These attributes go right into `packages.<system>`.
"${pkgName}-${crossSystem}" = nixpkgsFor.${system}.cross.${crossSystem}.nixComponents2.${pkgName};
}
lib.optionalAttrs
(linuxOnly -> nixpkgsFor.${system}.cross.${crossSystem}.stdenv.hostPlatform.isLinux)
{
# These attributes go right into `packages.<system>`.
"${pkgName}-${crossSystem}" = nixpkgsFor.${system}.cross.${crossSystem}.nixComponents2.${pkgName};
}
)
)
// flatMapAttrs (lib.genAttrs stdenvs (_: { })) (
stdenvName:
{ }:
{
# These attributes go right into `packages.<system>`.
"${pkgName}-${stdenvName}" =
nixpkgsFor.${system}.nativeForStdenv.${stdenvName}.nixComponents2.${pkgName};
}
)
)
// lib.optionalAttrs (builtins.elem system linux64BitSystems) {
dockerImage =
+5
View File
@@ -95,6 +95,11 @@
''^tests/functional/lang/eval-fail-bad-string-interpolation-3\.nix$''
''^tests/functional/lang/eval-fail-bad-string-interpolation-4\.nix$''
''^tests/functional/lang/eval-okay-regex-match2\.nix$''
# URL literal tests - nixfmt converts unquoted URLs to strings
''^tests/functional/lang/eval-fail-url-literal\.nix$''
''^tests/functional/lang/eval-okay-url-literal-warn\.nix$''
''^tests/functional/lang/eval-okay-url-literal-default\.nix$''
];
};
clang-format = {
+3 -1
View File
@@ -1,6 +1,6 @@
{
runCommand,
system,
stdenv,
buildPackages,
cacert,
nix,
@@ -9,6 +9,8 @@
let
inherit (stdenv.hostPlatform) system;
installerClosureInfo = buildPackages.closureInfo {
rootPaths = [
nix
+13 -3
View File
@@ -30,9 +30,19 @@ scope: {
NIX_CFLAGS_COMPILE = "-DINITIAL_MARK_STACK_SIZE=1048576";
});
curl = pkgs.curl.override {
http3Support = !pkgs.stdenv.hostPlatform.isWindows;
};
curl =
(pkgs.curl.override {
http3Support = !pkgs.stdenv.hostPlatform.isWindows;
# Make sure we enable all the dependencies for Content-Encoding/Transfer-Encoding decompression.
zstdSupport = true;
brotliSupport = true;
zlibSupport = true;
}).overrideAttrs
{
# TODO: Fix in nixpkgs. Static build with brotli is marked as broken, but it's not the case.
# Remove once https://github.com/NixOS/nixpkgs/pull/494111 lands in the 25.11 channel.
meta.broken = false;
};
libblake3 = pkgs.libblake3.override {
useTBB = !(stdenv.hostPlatform.isWindows || stdenv.hostPlatform.isStatic);
+23 -3
View File
@@ -115,7 +115,11 @@ rec {
# Binary package for various platforms.
build = forAllPackages (
pkgName: forAllSystems (system: nixpkgsFor.${system}.native.nixComponents2.${pkgName})
pkgName:
lib.filterAttrs (
system: _do_not_touch:
pkgName == "nix-nswrapper" -> nixpkgsFor.${system}.native.stdenv.hostPlatform.isLinux
) (forAllSystems (system: nixpkgsFor.${system}.native.nixComponents2.${pkgName}))
);
shellInputs = removeAttrs (forAllSystems (
@@ -135,6 +139,10 @@ rec {
(
if pkgName == "nix-functional-tests" then
lib.flip builtins.removeAttrs [ "x86_64-w64-mingw32" ]
else if pkgName == "nix-nswrapper" then
lib.filterAttrs (
crossSystem: _do_not_touch: nixpkgsFor.x86_64-linux.cross.${crossSystem}.stdenv.hostPlatform.isLinux
)
else
lib.id
)
@@ -171,7 +179,13 @@ rec {
)
);
in
forAllPackages (pkgName: forAllSystems (system: components.${system}.${pkgName}));
forAllPackages (
pkgName:
lib.filterAttrs (
system: _do_not_touch:
pkgName == "nix-nswrapper" -> nixpkgsFor.${system}.native.stdenv.hostPlatform.isLinux
) (forAllSystems (system: components.${system}.${pkgName}))
);
buildNoTests = forAllSystems (system: nixpkgsFor.${system}.native.nixComponents2.nix-cli);
@@ -191,7 +205,13 @@ rec {
)
);
in
forAllPackages (pkgName: forAllSystems (system: components.${system}.${pkgName}));
forAllPackages (
pkgName:
lib.filterAttrs (
system: _do_not_touch:
pkgName == "nix-nswrapper" -> nixpkgsFor.${system}.native.stdenv.hostPlatform.isLinux
) (forAllSystems (system: components.${system}.${pkgName}))
);
# Perl bindings for various platforms.
perlBindings = forAllSystems (system: nixpkgsFor.${system}.native.nixComponents2.nix-perl-bindings);
+2 -2
View File
@@ -407,7 +407,7 @@ void createOutLinks(const std::filesystem::path & outLink, const BuiltPaths & bu
struct MixOutLinkBase : virtual Args
{
/** Prefix for any output symlinks. Empty means do not write an output symlink. */
Path outLink;
std::filesystem::path outLink;
MixOutLinkBase(const std::string & defaultOutLink)
: outLink(defaultOutLink)
@@ -435,7 +435,7 @@ struct MixOutLinkByDefault : MixOutLinkBase, virtual Args
addFlag({
.longName = "no-link",
.description = "Do not create symlinks to the build results.",
.handler = {&outLink, Path("")},
.handler = {&outLink, std::filesystem::path{}},
});
}
};
@@ -3,6 +3,7 @@
#include "nix/util/finally.hh"
#include "nix/util/types.hh"
#include <filesystem>
#include <functional>
#include <string>
@@ -36,10 +37,10 @@ public:
class ReadlineLikeInteracter : public virtual ReplInteracter
{
std::string historyFile;
std::filesystem::path historyFile;
public:
ReadlineLikeInteracter(std::string historyFile)
: historyFile(historyFile)
ReadlineLikeInteracter(std::filesystem::path historyFile)
: historyFile(std::move(historyFile))
{
}
+2 -2
View File
@@ -2,6 +2,7 @@
///@file
#include "nix/expr/eval.hh"
#include "nix/util/os-string.hh"
namespace nix {
@@ -27,8 +28,7 @@ struct AbstractNixRepl
* @param programName Name of the command, e.g. `nix` or `nix-env`.
* @param args arguments to the command.
*/
using RunNix =
void(const std::string & programName, const Strings & args, const std::optional<std::string> & input);
using RunNix = void(const std::string & programName, OsStrings args, const std::optional<std::string> & input);
/**
* @param runNix Function to run the nix CLI to support various
+1 -1
View File
@@ -157,7 +157,7 @@ MixFlakeOptions::MixFlakeOptions()
.category = category,
.labels = {"flake-lock-path"},
.handler = {[&](std::string lockFilePath) {
lockFlags.referenceLockFilePath = {getFSSourceAccessor(), CanonPath(absPath(lockFilePath))};
lockFlags.referenceLockFilePath = {getFSSourceAccessor(), CanonPath(absPath(lockFilePath).string())};
}},
.completer = completePath,
});
+3 -3
View File
@@ -118,14 +118,14 @@ ReadlineLikeInteracter::Guard ReadlineLikeInteracter::init(detail::ReplCompleter
// Allow nix-repl specific settings in .inputrc
rl_readline_name = "nix-repl";
try {
createDirs(dirOf(historyFile));
createDirs(historyFile.parent_path());
} catch (SystemError & e) {
logWarning(e.info());
}
#if !USE_READLINE
el_hist_size = 1000;
#endif
read_history(historyFile.c_str());
read_history(historyFile.string().c_str());
auto oldRepl = curRepl;
curRepl = repl;
Guard restoreRepl([oldRepl] { curRepl = oldRepl; });
@@ -208,7 +208,7 @@ bool ReadlineLikeInteracter::getLine(std::string & input, ReplPromptType promptT
ReadlineLikeInteracter::~ReadlineLikeInteracter()
{
write_history(historyFile.c_str());
write_history(historyFile.string().c_str());
}
}; // namespace nix
+54 -31
View File
@@ -1,6 +1,7 @@
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <memory>
#include "nix/util/error.hh"
#include "nix/cmd/repl-interacter.hh"
@@ -28,6 +29,8 @@
#include "nix/util/ref.hh"
#include "nix/expr/value.hh"
#include "nix/util/os-string.hh"
#include "nix/util/processes.hh"
#include "nix/util/strings.hh"
namespace nix {
@@ -71,7 +74,7 @@ struct NixRepl : AbstractNixRepl, detail::ReplCompleterMixin, gc
RunNix * runNixPtr;
void runNix(const std::string & program, const Strings & args, const std::optional<std::string> & input = {});
void runNix(const std::string & program, OsStrings args, const std::optional<std::string> & input = {});
std::unique_ptr<ReplInteracter> interacter;
@@ -98,6 +101,7 @@ struct NixRepl : AbstractNixRepl, detail::ReplCompleterMixin, gc
void addAttrsToScope(Value & attrs);
void addVarToScope(const Symbol name, Value & v);
Expr * parseString(std::string s);
ExprAttrs * parseReplBindings(std::string s);
void evalString(std::string s, Value & v);
void loadDebugTraceEnv(DebugTrace & dt);
@@ -139,7 +143,7 @@ NixRepl::NixRepl(
, getValues(getValues)
, staticEnv(new StaticEnv(nullptr, state->staticBaseEnv))
, runNixPtr{runNix}
, interacter(make_unique<ReadlineLikeInteracter>((getDataDir() / "repl-history").string()))
, interacter(std::make_unique<ReadlineLikeInteracter>(getDataDir() / "repl-history"))
{
}
@@ -306,21 +310,6 @@ StringSet NixRepl::completePrefix(const std::string & prefix)
return completions;
}
// FIXME: DRY and match or use the parser
static bool isVarName(std::string_view s)
{
if (s.size() == 0)
return false;
char c = s[0];
if ((c >= '0' && c <= '9') || c == '-' || c == '\'')
return false;
for (auto & i : s)
if (!((i >= 'a' && i <= 'z') || (i >= 'A' && i <= 'Z') || (i >= '0' && i <= '9') || i == '_' || i == '-'
|| i == '\''))
return false;
return true;
}
StorePath NixRepl::getDerivationPath(Value & v)
{
auto packageInfo = getDerivation(*state, v, false);
@@ -508,7 +497,12 @@ ProcessLineResult NixRepl::processLine(std::string line)
// runProgram redirects stdout to a StringSink,
// using runProgram2 to allow editors to display their UI
runProgram2(RunOptions{.program = editor, .lookupPath = true, .args = args, .isInteractive = true});
runProgram2({
.program = editor,
.lookupPath = true,
.args = toOsStrings(std::move(args)),
.isInteractive = true,
});
// Reload right after exiting the editor
state->resetFileCache();
@@ -528,7 +522,7 @@ ProcessLineResult NixRepl::processLine(std::string line)
state->callFunction(f, v, result, PosIdx());
StorePath drvPath = getDerivationPath(result);
runNix("nix-shell", {state->store->printStorePath(drvPath)});
runNix("nix-shell", toOsStrings({state->store->printStorePath(drvPath)}));
}
else if (command == ":b" || command == ":bl" || command == ":i" || command == ":sh" || command == ":log") {
@@ -559,7 +553,7 @@ ProcessLineResult NixRepl::processLine(std::string line)
}
}
} else if (command == ":i") {
runNix("nix-env", {"-i", drvPathRaw});
runNix("nix-env", toOsStrings({"-i", drvPathRaw}));
} else if (command == ":log") {
settings.readOnlyMode = true;
Finally roModeReset([&]() { settings.readOnlyMode = false; });
@@ -567,7 +561,7 @@ ProcessLineResult NixRepl::processLine(std::string line)
auto log = fetchBuildLog(state->store, drvPath, drvPathRaw);
logger->writeToStdout(log);
} else {
runNix("nix-shell", {drvPathRaw});
runNix("nix-shell", toOsStrings({drvPathRaw}));
}
}
@@ -668,15 +662,22 @@ ProcessLineResult NixRepl::processLine(std::string line)
throw Error("unknown command '%1%'", command);
else {
size_t p = line.find('=');
std::string name;
if (p != std::string::npos && p < line.size() && line[p + 1] != '='
&& isVarName(name = removeWhitespace(line.substr(0, p)))) {
Expr * e = parseString(line.substr(p + 1));
Value & v(*state->allocValue());
v.mkThunk(env, e);
addVarToScope(state->symbols.create(name), v);
// Try parsing as bindings first (handles `x = 1`, `inherit ...`, etc.)
ExprAttrs * bindings = nullptr;
try {
bindings = parseReplBindings(line);
} catch (ParseError &) {
}
if (bindings) {
Env * inheritEnv = bindings->inheritFromExprs ? bindings->buildInheritFromEnv(*state, *env) : nullptr;
for (auto & [symbol, def] : *bindings->attrs) {
Value & v(*state->allocValue());
v.mkThunk(def.chooseByKind(env, env, inheritEnv), def.e);
addVarToScope(symbol, v);
}
} else {
// Otherwise evaluate as expression
Value v;
evalString(line, v);
auto suspension = logger->suspend();
@@ -865,6 +866,28 @@ Expr * NixRepl::parseString(std::string s)
}
}
ExprAttrs * NixRepl::parseReplBindings(std::string s)
{
auto basePath = state->rootPath(".");
// Try parsing as bindings
std::exception_ptr bindingsError;
try {
return state->parseReplBindings(s, basePath, staticEnv);
} catch (ParseError &) {
bindingsError = std::current_exception();
}
// Try with semicolon appended (for `inherit foo` shorthand)
// Use original source (s) for error messages, not s + ";"
try {
return state->parseReplBindings(s + ";", s, basePath, staticEnv);
} catch (ParseError &) {
// Semicolon retry failed; rethrow the original bindings error
std::rethrow_exception(bindingsError);
}
}
void NixRepl::evalString(std::string s, Value & v)
{
Expr * e = parseString(s);
@@ -872,10 +895,10 @@ void NixRepl::evalString(std::string s, Value & v)
state->forceValue(v, v.determinePos(noPos));
}
void NixRepl::runNix(const std::string & program, const Strings & args, const std::optional<std::string> & input)
void NixRepl::runNix(const std::string & program, OsStrings args, const std::optional<std::string> & input)
{
if (runNixPtr)
(*runNixPtr)(program, args, input);
(*runNixPtr)(program, std::move(args), input);
else
throw Error(
"Cannot run '%s' because no method of calling the Nix CLI was provided. This is a configuration problem pertaining to how this program was built. See Nix 2.25 release notes",
+55
View File
@@ -0,0 +1,55 @@
#include "nix/expr/diagnose.hh"
#include "nix/util/configuration.hh"
#include "nix/util/config-impl.hh"
#include "nix/util/abstract-setting-to-json.hh"
#include <nlohmann/json.hpp>
namespace nix {
template<>
Diagnose BaseSetting<Diagnose>::parse(const std::string & str) const
{
if (str == "ignore")
return Diagnose::Ignore;
else if (str == "warn")
return Diagnose::Warn;
else if (str == "fatal")
return Diagnose::Fatal;
else
throw UsageError("option '%s' has invalid value '%s' (expected 'ignore', 'warn', or 'fatal')", name, str);
}
template<>
struct BaseSetting<Diagnose>::trait
{
static constexpr bool appendable = false;
};
template<>
std::string BaseSetting<Diagnose>::to_string() const
{
switch (value) {
case Diagnose::Ignore:
return "ignore";
case Diagnose::Warn:
return "warn";
case Diagnose::Fatal:
return "fatal";
default:
unreachable();
}
}
NLOHMANN_JSON_SERIALIZE_ENUM(
Diagnose,
{
{Diagnose::Ignore, "ignore"},
{Diagnose::Warn, "warn"},
{Diagnose::Fatal, "fatal"},
});
/* Explicit instantiation of templates */
template class BaseSetting<Diagnose>;
} // namespace nix
+7
View File
@@ -1,9 +1,16 @@
#include "nix/expr/eval-error.hh"
#include "nix/expr/eval.hh"
#include "nix/expr/value.hh"
#include "nix/store/store-api.hh"
namespace nix {
InvalidPathError::InvalidPathError(EvalState & state, const StorePath & path)
: CloneableError(state, "path '%s' is not valid", path.to_string())
, path{path}
{
}
template<class T>
EvalErrorBuilder<T> & EvalErrorBuilder<T>::withExitStatus(unsigned int exitStatus)
{
+1 -1
View File
@@ -137,7 +137,7 @@ public:
: state(state)
, sampleInterval(period)
, profileFd([&]() {
AutoCloseFD fd = openNewFileForWrite(
auto fd = openNewFileForWrite(
profileFile,
0660,
{
+21
View File
@@ -1,4 +1,5 @@
#include "nix/util/users.hh"
#include "nix/util/logging.hh"
#include "nix/store/globals.hh"
#include "nix/store/profiles.hh"
#include "nix/expr/eval.hh"
@@ -6,6 +7,26 @@
namespace nix {
void DeprecatedWarnSetting::assign(const bool & v)
{
value = v;
warn("'%s' is deprecated, use '%s = %s' instead", name, targetName, v ? "warn" : "ignore");
if (!target.overridden)
target = v ? Diagnose::Warn : Diagnose::Ignore;
}
void DeprecatedWarnSetting::appendOrSet(bool newValue, bool append)
{
assert(!append);
assign(newValue);
}
void DeprecatedWarnSetting::override(const bool & v)
{
overridden = true;
assign(v);
}
/* Very hacky way to parse $NIX_PATH, which is colon-separated, but
can contain URLs (e.g. "nixpkgs=https://bla...:foo=https://"). */
Strings EvalSettings::parseNixPath(const std::string & s)
+57 -11
View File
@@ -426,29 +426,36 @@ bool isAllowedURI(std::string_view uri, const Strings & allowedUris)
return false;
}
void EvalState::checkURI(const std::string & uri)
void EvalState::checkURI(const std::string & uri0)
{
if (!settings.restrictEval)
return;
if (isAllowedURI(uri, settings.allowedUris.get()))
if (isAllowedURI(uri0, settings.allowedUris.get()))
return;
/* If the URI is a path, then check it against allowedPaths as
well. */
if (isAbsolute(uri)) {
if (auto rootFS2 = rootFS.dynamic_pointer_cast<AllowListSourceAccessor>())
rootFS2->checkAccess(CanonPath(uri));
return;
{
std::filesystem::path path(uri0);
if (path.is_absolute()) {
if (auto rootFS2 = rootFS.dynamic_pointer_cast<AllowListSourceAccessor>())
rootFS2->checkAccess(CanonPath(path.string()));
return;
}
}
if (hasPrefix(uri, "file://")) {
if (auto rootFS2 = rootFS.dynamic_pointer_cast<AllowListSourceAccessor>())
rootFS2->checkAccess(CanonPath(uri.substr(7)));
return;
try {
ParsedURL uri = parseURL(uri0);
if (uri.scheme == "file") {
if (auto rootFS2 = rootFS.dynamic_pointer_cast<AllowListSourceAccessor>())
rootFS2->checkAccess(CanonPath(urlPathToPath(uri.path).string()));
return;
}
} catch (BadURL &) {
}
throw RestrictedPathError("access to URI '%s' is forbidden in restricted mode", uri);
throw RestrictedPathError("access to URI '%s' is forbidden in restricted mode", uri0);
}
Value * EvalState::addConstant(const std::string & name, Value & v, Constant info)
@@ -3201,6 +3208,21 @@ Expr * EvalState::parseExprFromString(std::string s, const SourcePath & basePath
return parseExprFromString(std::move(s), basePath, staticBaseEnv);
}
ExprAttrs *
EvalState::parseReplBindings(std::string s_, const SourcePath & basePath, const std::shared_ptr<StaticEnv> & staticEnv)
{
return parseReplBindings(s_, s_, basePath, staticEnv);
}
ExprAttrs * EvalState::parseReplBindings(
std::string s_, std::string errorSource, const SourcePath & basePath, const std::shared_ptr<StaticEnv> & staticEnv)
{
auto s = make_ref<std::string>(std::move(errorSource));
// flex requires two NUL terminators for yy_scan_buffer
s_.append("\0\0", 2);
return parseReplBindings(s_.data(), s_.size(), Pos::String{.source = s}, basePath, staticEnv);
}
Expr * EvalState::parseStdin()
{
// NOTE this method (and parseExprFromString) must take care to *fully copy* their
@@ -3342,6 +3364,30 @@ Expr * EvalState::parse(
return result;
}
ExprAttrs * EvalState::parseReplBindings(
char * text,
size_t length,
Pos::Origin origin,
const SourcePath & basePath,
const std::shared_ptr<StaticEnv> & staticEnv)
{
DocCommentMap tmpDocComments;
DocCommentMap * docComments = &tmpDocComments;
if (auto sourcePath = std::get_if<SourcePath>(&origin)) {
auto [it, _] = positionToDocComment.try_emplace(*sourcePath);
docComments = &it->second;
}
auto bindings = parseReplBindingsFromBuf(
text, length, origin, basePath, mem.exprs, symbols, settings, positions, *docComments, rootFS);
assert(bindings);
bindings->bindVars(*this, staticEnv);
return bindings;
}
DocComment EvalState::getDocCommentForPos(PosIdx pos)
{
auto pos2 = positions[pos];
+76
View File
@@ -0,0 +1,76 @@
#pragma once
///@file
#include <optional>
#include "nix/util/ansicolor.hh"
#include "nix/util/configuration.hh"
#include "nix/util/error.hh"
#include "nix/util/logging.hh"
namespace nix {
/**
* Diagnostic level for deprecated or non-portable language features.
*/
enum struct Diagnose {
/**
* Ignore the feature without any diagnostic.
*/
Ignore,
/**
* Warn when the feature is used, but allow it.
*/
Warn,
/**
* Treat the feature as a fatal error.
*/
Fatal,
};
template<>
Diagnose BaseSetting<Diagnose>::parse(const std::string & str) const;
template<>
std::string BaseSetting<Diagnose>::to_string() const;
/**
* Check a diagnostic setting and either do nothing, log a warning, or throw an error.
*
* The setting name is automatically appended to the error message.
*
* @param setting The diagnostic setting to check
* @param mkError A function that takes a bool (true if fatal, false if warning) and
* returns an optional error to throw (or warn with).
* Only called if level is not `Ignore`.
* If the function returns `std::nullopt`, no diagnostic is emitted.
*
* @throws The error returned by mkError if level is `Fatal` and mkError returns a value
*/
template<typename F>
void diagnose(const Setting<Diagnose> & setting, F && mkError)
{
auto withError = [&](bool fatal, auto && handler) {
auto maybeError = mkError(fatal);
if (!maybeError)
return;
auto & info = maybeError->unsafeInfo();
// Append the setting name to help users find the right setting
info.msg = HintFmt("%s (" ANSI_BOLD "%s" ANSI_NORMAL ")", Uncolored(info.msg.str()), setting.name);
maybeError->recalcWhat();
handler(std::move(*maybeError));
};
switch (setting.get()) {
case Diagnose::Ignore:
return;
case Diagnose::Warn:
withError(false, [](auto && error) { logWarning(error.info()); });
return;
case Diagnose::Fatal:
withError(true, [](auto && error) { throw std::move(error); });
return;
}
}
} // namespace nix
+3 -5
View File
@@ -2,6 +2,7 @@
#include "nix/util/error.hh"
#include "nix/util/pos-idx.hh"
#include "nix/store/path.hh"
namespace nix {
@@ -81,12 +82,9 @@ MakeError(RecoverableEvalError, EvalBaseError);
struct InvalidPathError : public CloneableError<InvalidPathError, EvalError>
{
public:
Path path;
StorePath path;
InvalidPathError(EvalState & state, const Path & path)
: CloneableError(state, "path '%s' is not valid", path)
{
}
InvalidPathError(EvalState & state, const StorePath & path);
};
/**
+89 -8
View File
@@ -1,6 +1,7 @@
#pragma once
///@file
#include "nix/expr/diagnose.hh"
#include "nix/expr/eval-profiler-settings.hh"
#include "nix/util/configuration.hh"
#include "nix/util/source-path.hh"
@@ -10,6 +11,36 @@ namespace nix {
class EvalState;
struct PrimOp;
/**
* A deprecated bool setting that migrates to a `Setting<Diagnose>`.
* When set to true, it emits a deprecation warning and sets the target
* `Setting<Diagnose>` setting to `warn`.
*/
class DeprecatedWarnSetting : public BaseSetting<bool>
{
Setting<Diagnose> & target;
const char * targetName;
public:
DeprecatedWarnSetting(
Config * options,
Setting<Diagnose> & target,
const char * targetName,
const std::string & name,
const std::string & description,
const StringSet & aliases = {})
: BaseSetting<bool>(false, true, name, description, aliases, std::nullopt)
, target(target)
, targetName(targetName)
{
options->addSetting(this);
}
void assign(const bool & v) override;
void appendOrSet(bool newValue, bool append) override;
void override(const bool & v) override;
};
struct EvalSettings : Config
{
/**
@@ -328,20 +359,70 @@ struct EvalSettings : Config
This option can be enabled by setting `NIX_ABORT_ON_WARN=1` in the environment.
)"};
Setting<bool> warnShortPathLiterals{
Setting<Diagnose> lintShortPathLiterals{
this,
false,
"warn-short-path-literals",
Diagnose::Ignore,
"lint-short-path-literals",
R"(
If set to true, the Nix evaluator will warn when encountering relative path literals
that don't start with `./` or `../`.
Controls handling of relative path literals that don't start with `./` or `../`.
For example, with this setting enabled, `foo/bar` would emit a warning
suggesting to use `./foo/bar` instead.
- `ignore`: Ignore without warning (default)
- `warn`: Emit a warning suggesting to use `./` prefix
- `fatal`: Treat as a parse error
For example, with this setting set to `warn` or `fatal`, `foo/bar` would
suggest using `./foo/bar` instead.
This is useful for improving code readability and making path literals
more explicit.
)"};
)",
};
DeprecatedWarnSetting warnShortPathLiterals{
this,
lintShortPathLiterals,
"lint-short-path-literals",
"warn-short-path-literals",
R"(
Deprecated. Use [`lint-short-path-literals`](#conf-lint-short-path-literals)` = warn` instead.
)",
};
Setting<Diagnose> lintUrlLiterals{
this,
Diagnose::Ignore,
"lint-url-literals",
R"(
Controls handling of unquoted URLs as part of the Nix language syntax.
The Nix language allows for URL literals, like so:
```
$ nix repl
nix-repl> http://foo
"http://foo"
```
Setting this to `warn` or `fatal` will cause the Nix parser to
warn or throw an error when encountering a URL literal:
```
$ nix repl --lint-url-literals fatal
nix-repl> http://foo
error: URL literal 'http://foo' is deprecated
at «string»:1:1:
1| http://foo
| ^
```
Unquoted URLs are being deprecated and their usage is discouraged.
The reason is that, as opposed to path literals, URLs have no
special properties that distinguish them from regular strings, URLs
containing query parameters have to be quoted anyway, and unquoted URLs
may confuse external tooling.
)",
};
Setting<unsigned> bindingsUpdateLayerRhsSizeThreshold{
this,
+19
View File
@@ -603,6 +603,18 @@ public:
parseExprFromString(std::string s, const SourcePath & basePath, const std::shared_ptr<StaticEnv> & staticEnv);
Expr * parseExprFromString(std::string s, const SourcePath & basePath);
/**
* Parse REPL bindings from the specified string.
* Returns ExprAttrs with bindings to add to scope.
*/
ExprAttrs *
parseReplBindings(std::string s, const SourcePath & basePath, const std::shared_ptr<StaticEnv> & staticEnv);
ExprAttrs * parseReplBindings(
std::string s,
std::string errorSource,
const SourcePath & basePath,
const std::shared_ptr<StaticEnv> & staticEnv);
Expr * parseStdin();
/**
@@ -887,6 +899,13 @@ private:
const SourcePath & basePath,
const std::shared_ptr<StaticEnv> & staticEnv);
ExprAttrs * parseReplBindings(
char * text,
size_t length,
Pos::Origin origin,
const SourcePath & basePath,
const std::shared_ptr<StaticEnv> & staticEnv);
/**
* Current Nix call stack depth, used with `max-call-depth` setting to throw stack overflow hopefully before we run
* out of system stack.
+1
View File
@@ -11,6 +11,7 @@ headers = [ config_pub_h ] + files(
'attr-path.hh',
'attr-set.hh',
'counter.hh',
'diagnose.hh',
'eval-cache.hh',
'eval-error.hh',
'eval-gc.hh',
+22
View File
@@ -14,6 +14,7 @@
%x INPATH
%x INPATH_SLASH
%x PATH_START
%x REPL_BINDINGS_MODE
%top {
#include "parser-tab.hh" // YYSTYPE
@@ -113,6 +114,13 @@ URI [a-zA-Z][a-zA-Z0-9\+\-\.]*\:[a-zA-Z0-9\%\/\?\:\@\&\=\+\$\,\-\_\.\!\~
%%
/* REPL bindings mode: inject REPL_BINDINGS token at start, then switch to normal lexing */
<REPL_BINDINGS_MODE>.|\n {
yyless(0);
yylloc->unstash();
POP_STATE();
return REPL_BINDINGS;
}
if { return IF; }
then { return THEN; }
@@ -339,3 +347,17 @@ or { return OR_KW; }
}
%%
#include <type_traits>
// Verify that the forward declaration in parser.y matches flex's definition
static_assert(std::is_same_v<yyscan_t, void *>);
namespace nix {
void setReplBindingsMode(yyscan_t scanner)
{
yy_push_state(REPL_BINDINGS_MODE, scanner);
}
}
+1
View File
@@ -153,6 +153,7 @@ endforeach
sources = files(
'attr-path.cc',
'attr-set.cc',
'diagnose.cc',
'eval-cache.cc',
'eval-error.cc',
'eval-gc.cc',
+94 -11
View File
@@ -30,6 +30,7 @@
#include "nix/expr/nixexpr.hh"
#include "nix/expr/eval.hh"
#include "nix/expr/eval-settings.hh"
#include "nix/expr/diagnose.hh"
#include "nix/expr/parser-state.hh"
#define YY_DECL \
@@ -54,6 +55,11 @@
} \
while (0)
// Forward declaration for flex scanner type.
// lexer-tab.hh is large; avoid including it just for this type.
// Asserted with static_assert in lexer.l.
typedef void * yyscan_t;
namespace nix {
typedef boost::unordered_flat_map<PosIdx, DocComment, std::hash<PosIdx>> DocCommentMap;
@@ -70,6 +76,28 @@ Expr * parseExprFromBuf(
DocCommentMap & docComments,
const ref<SourceAccessor> rootFS);
/**
* Puts the lexer in REPL bindings mode before the first token. This causes
* the parser to accept REPL bindings (attribute definitions).
*/
void setReplBindingsMode(yyscan_t scanner);
/**
* Parse REPL bindings from a buffer.
* Returns ExprAttrs with bindings to add to scope.
*/
ExprAttrs * parseReplBindingsFromBuf(
char * text,
size_t length,
Pos::Origin origin,
const SourcePath & basePath,
Exprs & exprs,
SymbolTable & symbols,
const EvalSettings & settings,
PosTable & positions,
DocCommentMap & docComments,
const ref<SourceAccessor> rootFS);
}
#endif
@@ -175,6 +203,7 @@ static Expr * makeCall(Exprs & exprs, PosIdx pos, Expr * fn, Expr * arg) {
%token IND_STRING_OPEN "start of an indented string"
%token IND_STRING_CLOSE "end of an indented string"
%token ELLIPSIS "'...'"
%token REPL_BINDINGS "start of REPL bindings"
%right IMPL
%left OR
@@ -196,6 +225,10 @@ start: expr {
// This parser does not use yynerrs; suppress the warning.
(void) yynerrs_;
}
| REPL_BINDINGS binds1 {
state->result = $2;
(void) yynerrs_;
};
expr: expr_function;
@@ -337,12 +370,14 @@ expr_simple
state->exprs.add<ExprString>(state->exprs.alloc, path)});
}
| URI {
static bool noURLLiterals = experimentalFeatureSettings.isEnabled(Xp::NoUrlLiterals);
if (noURLLiterals)
throw ParseError({
.msg = HintFmt("URL literals are disabled"),
diagnose(state->settings.lintUrlLiterals, [&](bool fatal) -> std::optional<ParseError> {
return ParseError({
.msg = HintFmt("URL literals are %s. Consider using a string literal \"%s\" instead",
fatal ? "disallowed" : "discouraged",
std::string_view($1.p, $1.l)),
.pos = state->positions[CUR_POS]
});
});
$$ = state->exprs.add<ExprString>(state->exprs.alloc, $1);
}
| '(' expr ')' { $$ = $2; }
@@ -381,14 +416,17 @@ path_start
std::string_view literal({$1.p, $1.l});
/* check for short path literals */
if (state->settings.warnShortPathLiterals && literal.front() != '/' && literal.front() != '.') {
logWarning({
.msg = HintFmt("relative path literal '%s' should be prefixed with '.' for clarity: './%s'. (" ANSI_BOLD "warn-short-path-literals" ANSI_NORMAL " = true)", literal, literal),
.pos = state->positions[CUR_POS]
});
}
diagnose(state->settings.lintShortPathLiterals, [&](bool) -> std::optional<ParseError> {
if (literal.front() != '/' && literal.front() != '.')
return ParseError({
.msg = HintFmt("relative path literal '%s' should be prefixed with '.' for clarity: './%s'", literal, literal),
.pos = state->positions[CUR_POS]
});
return std::nullopt;
});
Path path(absPath(literal, state->basePath.path.abs()));
auto basePath = std::filesystem::path(state->basePath.path.abs());
Path path(absPath(literal, &basePath).string());
/* add back in the trailing '/' to the first segment */
if (literal.size() > 1 && literal.back() == '/')
path += '/';
@@ -577,6 +615,51 @@ Expr * parseExprFromBuf(
return state.result;
}
ExprAttrs * parseReplBindingsFromBuf(
char * text,
size_t length,
Pos::Origin origin,
const SourcePath & basePath,
Exprs & exprs,
SymbolTable & symbols,
const EvalSettings & settings,
PosTable & positions,
DocCommentMap & docComments,
const ref<SourceAccessor> rootFS)
{
yyscan_t scanner;
LexerState lexerState {
.positionToDocComment = docComments,
.positions = positions,
.origin = positions.addOrigin(origin, length),
};
ParserState state {
.lexerState = lexerState,
.exprs = exprs,
.symbols = symbols,
.positions = positions,
.basePath = basePath,
.origin = lexerState.origin,
.rootFS = rootFS,
.settings = settings,
};
yylex_init_extra(&lexerState, &scanner);
Finally _destroy([&] { yylex_destroy(scanner); });
yy_scan_buffer(text, length, scanner);
setReplBindingsMode(scanner);
Parser parser(scanner, &state);
parser.parse();
assert(state.result);
// state.result is Expr *, but the REPL_BINDINGS grammar rule
// always produces an ExprAttrs via the binds1 production.
auto bindings = dynamic_cast<ExprAttrs *>(state.result);
assert(bindings);
return bindings;
}
}
#pragma GCC diagnostic pop // end ignored "-Wswitch-enum"
+1 -1
View File
@@ -12,7 +12,7 @@ SourcePath EvalState::rootPath(CanonPath path)
SourcePath EvalState::rootPath(PathView path)
{
return {rootFS, CanonPath(absPath(path))};
return {rootFS, CanonPath(absPath(path).string())};
}
SourcePath EvalState::storePath(const StorePath & path)
+6 -5
View File
@@ -11,6 +11,7 @@
#include "nix/store/path-references.hh"
#include "nix/store/store-api.hh"
#include "nix/util/util.hh"
#include "nix/util/os-string.hh"
#include "nix/util/processes.hh"
#include "nix/expr/value-to-json.hh"
#include "nix/expr/value-to-xml.hh"
@@ -74,7 +75,7 @@ StringMap EvalState::realiseContext(const NixStringContext & context, StorePathS
for (auto & c : context) {
auto ensureValid = [&](const StorePath & p) {
if (!store->isValidPath(p))
error<InvalidPathError>(store->printStorePath(p)).debugThrow();
error<InvalidPathError>(p).debugThrow();
};
std::visit(
overloaded{
@@ -503,12 +504,12 @@ void prim_exec(EvalState & state, const PosIdx pos, Value ** args, Value & v)
try {
auto _ = state.realiseContext(context); // FIXME: Handle CA derivations
} catch (InvalidPathError & e) {
state.error<EvalError>("cannot execute '%1%', since path '%2%' is not valid", program, e.path)
state.error<EvalError>("cannot execute '%1%', since store path '%2%' is not valid", program, e.path.to_string())
.atPos(pos)
.debugThrow();
}
auto output = runProgram(program, true, commandArgs);
auto output = runProgram(program, true, toOsStrings(std::move(commandArgs)));
Expr * parsed;
try {
parsed = state.parseExprFromString(std::move(output), state.rootPath(CanonPath::root));
@@ -1933,7 +1934,7 @@ static void prim_storePath(EvalState & state, const PosIdx pos, Value ** args, V
directly in the store. The latter condition is necessary so
e.g. nix-push does the right thing. */
if (!state.store->isStorePath(path.abs()))
path = CanonPath(canonPath(path.abs(), true));
path = CanonPath(canonPath(path.abs(), true).string());
if (!state.store->isInStore(path.abs()))
state.error<EvalError>("path '%1%' is not in the Nix store", path).atPos(pos).debugThrow();
auto path2 = state.store->toStorePath(path.abs()).first;
@@ -2154,7 +2155,7 @@ static void prim_findFile(EvalState & state, const PosIdx pos, Value ** args, Va
auto rewrites = state.realiseContext(context);
path = rewriteStrings(std::move(path), rewrites);
} catch (InvalidPathError & e) {
state.error<EvalError>("cannot find '%1%', since path '%2%' is not valid", path, e.path)
state.error<EvalError>("cannot find '%1%', since path '%2%' is not valid", path, e.path.to_string())
.atPos(pos)
.debugThrow();
}
+4 -1
View File
@@ -161,7 +161,7 @@ bool Input::isFinal() const
return maybeGetBoolAttr(attrs, "__final").value_or(false);
}
std::optional<std::string> Input::isRelative() const
std::optional<std::filesystem::path> Input::isRelative() const
{
assert(scheme);
return scheme->isRelative(*this);
@@ -236,6 +236,9 @@ void Input::checkLocks(Input specified, Input & result)
if (auto prevNarHash = specified.getNarHash())
specified.attrs.insert_or_assign("narHash", prevNarHash->to_string(HashFormat::SRI, true));
if (auto narHash = result.getNarHash())
result.attrs.insert_or_assign("narHash", narHash->to_string(HashFormat::SRI, true));
for (auto & field : specified.attrs) {
auto field2 = result.attrs.find(field.first);
if (field2 != result.attrs.end() && field.second != field2->second)
+12 -7
View File
@@ -1,9 +1,11 @@
#include "nix/fetchers/git-lfs-fetch.hh"
#include "nix/fetchers/git-utils.hh"
#include "nix/store/filetransfer.hh"
#include "nix/util/os-string.hh"
#include "nix/util/processes.hh"
#include "nix/util/url.hh"
#include "nix/util/users.hh"
#include "nix/util/util.hh"
#include "nix/util/hash.hh"
#include "nix/store/ssh.hh"
@@ -59,24 +61,27 @@ static LfsApiInfo getLfsApi(const ParsedURL & url)
auto args = getNixSshOpts();
if (url.authority->port)
args.push_back(fmt("-p%d", *url.authority->port));
args.push_back(string_to_os_string(fmt("-p%d", *url.authority->port)));
std::ostringstream hostnameAndUser;
if (url.authority->user)
hostnameAndUser << *url.authority->user << "@";
hostnameAndUser << url.authority->host;
args.push_back(std::move(hostnameAndUser).str());
args.push_back(string_to_os_string(std::move(hostnameAndUser).str()));
args.push_back("--");
args.push_back("git-lfs-authenticate");
args.push_back(OS_STR("--"));
args.push_back(OS_STR("git-lfs-authenticate"));
// FIXME %2F encode slashes? Does this command take/accept percent encoding?
args.push_back(url.renderPath(/*encode=*/false));
args.push_back("download");
args.push_back(string_to_os_string(url.renderPath(/*encode=*/false)));
args.push_back(OS_STR("download"));
auto [status, output] = runProgram({.program = "ssh", .args = args});
if (output.empty())
throw Error("git-lfs-authenticate: no output (cmd: 'ssh %s')", concatStringsSep(" ", args));
throw Error(
"git-lfs-authenticate: no output (cmd: 'ssh %s')",
concatMapStringsSep(
" ", args, [](const OsString & s) { return escapeShellArgAlways(os_string_to_string(s)); }));
auto queryResp = nlohmann::json::parse(output);
auto headerIt = queryResp.find("header");
+30 -17
View File
@@ -4,6 +4,7 @@
#include "nix/fetchers/fetch-settings.hh"
#include "nix/util/base-n.hh"
#include "nix/util/finally.hh"
#include "nix/util/os-string.hh"
#include "nix/util/processes.hh"
#include "nix/util/signals.hh"
#include "nix/util/users.hh"
@@ -637,12 +638,24 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
// then use code that was removed in this commit (see blame)
auto dir = this->path;
Strings gitArgs{"-C", dir.string(), "--git-dir", ".", "fetch", "--progress", "--force"};
if (shallow)
append(gitArgs, {"--depth", "1"});
append(gitArgs, {std::string("--"), url, refspec});
OsStrings gitArgs = {
OS_STR("-C"),
dir.native(),
OS_STR("--git-dir"),
OS_STR("."),
OS_STR("fetch"),
OS_STR("--progress"),
OS_STR("--force"),
};
if (shallow) {
gitArgs.push_back(OS_STR("--depth"));
gitArgs.push_back(OS_STR("1"));
}
gitArgs.push_back(OS_STR("--"));
gitArgs.push_back(string_to_os_string(url));
gitArgs.push_back(string_to_os_string(refspec));
auto status = runProgram(RunOptions{.program = "git", .args = gitArgs, .isInteractive = true}).first;
auto status = runProgram({.program = "git", .args = gitArgs, .isInteractive = true}).first;
if (status > 0)
throw Error("Failed to fetch git repository '%s'", url);
@@ -682,18 +695,18 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
writeFile(allowedSignersFile, allowedSigners);
// Run verification command
auto [status, output] = runProgram(
RunOptions{
.program = "git",
.args =
{"-c",
"gpg.ssh.allowedSignersFile=" + allowedSignersFile,
"-C",
path.string(),
"verify-commit",
rev.gitRev()},
.mergeStderrToStdout = true,
});
auto [status, output] = runProgram({
.program = "git",
.args{
OS_STR("-c"),
OS_STR("gpg.ssh.allowedSignersFile=") + allowedSignersFile.native(),
OS_STR("-C"),
path.native(),
OS_STR("verify-commit"),
string_to_os_string(rev.gitRev()),
},
.mergeStderrToStdout = true,
});
/* Evaluate result through status code and checking if public
key fingerprints appear on stderr. This is necessary
+55 -35
View File
@@ -7,6 +7,7 @@
#include "nix/store/store-api.hh"
#include "nix/util/url-parts.hh"
#include "nix/store/pathlocks.hh"
#include "nix/util/os-string.hh"
#include "nix/util/processes.hh"
#include "nix/util/git.hh"
#include "nix/fetchers/git-utils.hh"
@@ -62,7 +63,7 @@ std::optional<std::string> readHead(const std::filesystem::path & path)
RunOptions{
.program = "git",
// FIXME: use 'HEAD' to avoid returning all refs
.args = {"ls-remote", "--symref", path.string()},
.args = {OS_STR("ls-remote"), OS_STR("--symref"), path.native()},
.isInteractive = true,
});
if (status != 0)
@@ -89,7 +90,19 @@ bool storeCachedHead(const std::string & actualUrl, bool shallow, const std::str
{
std::filesystem::path cacheDir = getCachePath(actualUrl, shallow);
try {
runProgram("git", true, {"-C", cacheDir.string(), "--git-dir", ".", "symbolic-ref", "--", "HEAD", headRef});
runProgram(
"git",
true,
{
OS_STR("-C"),
cacheDir.native(),
OS_STR("--git-dir"),
OS_STR("."),
OS_STR("symbolic-ref"),
OS_STR("--"),
OS_STR("HEAD"),
string_to_os_string(headRef),
});
} catch (ExecError & e) {
if (
#ifndef WIN32 // TODO abstract over exit status handling on Windows
@@ -439,19 +452,19 @@ struct GitInputScheme : InputScheme
{
auto repoInfo = getRepoInfo(input);
Strings args = {"clone"};
OsStrings args = {OS_STR("clone")};
args.push_back(repoInfo.locationToArg());
args.push_back(string_to_os_string(repoInfo.locationToArg()));
if (auto ref = input.getRef()) {
args.push_back("--branch");
args.push_back(*ref);
args.push_back(OS_STR("--branch"));
args.push_back(string_to_os_string(*ref));
}
if (input.getRev())
throw UnimplementedError("cloning a specific revision is not implemented");
args.push_back(destDir.string());
args.push_back(destDir.native());
runProgram("git", true, args, {}, true);
}
@@ -478,14 +491,15 @@ struct GitInputScheme : InputScheme
auto result = runProgram(
RunOptions{
.program = "git",
.args =
{"-C",
repoPath->string(),
"--git-dir",
repoInfo.gitDir,
"check-ignore",
"--quiet",
std::string(path.rel())},
.args{
OS_STR("-C"),
repoPath->native(),
OS_STR("--git-dir"),
string_to_os_string(repoInfo.gitDir),
OS_STR("check-ignore"),
OS_STR("--quiet"),
string_to_os_string(std::string(path.rel())),
},
});
auto exitCode =
#ifndef WIN32 // TODO abstract over exit status handling on Windows
@@ -500,14 +514,16 @@ struct GitInputScheme : InputScheme
runProgram(
"git",
true,
{"-C",
repoPath->string(),
"--git-dir",
repoInfo.gitDir,
"add",
"--intent-to-add",
"--",
std::string(path.rel())});
{
OS_STR("-C"),
repoPath->native(),
OS_STR("--git-dir"),
string_to_os_string(repoInfo.gitDir),
OS_STR("add"),
OS_STR("--intent-to-add"),
OS_STR("--"),
string_to_os_string(std::string(path.rel())),
});
if (commitMsg) {
// Pause the logger to allow for user input (such as a gpg passphrase) in `git commit`
@@ -515,14 +531,16 @@ struct GitInputScheme : InputScheme
runProgram(
"git",
true,
{"-C",
repoPath->string(),
"--git-dir",
repoInfo.gitDir,
"commit",
std::string(path.rel()),
"-F",
"-"},
{
OS_STR("-C"),
repoPath->native(),
OS_STR("--git-dir"),
string_to_os_string(repoInfo.gitDir),
OS_STR("commit"),
string_to_os_string(std::string(path.rel())),
OS_STR("-F"),
OS_STR("-"),
},
*commitMsg);
}
}
@@ -627,10 +645,12 @@ struct GitInputScheme : InputScheme
//
// See: https://discourse.nixos.org/t/57783 and #9708
//
if (url.scheme == "file" && !forceHttp && !isBareRepository(renderUrlPathEnsureLegal(url.path))) {
auto path = renderUrlPathEnsureLegal(url.path);
auto maybeUrlFsPathForFileUrl =
url.scheme == "file" ? std::make_optional(urlPathToPath(url.path)) : std::nullopt;
if (maybeUrlFsPathForFileUrl && !forceHttp && !isBareRepository(maybeUrlFsPathForFileUrl->string())) {
auto & path = *maybeUrlFsPathForFileUrl;
if (!isAbsolute(path)) {
if (!path.is_absolute()) {
warn(
"Fetching Git repository '%s', which uses a path relative to the current directory. "
"This is not supported and will stop working in a future release. "
@@ -640,7 +660,7 @@ struct GitInputScheme : InputScheme
repoInfo.location = std::filesystem::absolute(path);
} else {
if (url.scheme == "file")
if (maybeUrlFsPathForFileUrl)
/* Query parameters are meaningless for file://, but
Git interprets them as part of the file name. So get
rid of them. */
@@ -86,7 +86,7 @@ public:
* Only for relative path flakes, i.e. 'path:./foo', returns the
* relative path, i.e. './foo'.
*/
std::optional<std::string> isRelative() const;
std::optional<std::filesystem::path> isRelative() const;
/**
* Return whether this is a "final" input, meaning that fetching
@@ -263,7 +263,7 @@ struct InputScheme
return false;
}
virtual std::optional<std::string> isRelative(const Input & input) const
virtual std::optional<std::filesystem::path> isRelative(const Input & input) const
{
return std::nullopt;
}
@@ -6,6 +6,7 @@
#include "nix/store/path.hh"
#include "nix/util/ref.hh"
#include "nix/util/types.hh"
#include "nix/util/url.hh"
namespace nix {
class Store;
@@ -27,7 +28,7 @@ struct DownloadFileResult
DownloadFileResult downloadFile(
Store & store,
const Settings & settings,
const std::string & url,
const VerbatimURL & url,
const std::string & name,
const Headers & headers = {});
+102 -53
View File
@@ -1,5 +1,9 @@
#include "nix/fetchers/fetchers.hh"
#include "nix/util/file-system.hh"
#include "nix/util/fmt.hh"
#include "nix/util/os-string.hh"
#include "nix/util/processes.hh"
#include "nix/util/util.hh"
#include "nix/util/environment-variables.hh"
#include "nix/util/users.hh"
#include "nix/fetchers/cache.hh"
@@ -10,24 +14,25 @@
#include "nix/fetchers/fetch-settings.hh"
#include <sys/time.h>
#include <variant>
using namespace std::string_literals;
namespace nix::fetchers {
static RunOptions hgOptions(const Strings & args)
static RunOptions hgOptions(OsStrings args)
{
auto env = getEnvOs();
// Set HGPLAIN: this means we get consistent output from hg and avoids leakage from a user or system .hgrc.
env[OS_STR("HGPLAIN")] = OS_STR("");
return {.program = "hg", .lookupPath = true, .args = args, .environment = env};
return {.program = "hg", .lookupPath = true, .args = std::move(args), .environment = env};
}
// runProgram wrapper that uses hgOptions instead of stock RunOptions.
static std::string runHg(const Strings & args, const std::optional<std::string> & input = {})
static std::string runHg(OsStrings args, const std::optional<std::string> & input = {})
{
RunOptions opts = hgOptions(args);
RunOptions opts = hgOptions(std::move(args));
opts.input = input;
auto res = runProgram(std::move(opts));
@@ -145,7 +150,7 @@ struct MercurialInputScheme : InputScheme
{
auto url = parseURL(getStrAttr(input.attrs, "url"));
if (url.scheme == "file" && !input.getRef() && !input.getRev())
return renderUrlPathEnsureLegal(url.path);
return urlPathToPath(url.path);
return {};
}
@@ -155,29 +160,36 @@ struct MercurialInputScheme : InputScheme
std::string_view contents,
std::optional<std::string> commitMsg) const override
{
auto [isLocal, repoPath] = getActualUrl(input);
if (!isLocal)
throw Error(
"cannot commit '%s' to Mercurial repository '%s' because it's not a working tree",
path,
input.to_string());
std::visit(
overloaded{
[&](const std::filesystem::path & repoPath) {
auto absPath = repoPath / path.rel();
auto absPath = CanonPath(repoPath) / path;
writeFile(absPath, contents);
writeFile(absPath.abs(), contents);
// FIXME: shut up if file is already tracked.
runHg({OS_STR("add"), absPath.native()});
// FIXME: shut up if file is already tracked.
runHg({"add", absPath.abs()});
if (commitMsg)
runHg({"commit", absPath.abs(), "-m", *commitMsg});
if (commitMsg)
runHg({OS_STR("commit"), absPath.native(), OS_STR("-m"), string_to_os_string(*commitMsg)});
},
[&](const std::string &) {
throw Error(
"cannot commit '%s' to Mercurial repository '%s' because it's not a working tree",
path,
input.to_string());
},
},
getActualUrl(input));
}
std::pair<bool, std::string> getActualUrl(const Input & input) const
std::variant<std::filesystem::path, std::string> getActualUrl(const Input & input) const
{
auto url = parseURL(getStrAttr(input.attrs, "url"));
bool isLocal = url.scheme == "file";
return {isLocal, isLocal ? renderUrlPathEnsureLegal(url.path) : url.to_string()};
if (url.scheme == "file")
return urlPathToPath(url.path);
else
return url.to_string();
}
StorePath fetchToStore(const Settings & settings, Store & store, Input & input) const
@@ -186,35 +198,52 @@ struct MercurialInputScheme : InputScheme
auto name = input.getName();
auto [isLocal, actualUrl_] = getActualUrl(input);
auto actualUrl = actualUrl_; // work around clang bug
auto actualUrl_ = getActualUrl(input);
// FIXME: return lastModified.
// FIXME: don't clone local repositories.
if (!input.getRef() && !input.getRev() && isLocal && pathExists(actualUrl + "/.hg")) {
bool clean = runHg({"status", "-R", actualUrl, "--modified", "--added", "--removed"}) == "";
if (!clean) {
if (auto * localPathP = std::get_if<std::filesystem::path>(&actualUrl_)) {
auto & localPath = *localPathP;
auto unlocked = !input.getRef() && !input.getRev();
auto isValidLocalRepo = pathExists(localPath / ".hg");
// short circuiting to not bother checking if locked / no repo is important.
bool dirty = unlocked && isValidLocalRepo
&& runHg({
OS_STR("status"),
OS_STR("-R"),
localPath.native(),
OS_STR("--modified"),
OS_STR("--added"),
OS_STR("--removed"),
}) != "";
if (dirty) {
/* This is an unclean working tree. So copy all tracked
files. */
if (!settings.allowDirty)
throw Error("Mercurial tree '%s' is unclean", actualUrl);
throw Error("Mercurial tree '%s' is unclean", PathFmt{localPath});
if (settings.warnDirty)
warn("Mercurial tree '%s' is unclean", actualUrl);
warn("Mercurial tree '%s' is unclean", PathFmt{localPath});
input.attrs.insert_or_assign("ref", chomp(runHg({"branch", "-R", actualUrl})));
input.attrs.insert_or_assign("ref", chomp(runHg({OS_STR("branch"), OS_STR("-R"), localPath.native()})));
auto files = tokenizeString<StringSet>(
runHg({"status", "-R", actualUrl, "--clean", "--modified", "--added", "--no-status", "--print0"}),
runHg({
OS_STR("status"),
OS_STR("-R"),
localPath.native(),
OS_STR("--clean"),
OS_STR("--modified"),
OS_STR("--added"),
OS_STR("--no-status"),
OS_STR("--print0"),
}),
"\0"s);
std::filesystem::path actualPath(absPath(actualUrl));
auto actualPath = absPath(localPath);
PathFilter filter = [&](const Path & p) -> bool {
assert(hasPrefix(p, actualPath.string()));
@@ -231,18 +260,23 @@ struct MercurialInputScheme : InputScheme
return files.count(file);
};
auto storePath = store.addToStore(
return store.addToStore(
input.getName(),
{getFSSourceAccessor(), CanonPath(actualPath.string())},
ContentAddressMethod::Raw::NixArchive,
HashAlgorithm::SHA256,
{},
filter);
return storePath;
}
}
auto [actualUrl, actualUrlOs] = std::visit(
overloaded{
[&](const std::filesystem::path & p) { return std::make_pair(p.string(), p.native()); },
[&](const std::string & s) { return std::make_pair(s, string_to_os_string(s)); },
},
actualUrl_);
if (!input.getRef())
input.attrs.insert_or_assign("ref", "default");
@@ -282,40 +316,48 @@ struct MercurialInputScheme : InputScheme
/* If this is a commit hash that we already have, we don't
have to pull again. */
if (!(input.getRev() && pathExists(cacheDir)
&& runProgram(
hgOptions({"log", "-R", cacheDir.string(), "-r", input.getRev()->gitRev(), "--template", "1"}))
&& runProgram(hgOptions({
OS_STR("log"),
OS_STR("-R"),
cacheDir.native(),
OS_STR("-r"),
string_to_os_string(input.getRev()->gitRev()),
OS_STR("--template"),
OS_STR("1"),
}))
.second
== "1")) {
Activity act(*logger, lvlTalkative, actUnknown, fmt("fetching Mercurial repository '%s'", actualUrl));
if (pathExists(cacheDir)) {
try {
runHg({"pull", "-R", cacheDir.string(), "--", actualUrl});
runHg({OS_STR("pull"), OS_STR("-R"), cacheDir.native(), OS_STR("--"), actualUrlOs});
} catch (ExecError & e) {
auto transJournal = cacheDir / ".hg" / "store" / "journal";
/* hg throws "abandoned transaction" error only if this file exists */
if (pathExists(transJournal)) {
runHg({"recover", "-R", cacheDir.string()});
runHg({"pull", "-R", cacheDir.string(), "--", actualUrl});
runHg({OS_STR("recover"), OS_STR("-R"), cacheDir.native()});
runHg({OS_STR("pull"), OS_STR("-R"), cacheDir.native(), OS_STR("--"), actualUrlOs});
} else {
throw ExecError(e.status, "'hg pull' %s", statusToString(e.status));
}
}
} else {
createDirs(dirOf(cacheDir.string()));
runHg({"clone", "--noupdate", "--", actualUrl, cacheDir.string()});
createDirs(cacheDir.parent_path());
runHg({OS_STR("clone"), OS_STR("--noupdate"), OS_STR("--"), actualUrlOs, cacheDir.native()});
}
}
/* Fetch the remote rev or ref. */
auto tokens = tokenizeString<std::vector<std::string>>(runHg(
{"log",
"-R",
cacheDir.string(),
"-r",
input.getRev() ? input.getRev()->gitRev() : *input.getRef(),
"--template",
"{node} {rev} {branch}"}));
auto tokens = tokenizeString<std::vector<std::string>>(runHg({
OS_STR("log"),
OS_STR("-R"),
cacheDir.native(),
OS_STR("-r"),
string_to_os_string(input.getRev() ? input.getRev()->gitRev() : *input.getRef()),
OS_STR("--template"),
OS_STR("{node} {rev} {branch}"),
}));
assert(tokens.size() == 3);
auto rev = Hash::parseAny(tokens[0], HashAlgorithm::SHA1);
@@ -331,7 +373,14 @@ struct MercurialInputScheme : InputScheme
std::filesystem::path tmpDir = createTempDir();
AutoDelete delTmpDir(tmpDir, true);
runHg({"archive", "-R", cacheDir.string(), "-r", rev.gitRev(), tmpDir.string()});
runHg({
OS_STR("archive"),
OS_STR("-R"),
cacheDir.native(),
OS_STR("-r"),
string_to_os_string(rev.gitRev()),
tmpDir.native(),
});
deletePath(tmpDir / ".hg_archival.txt");
+6 -6
View File
@@ -19,7 +19,7 @@ struct PathInputScheme : InputScheme
Input input{};
input.attrs.insert_or_assign("type", "path");
input.attrs.insert_or_assign("path", renderUrlPathEnsureLegal(url.path));
input.attrs.insert_or_assign("path", urlPathToPath(url.path).string());
for (auto & [name, value] : url.query)
if (name == "rev" || name == "narHash")
@@ -114,10 +114,10 @@ struct PathInputScheme : InputScheme
writeFile(getAbsPath(input) / path.rel(), contents);
}
std::optional<std::string> isRelative(const Input & input) const override
std::optional<std::filesystem::path> isRelative(const Input & input) const override
{
auto path = getStrAttr(input.attrs, "path");
if (isAbsolute(path))
std::filesystem::path path = getStrAttr(input.attrs, "path");
if (path.is_absolute())
return std::nullopt;
else
return path;
@@ -130,9 +130,9 @@ struct PathInputScheme : InputScheme
std::filesystem::path getAbsPath(const Input & input) const
{
auto path = getStrAttr(input.attrs, "path");
std::filesystem::path path = getStrAttr(input.attrs, "path");
if (isAbsolute(path))
if (path.is_absolute())
return canonPath(path);
throw Error("cannot fetch input '%s' because it uses a relative path", input.to_string());
+3 -2
View File
@@ -147,13 +147,14 @@ static std::shared_ptr<Registry> getGlobalRegistry(const Settings & settings, St
return Registry::read(
settings,
[&] -> SourcePath {
if (!isAbsolute(path)) {
std::filesystem::path fsPath{path};
if (!fsPath.is_absolute()) {
auto storePath = downloadFile(store, settings, path, "flake-registry.json").storePath;
if (auto store2 = dynamic_cast<LocalFSStore *>(&store))
store2->addPermRoot(storePath, (getCacheDir() / "flake-registry.json").string());
return {store.requireStoreObjectAccessor(storePath)};
} else {
return SourcePath{getFSSourceAccessor(), CanonPath{path}}.resolveSymlinks();
return SourcePath{getFSSourceAccessor(), CanonPath{fsPath.string()}}.resolveSymlinks();
}
}(),
Registry::Global);
+5 -5
View File
@@ -15,7 +15,7 @@ namespace nix::fetchers {
DownloadFileResult downloadFile(
Store & store,
const Settings & settings,
const std::string & url,
const VerbatimURL & url,
const std::string & name,
const Headers & headers)
{
@@ -24,7 +24,7 @@ DownloadFileResult downloadFile(
Cache::Key key{
"file",
{{
{"url", url},
{"url", url.to_string()},
{"name", name},
}}};
@@ -42,7 +42,7 @@ DownloadFileResult downloadFile(
if (cached && !cached->expired)
return useCached();
FileTransferRequest request(VerbatimURL{url});
FileTransferRequest request(url);
request.headers = headers;
if (cached)
request.expectedETag = getStrAttr(cached->value, "etag");
@@ -113,7 +113,7 @@ static DownloadTarballResult downloadTarball_(
// Namely lets catch when the url is a local file path, but
// it is not in fact a tarball.
if (url.scheme == "file") {
std::filesystem::path localPath = renderUrlPathEnsureLegal(url.path);
std::filesystem::path localPath = urlPathToPath(url.path);
if (!localPath.is_absolute()) {
throw Error(
"tarball '%s' must use an absolute path. "
@@ -179,7 +179,7 @@ static DownloadTarballResult downloadTarball_(
auto [fdTemp, path] = createTempFile("nix-zipfile");
cleanupTemp.cancel();
cleanupTemp = {path};
debug("downloading '%s' into '%s'...", url, path);
debug("downloading '%s' into %s...", url, PathFmt(path));
{
FdSink sink(fdTemp.get());
source->drainInto(sink);
+1 -1
View File
@@ -13,7 +13,7 @@ struct nix_flake_settings
struct nix_flake_reference_parse_flags
{
std::optional<nix::Path> baseDirectory;
std::optional<std::filesystem::path> baseDirectory;
};
struct nix_flake_reference
+1 -1
View File
@@ -596,7 +596,7 @@ lockFlake(const Settings & settings, EvalState & state, const FlakeRef & topRef,
if (auto relativePath = input.ref->input.isRelative()) {
return SourcePath{
overriddenSourcePath.accessor,
CanonPath(*relativePath, overriddenSourcePath.path.parent().value())};
CanonPath(relativePath->string(), overriddenSourcePath.path.parent().value())};
} else
return std::nullopt;
};
+32 -30
View File
@@ -112,7 +112,7 @@ std::pair<FlakeRef, std::string> parsePathFlakeRefWithFragment(
auto succeeds = std::regex_match(url, match, pathFlakeRegex);
if (!succeeds)
throw Error("invalid flakeref '%s'", url);
auto path = match[1].str();
std::filesystem::path path = match[1].str();
auto query = decodeQuery(match[3].str(), /*lenient=*/true);
auto fragment = percentDecode(match[5].str());
@@ -121,60 +121,62 @@ std::pair<FlakeRef, std::string> parsePathFlakeRefWithFragment(
to 'baseDir'). If so, search upward to the root of the
repo (i.e. the directory containing .git). */
path = absPath(path, baseDir->string(), true);
path = absPath(path, get(baseDir), true);
if (isFlake) {
if (!S_ISDIR(lstat(path).st_mode)) {
if (baseNameOf(path) == "flake.nix") {
if (path.filename() == "flake.nix") {
// Be gentle with people who accidentally write `/foo/bar/flake.nix` instead of `/foo/bar`
auto parentPath = path.parent_path();
warn(
"Path '%s' should point at the directory containing the 'flake.nix' file, not the file itself. "
"Pretending that you meant '%s'",
path,
dirOf(path));
path = dirOf(path);
"Path %s should point at the directory containing the 'flake.nix' file, not the file itself. "
"Pretending that you meant %s",
PathFmt(path),
PathFmt(parentPath));
path = parentPath;
} else {
throw BadURL("path '%s' is not a flake (because it's not a directory)", path);
throw BadURL("path %s is not a flake (because it's not a directory)", PathFmt(path));
}
}
if (!allowMissing && !pathExists(path + "/flake.nix")) {
notice("path '%s' does not contain a 'flake.nix', searching up", path);
if (!allowMissing && !pathExists(path / "flake.nix")) {
notice("path %s does not contain a 'flake.nix', searching up", PathFmt(path));
// Save device to detect filesystem boundary
dev_t device = lstat(path).st_dev;
bool found = false;
while (path != "/") {
if (pathExists(path + "/flake.nix")) {
if (pathExists(path / "flake.nix")) {
found = true;
break;
} else if (pathExists(path + "/.git"))
} else if (pathExists(path / ".git"))
throw Error(
"path '%s' is not part of a flake (neither it nor its parent directories contain a 'flake.nix' file)",
path);
"path %s is not part of a flake (neither it nor its parent directories contain a 'flake.nix' file)",
PathFmt(path));
else {
if (lstat(path).st_dev != device)
throw Error("unable to find a flake before encountering filesystem boundary at '%s'", path);
throw Error(
"unable to find a flake before encountering filesystem boundary at %s", PathFmt(path));
}
path = dirOf(path);
path = path.parent_path();
}
if (!found)
throw BadURL("could not find a flake.nix file");
}
if (!allowMissing && !pathExists(path + "/flake.nix"))
throw BadURL("path '%s' is not a flake (because it doesn't contain a 'flake.nix' file)", path);
if (!allowMissing && !pathExists(path / "flake.nix"))
throw BadURL("path %s is not a flake (because it doesn't contain a 'flake.nix' file)", PathFmt(path));
auto flakeRoot = path;
std::string subdir;
while (flakeRoot != "/") {
if (pathExists(flakeRoot + "/.git")) {
if (pathExists(flakeRoot / ".git")) {
auto parsedURL = ParsedURL{
.scheme = "git+file",
.authority = ParsedURL::Authority{},
.path = splitString<std::vector<std::string>>(flakeRoot, "/"),
.path = pathToUrlPath(flakeRoot),
.query = query,
.fragment = fragment,
};
@@ -185,19 +187,19 @@ std::pair<FlakeRef, std::string> parsePathFlakeRefWithFragment(
parsedURL.query.insert_or_assign("dir", subdir);
}
if (pathExists(flakeRoot + "/.git/shallow"))
if (pathExists(flakeRoot / ".git" / "shallow"))
parsedURL.query.insert_or_assign("shallow", "1");
return fromParsedURL(fetchSettings, std::move(parsedURL), isFlake);
}
subdir = std::string(baseNameOf(flakeRoot)) + (subdir.empty() ? "" : "/" + subdir);
flakeRoot = dirOf(flakeRoot);
subdir = flakeRoot.filename().string() + (subdir.empty() ? "" : "/" + subdir);
flakeRoot = flakeRoot.parent_path();
}
}
} else {
if (!preserveRelativePaths && !isAbsolute(path))
if (!preserveRelativePaths && !path.is_absolute())
throw BadURL("flake reference '%s' is not an absolute path", url);
}
@@ -205,8 +207,8 @@ std::pair<FlakeRef, std::string> parsePathFlakeRefWithFragment(
fetchSettings,
{
.scheme = "path",
.authority = isAbsolute(path) ? std::optional{ParsedURL::Authority{}} : std::nullopt,
.path = splitString<std::vector<std::string>>(path, "/"),
.authority = path.is_absolute() ? std::optional{ParsedURL::Authority{}} : std::nullopt,
.path = pathToUrlPath(path),
.query = query,
.fragment = fragment,
},
@@ -250,9 +252,9 @@ std::optional<std::pair<FlakeRef, std::string>> parseURLFlakeRef(
auto parsed = parseURL(url, /*lenient=*/true);
if (baseDir && (parsed.scheme == "path" || parsed.scheme == "git+file")) {
/* Here we know that the path must not contain encoded '/' or NUL bytes. */
auto path = renderUrlPathEnsureLegal(parsed.path);
if (!isAbsolute(path))
parsed.path = splitString<std::vector<std::string>>(absPath(path, baseDir->string()), "/");
auto path = urlPathToPath(parsed.path);
if (!path.is_absolute())
parsed.path = pathToUrlPath(absPath(path, get(baseDir)));
}
return fromParsedURL(fetchSettings, std::move(parsed), isFlake);
} catch (BadURL &) {
+1 -1
View File
@@ -116,7 +116,7 @@ nix_err nix_store_real_path(
context->last_err_code = NIX_OK;
try {
auto store2 = store->ptr.dynamic_pointer_cast<nix::LocalFSStore>();
auto res = store2 ? store2->toRealPath(path->path) : store->ptr->printStorePath(path->path);
auto res = store2 ? store2->toRealPath(path->path).string() : store->ptr->printStorePath(path->path);
return call_nix_get_string_callback(res, callback, user_data);
}
NIXC_CATCH_ERRS
+3 -3
View File
@@ -1,4 +1,5 @@
#include "nix/store/tests/https-store.hh"
#include "nix/util/os-string.hh"
#include <thread>
@@ -21,7 +22,7 @@ ref<TestHttpBinaryCacheStore> TestHttpBinaryCacheStoreConfig::openTestStore(ref<
void HttpsBinaryCacheStoreTest::openssl(Strings args)
{
runProgram("openssl", /*lookupPath=*/true, args);
runProgram("openssl", /*lookupPath=*/true, toOsStrings(std::move(args)));
}
void HttpsBinaryCacheStoreTest::SetUp()
@@ -37,8 +38,7 @@ void HttpsBinaryCacheStoreTest::SetUp()
delTmpDir = std::make_unique<AutoDelete>(tmpDir);
localCacheStore =
make_ref<LocalBinaryCacheStoreConfig>("file", cacheDir.string(), LocalBinaryCacheStoreConfig::Params{})
->openStore();
make_ref<LocalBinaryCacheStoreConfig>(cacheDir, LocalBinaryCacheStoreConfig::Params{})->openStore();
caCert = tmpDir / "ca.crt";
caKey = tmpDir / "ca.key";
@@ -50,8 +50,7 @@ protected:
#else
// resolve any symlinks in i.e. on macOS /tmp -> /private/tmp
// because this is not allowed for a nix store.
auto tmpl =
nix::absPath(std::filesystem::path(nix::defaultTempDir()) / "tests_nix-store.XXXXXX", std::nullopt, true);
auto tmpl = nix::absPath(nix::defaultTempDir() / "tests_nix-store.XXXXXX", nullptr, true);
nixDir = mkdtemp((char *) tmpl.c_str());
#endif
+12 -5
View File
@@ -7,24 +7,31 @@
namespace nix {
using Authority = ParsedURL::Authority;
TEST(HttpBinaryCacheStore, constructConfig)
{
HttpBinaryCacheStoreConfig config{"http", "foo.bar.baz", {}};
HttpBinaryCacheStoreConfig config{
{
.scheme = "http",
.authority = Authority{.host = "foo.bar.baz"},
},
{},
};
EXPECT_EQ(config.cacheUri.to_string(), "http://foo.bar.baz");
}
TEST(HttpBinaryCacheStore, constructConfigNoTrailingSlash)
{
HttpBinaryCacheStoreConfig config{"https", "foo.bar.baz/a/b/", {}};
HttpBinaryCacheStoreConfig config{parseURL("https://foo.bar.baz/a/b/"), {}};
EXPECT_EQ(config.cacheUri.to_string(), "https://foo.bar.baz/a/b");
}
TEST(HttpBinaryCacheStore, constructConfigWithParams)
{
StoreConfig::Params params{{"compression", "xz"}};
HttpBinaryCacheStoreConfig config{"https", "foo.bar.baz/a/b/", params};
HttpBinaryCacheStoreConfig config{parseURL("https://foo.bar.baz/a/b/"), params};
EXPECT_EQ(config.cacheUri.to_string(), "https://foo.bar.baz/a/b");
EXPECT_EQ(config.getReference().params, params);
}
@@ -32,7 +39,7 @@ TEST(HttpBinaryCacheStore, constructConfigWithParams)
TEST(HttpBinaryCacheStore, constructConfigWithParamsAndUrlWithParams)
{
StoreConfig::Params params{{"compression", "xz"}};
HttpBinaryCacheStoreConfig config{"https", "foo.bar.baz/a/b?some-param=some-value", params};
HttpBinaryCacheStoreConfig config{parseURL("https://foo.bar.baz/a/b?some-param=some-value"), params};
EXPECT_EQ(config.cacheUri.to_string(), "https://foo.bar.baz/a/b?some-param=some-value");
EXPECT_EQ(config.getReference().params, params);
}
+1 -2
View File
@@ -7,8 +7,7 @@ namespace nix {
TEST(LegacySSHStore, constructConfig)
{
LegacySSHStoreConfig config(
"ssh",
"me@localhost:2222",
ParsedURL::Authority::parse("me@localhost:2222"),
StoreConfig::Params{
{
"remote-program",
@@ -6,8 +6,7 @@ namespace nix {
TEST(LocalBinaryCacheStore, constructConfig)
{
LocalBinaryCacheStoreConfig config{"local", "/foo/bar/baz", {}};
LocalBinaryCacheStoreConfig config{std::filesystem::path("/foo/bar/baz"), {}};
EXPECT_EQ(config.binaryCacheDir, "/foo/bar/baz");
}
+1 -2
View File
@@ -7,7 +7,6 @@ namespace nix {
TEST(LocalOverlayStore, constructConfig_rootQueryParam)
{
LocalOverlayStoreConfig config{
"local-overlay",
"",
{
{
@@ -22,7 +21,7 @@ TEST(LocalOverlayStore, constructConfig_rootQueryParam)
TEST(LocalOverlayStore, constructConfig_rootPath)
{
LocalOverlayStoreConfig config{"local-overlay", "/foo/bar", {}};
LocalOverlayStoreConfig config{"/foo/bar", {}};
EXPECT_EQ(config.rootDir.get(), std::optional{"/foo/bar"});
}
+2 -3
View File
@@ -13,7 +13,6 @@ namespace nix {
TEST(LocalStore, constructConfig_rootQueryParam)
{
LocalStoreConfig config{
"local",
"",
{
{
@@ -28,14 +27,14 @@ TEST(LocalStore, constructConfig_rootQueryParam)
TEST(LocalStore, constructConfig_rootPath)
{
LocalStoreConfig config{"local", "/foo/bar", {}};
LocalStoreConfig config{"/foo/bar", {}};
EXPECT_EQ(config.rootDir.get(), std::optional{"/foo/bar"});
}
TEST(LocalStore, constructConfig_to_string)
{
LocalStoreConfig config{"local", "", {}};
LocalStoreConfig config{"", {}};
EXPECT_EQ(config.getReference().to_string(), "local");
}
+2 -2
View File
@@ -27,7 +27,7 @@ TEST(machines, getMachinesUriOnly)
ASSERT_THAT(actual, SizeIs(1));
EXPECT_THAT(actual[0], Field(&Machine::storeUri, Eq(StoreReference::parse("ssh://nix@scratchy.labs.cs.uu.nl"))));
EXPECT_THAT(actual[0], Field(&Machine::systemTypes, ElementsAre("TEST_ARCH-TEST_OS")));
EXPECT_THAT(actual[0], Field(&Machine::sshKey, SizeIs(0)));
EXPECT_THAT(actual[0], Field(&Machine::sshKey, Eq(std::filesystem::path{})));
EXPECT_THAT(actual[0], Field(&Machine::maxJobs, Eq(1)));
EXPECT_THAT(actual[0], Field(&Machine::speedFactor, Eq(1)));
EXPECT_THAT(actual[0], Field(&Machine::supportedFeatures, SizeIs(0)));
@@ -49,7 +49,7 @@ TEST(machines, getMachinesDefaults)
ASSERT_THAT(actual, SizeIs(1));
EXPECT_THAT(actual[0], Field(&Machine::storeUri, Eq(StoreReference::parse("ssh://nix@scratchy.labs.cs.uu.nl"))));
EXPECT_THAT(actual[0], Field(&Machine::systemTypes, ElementsAre("TEST_ARCH-TEST_OS")));
EXPECT_THAT(actual[0], Field(&Machine::sshKey, SizeIs(0)));
EXPECT_THAT(actual[0], Field(&Machine::sshKey, Eq(std::filesystem::path{})));
EXPECT_THAT(actual[0], Field(&Machine::maxJobs, Eq(1)));
EXPECT_THAT(actual[0], Field(&Machine::speedFactor, Eq(1)));
EXPECT_THAT(actual[0], Field(&Machine::supportedFeatures, SizeIs(0)));
+2 -2
View File
@@ -26,7 +26,7 @@ TEST(NarInfoDiskCacheImpl, create_and_read)
{
auto cache = NarInfoDiskCache::getTest(
settings.getNarInfoDiskCacheSettings(), {.useWAL = settings.useSQLiteWAL}, dbPath.string());
settings.getNarInfoDiskCacheSettings(), {.useWAL = settings.useSQLiteWAL}, dbPath);
// Set up "background noise" and check that different caches receive different ids
{
@@ -76,7 +76,7 @@ TEST(NarInfoDiskCacheImpl, create_and_read)
// We can't clear the in-memory cache, so we use a new cache object. This is
// more realistic anyway.
auto cache2 = NarInfoDiskCache::getTest(
settings.getNarInfoDiskCacheSettings(), {.useWAL = settings.useSQLiteWAL}, dbPath.string());
settings.getNarInfoDiskCacheSettings(), {.useWAL = settings.useSQLiteWAL}, dbPath);
{
auto r = cache2->upToDateCacheExists("http://foo");
+7 -7
View File
@@ -9,7 +9,7 @@ namespace nix {
TEST(S3BinaryCacheStore, constructConfig)
{
S3BinaryCacheStoreConfig config{"s3", "foobar", {}};
S3BinaryCacheStoreConfig config{"foobar", {}};
// The bucket name is stored as the host part of the authority in cacheUri
EXPECT_EQ(
@@ -23,7 +23,7 @@ TEST(S3BinaryCacheStore, constructConfig)
TEST(S3BinaryCacheStore, constructConfigWithRegion)
{
Store::Config::Params params{{"region", "eu-west-1"}};
S3BinaryCacheStoreConfig config{"s3", "my-bucket", params};
S3BinaryCacheStoreConfig config{"my-bucket", params};
EXPECT_EQ(
config.cacheUri,
@@ -37,7 +37,7 @@ TEST(S3BinaryCacheStore, constructConfigWithRegion)
TEST(S3BinaryCacheStore, defaultSettings)
{
S3BinaryCacheStoreConfig config{"s3", "test-bucket", {}};
S3BinaryCacheStoreConfig config{"test-bucket", {}};
EXPECT_EQ(
config.cacheUri,
@@ -62,7 +62,7 @@ TEST(S3BinaryCacheStore, s3StoreConfigPreservesParameters)
params["region"] = "eu-west-1";
params["endpoint"] = "custom.s3.com";
S3BinaryCacheStoreConfig config("s3", "test-bucket", params);
S3BinaryCacheStoreConfig config("test-bucket", params);
// The config should preserve S3-specific parameters
EXPECT_EQ(
@@ -99,7 +99,7 @@ TEST(S3BinaryCacheStore, parameterFiltering)
params["want-mass-query"] = "true"; // Non-S3 store parameter
params["priority"] = "10"; // Non-S3 store parameter
S3BinaryCacheStoreConfig config("s3", "test-bucket", params);
S3BinaryCacheStoreConfig config("test-bucket", params);
// Only S3-specific params should be in cacheUri.query
EXPECT_EQ(
@@ -127,7 +127,7 @@ TEST(S3BinaryCacheStore, parameterFiltering)
*/
TEST(S3BinaryCacheStore, storageClassDefault)
{
S3BinaryCacheStoreConfig config{"s3", "test-bucket", {}};
S3BinaryCacheStoreConfig config{"test-bucket", {}};
EXPECT_EQ(config.storageClass.get(), std::nullopt);
}
@@ -136,7 +136,7 @@ TEST(S3BinaryCacheStore, storageClassConfiguration)
StringMap params;
params["storage-class"] = "GLACIER";
S3BinaryCacheStoreConfig config("s3", "test-bucket", params);
S3BinaryCacheStoreConfig config("test-bucket", params);
EXPECT_EQ(config.storageClass.get(), std::optional<std::string>("GLACIER"));
}
+2 -4
View File
@@ -9,8 +9,7 @@ namespace nix {
TEST(SSHStore, constructConfig)
{
SSHStoreConfig config{
"ssh-ng",
"me@localhost:2222",
ParsedURL::Authority::parse("me@localhost:2222"),
StoreConfig::Params{
{
"remote-program",
@@ -35,8 +34,7 @@ TEST(SSHStore, constructConfig)
TEST(MountedSSHStore, constructConfig)
{
MountedSSHStoreConfig config{
"mounted-ssh",
"localhost",
{.host = "localhost"},
StoreConfig::Params{
{
"remote-program",
+4 -9
View File
@@ -6,26 +6,21 @@ namespace nix {
TEST(UDSRemoteStore, constructConfig)
{
UDSRemoteStoreConfig config{"unix", "/tmp/socket", {}};
UDSRemoteStoreConfig config{"/tmp/socket", {}};
EXPECT_EQ(config.path, "/tmp/socket");
}
TEST(UDSRemoteStore, constructConfigWrongScheme)
{
EXPECT_THROW(UDSRemoteStoreConfig("http", "/tmp/socket", {}), UsageError);
}
TEST(UDSRemoteStore, constructConfig_to_string)
{
UDSRemoteStoreConfig config{"unix", "", {}};
UDSRemoteStoreConfig config{"", {}};
EXPECT_EQ(config.getReference().to_string(), "daemon");
}
TEST(UDSRemoteStore, constructConfigWithParams)
{
StoreConfig::Params params{{"max-connections", "1"}};
UDSRemoteStoreConfig config{"unix", "/tmp/socket", params};
UDSRemoteStoreConfig config{"/tmp/socket", params};
auto storeReference = config.getReference();
EXPECT_EQ(storeReference.to_string(), "unix:///tmp/socket?max-connections=1");
EXPECT_EQ(storeReference.render(/*withParams=*/false), "unix:///tmp/socket");
@@ -35,7 +30,7 @@ TEST(UDSRemoteStore, constructConfigWithParams)
TEST(UDSRemoteStore, constructConfigWithParamsNoPath)
{
StoreConfig::Params params{{"max-connections", "1"}};
UDSRemoteStoreConfig config{"unix", "", params};
UDSRemoteStoreConfig config{"", params};
auto storeReference = config.getReference();
EXPECT_EQ(storeReference.to_string(), "daemon?max-connections=1");
EXPECT_EQ(storeReference.render(/*withParams=*/false), "daemon");
+3 -3
View File
@@ -27,12 +27,12 @@ namespace nix {
BinaryCacheStore::BinaryCacheStore(Config & config)
: config{config}
{
if (config.secretKeyFile != "")
signers.push_back(std::make_unique<LocalSigner>(SecretKey{readFile(config.secretKeyFile)}));
if (!config.secretKeyFile.get().empty())
signers.push_back(std::make_unique<LocalSigner>(SecretKey{readFile(config.secretKeyFile.get())}));
if (config.secretKeyFiles != "") {
std::stringstream ss(config.secretKeyFiles);
Path keyPath;
std::string keyPath;
while (std::getline(ss, keyPath, ',')) {
signers.push_back(std::make_unique<LocalSigner>(SecretKey{readFile(keyPath)}));
}
+12 -9
View File
@@ -387,8 +387,11 @@ Goal::Co DerivationBuildingGoal::tryToBuild(StorePathSet inputPaths)
for (auto & i : drv->outputsAndOptPaths(worker.store)) {
if (i.second.second)
lockFiles.insert(localStore->toRealPath(*i.second.second));
else
lockFiles.insert(localStore->toRealPath(drvPath) + "." + i.first);
else {
auto lockPath = localStore->toRealPath(drvPath);
lockPath += "." + i.first;
lockFiles.insert(std::move(lockPath));
}
}
}
@@ -1061,7 +1064,7 @@ static void runPostBuildHook(
LogSink sink(act);
runProgram2({
.program = workerSettings.postBuildHook,
.program = workerSettings.postBuildHook.get(),
.environment = hookEnvironment,
.standardOut = &sink,
.mergeStderrToStdout = true,
@@ -1178,15 +1181,15 @@ LogFile::LogFile(Store & store, const StorePath & drvPath, const LogFileSettings
auto baseName = std::string(baseNameOf(store.printStorePath(drvPath)));
Path logDir;
std::filesystem::path logDir;
if (auto localStore = dynamic_cast<LocalStore *>(&store))
logDir = localStore->config->logDir;
logDir = localStore->config->logDir.get();
else
logDir = logSettings.nixLogDir.string();
Path dir = fmt("%s/%s/%s/", logDir, LocalFSStore::drvsLogDir, baseName.substr(0, 2));
logDir = logSettings.nixLogDir;
auto dir = logDir / LocalFSStore::drvsLogDir / baseName.substr(0, 2);
createDirs(dir);
Path logFileName = fmt("%s/%s%s", dir, baseName.substr(2), logSettings.compressLog ? ".bz2" : "");
auto logFileName = dir / (baseName.substr(2) + (logSettings.compressLog ? ".bz2" : ""));
fd = openNewFileForWrite(
logFileName,
@@ -1196,7 +1199,7 @@ LogFile::LogFile(Store & store, const StorePath & drvPath, const LogFileSettings
.followSymlinksOnTruncate = true, /* FIXME: Probably shouldn't follow symlinks. */
});
if (!fd)
throw SysError("creating log file '%1%'", logFileName);
throw SysError("creating log file %1%", PathFmt(logFileName));
fileSink = std::make_shared<FdSink>(fd.get());
+11 -12
View File
@@ -20,14 +20,15 @@ namespace {
struct State
{
std::map<Path, int> priorities;
std::map<std::filesystem::path, int> priorities;
unsigned long symlinks = 0;
};
} // namespace
/* For each activated package, create symlinks */
static void createLinks(State & state, const Path & srcDir, const Path & dstDir, int priority)
static void
createLinks(State & state, const std::filesystem::path & srcDir, const std::filesystem::path & dstDir, int priority)
{
DirectoryIterator srcFiles;
@@ -35,7 +36,7 @@ static void createLinks(State & state, const Path & srcDir, const Path & dstDir,
srcFiles = DirectoryIterator{srcDir};
} catch (SystemError & e) {
if (e.is(std::errc::not_a_directory)) {
warn("not including '%s' in the user environment because it's not a directory", srcDir);
warn("not including %s in the user environment because it's not a directory", PathFmt(srcDir));
return;
}
throw;
@@ -78,9 +79,8 @@ static void createLinks(State & state, const Path & srcDir, const Path & dstDir,
} else if (S_ISLNK(dstSt.st_mode)) {
auto target = canonPath(dstFile, true);
if (!S_ISDIR(lstat(target).st_mode))
throw Error("collision between '%1%' and non-directory '%2%'", srcFile, target);
if (unlink(dstFile.c_str()) == -1)
throw SysError("unlinking '%1%'", dstFile);
throw Error("collision between %1% and non-directory %2%", PathFmt(srcFile), PathFmt(target));
unlink(dstFile);
if (mkdir(
dstFile.c_str()
#ifndef _WIN32 // TODO abstract mkdir perms for Windows
@@ -107,8 +107,7 @@ static void createLinks(State & state, const Path & srcDir, const Path & dstDir,
throw BuildEnvFileConflictError(readLink(dstFile), srcFile, priority);
if (prevPriority < priority)
continue;
if (unlink(dstFile.c_str()) == -1)
throw SysError("unlinking '%1%'", dstFile);
unlink(dstFile);
} else if (S_ISDIR(dstSt.st_mode))
throw Error("collision between non-directory '%1%' and directory '%2%'", srcFile, dstFile);
}
@@ -120,20 +119,20 @@ static void createLinks(State & state, const Path & srcDir, const Path & dstDir,
}
}
void buildProfile(const Path & out, Packages && pkgs)
void buildProfile(const std::filesystem::path & out, Packages && pkgs)
{
State state;
PathSet done, postponed;
auto addPkg = [&](const Path & pkgDir, int priority) {
if (!done.insert(pkgDir).second)
auto addPkg = [&](const std::filesystem::path & pkgDir, int priority) {
if (!done.insert(pkgDir.string()).second)
return;
createLinks(state, pkgDir, out, priority);
try {
for (const auto & p : tokenizeString<std::vector<std::string>>(
readFile(pkgDir + "/nix-support/propagated-user-env-packages"), " \n"))
readFile(pkgDir / "nix-support" / "propagated-user-env-packages"), " \n"))
if (!done.count(p))
postponed.insert(p);
} catch (SystemError & e) {
+1 -1
View File
@@ -15,7 +15,7 @@ static void builtinFetchurl(const BuiltinBuilderContext & ctx)
pass a pointer to the data. */
if (ctx.netrcData != "") {
fileTransferSettings.netrcFile = "netrc";
writeFile(fileTransferSettings.netrcFile, ctx.netrcData, 0600);
writeFile(fileTransferSettings.netrcFile.get(), ctx.netrcData, 0600);
}
fileTransferSettings.caFile = "ca-certificates.crt";
+1 -9
View File
@@ -1,17 +1,9 @@
#include <regex>
#include "nix/store/common-ssh-store-config.hh"
#include "nix/store/ssh.hh"
namespace nix {
CommonSSHStoreConfig::CommonSSHStoreConfig(std::string_view scheme, std::string_view authority, const Params & params)
: CommonSSHStoreConfig(scheme, ParsedURL::Authority::parse(authority), params)
{
}
CommonSSHStoreConfig::CommonSSHStoreConfig(
std::string_view scheme, const ParsedURL::Authority & authority, const Params & params)
CommonSSHStoreConfig::CommonSSHStoreConfig(const ParsedURL::Authority & authority, const Params & params)
: StoreConfig(params)
, authority(authority)
{
+3 -3
View File
@@ -680,17 +680,17 @@ static void performOp(
"you are not privileged to create perm roots\n\n"
"hint: you can just do this client-side without special privileges, and probably want to do that instead.");
auto storePath = WorkerProto::Serialise<StorePath>::read(*store, rconn);
Path gcRoot = absPath(readString(conn.from));
std::filesystem::path gcRoot = absPath(readString(conn.from));
logger->startWork();
auto & localFSStore = require<LocalFSStore>(*store);
localFSStore.addPermRoot(storePath, gcRoot);
logger->stopWork();
conn.to << gcRoot;
conn.to << gcRoot.string();
break;
}
case WorkerProto::Op::AddIndirectRoot: {
Path path = absPath(readString(conn.from));
std::filesystem::path path = absPath(readString(conn.from));
logger->startWork();
auto & indirectRootStore = require<IndirectRootStore>(*store);
+55 -45
View File
@@ -2,7 +2,6 @@
#include "nix/store/globals.hh"
#include "nix/util/config-global.hh"
#include "nix/store/store-api.hh"
#include "nix/util/compression.hh"
#include "nix/util/finally.hh"
#include "nix/util/callback.hh"
#include "nix/util/signals.hh"
@@ -88,14 +87,10 @@ struct curlFileTransfer : public FileTransfer
FileTransferRequest request;
FileTransferResult result;
std::unique_ptr<Activity> _act;
bool done = false; // whether either the success or failure function has been called
Callback<FileTransferResult> callback;
CURL * req = 0;
// buffer to accompany the `req` above
char errbuf[CURL_ERROR_SIZE];
bool active = false; // whether the handle has been added to the multi object
bool paused = false; // whether the request has been paused previously
bool enqueued = false; // whether the request has been added the incoming queue
std::string statusMsg;
unsigned int attempt = 0;
@@ -106,9 +101,35 @@ struct curlFileTransfer : public FileTransfer
curlSList requestHeaders;
std::string encoding;
/**
* Whether either the success or failure function has been called.
*/
bool done:1 = false;
bool acceptRanges = false;
/**
* Whether the handle has been added to the multi object.
*/
bool active:1 = false;
/**
* Whether the request has been paused previously.
*/
bool paused:1 = false;
/**
* Whether the request has been added the incoming queue.
*/
bool enqueued:1 = false;
/**
* Whether we can use range downloads for retries.
*/
bool acceptRanges:1 = false;
/**
* Whether the response has a non-trivial (not "identity") Content-Encoding.
*/
bool hasContentEncoding:1 = false;
curl_off_t writtenToSink = 0;
@@ -169,15 +190,6 @@ struct curlFileTransfer : public FileTransfer
{
result.urls.push_back(request.uri.to_string());
/* Don't set Accept-Encoding for S3 requests that use AWS SigV4 signing.
curl's SigV4 implementation signs all headers including Accept-Encoding,
but some S3-compatible services (like GCS) modify this header in transit,
causing signature verification to fail.
See https://github.com/NixOS/nix/issues/15019 */
#if NIX_WITH_AWS_AUTH
if (!request.awsSigV4Provider)
#endif
appendHeaders("Accept-Encoding: zstd, br, gzip, deflate, bzip2, xz");
if (!request.expectedETag.empty())
appendHeaders("If-None-Match: " + request.expectedETag);
if (!request.mimeType.empty())
@@ -225,7 +237,6 @@ struct curlFileTransfer : public FileTransfer
}
LambdaSink finalSink;
std::shared_ptr<FinishSink> decompressionSink;
std::optional<StringSink> errorSink;
std::exception_ptr callbackException;
@@ -235,18 +246,15 @@ struct curlFileTransfer : public FileTransfer
size_t realSize = size * nmemb;
result.bodySize += realSize;
if (!decompressionSink) {
decompressionSink = makeDecompressionSink(encoding, finalSink);
if (!successfulStatuses.count(getHTTPStatus())) {
// In this case we want to construct a TeeSink, to keep
// the response around (which we figure won't be big
// like an actual download should be) to improve error
// messages.
errorSink = StringSink{};
}
if (!errorSink && !successfulStatuses.count(getHTTPStatus())) {
// In this case we want to construct a TeeSink, to keep
// the response around (which we figure won't be big
// like an actual download should be) to improve error
// messages.
errorSink = StringSink{};
}
(*decompressionSink)({(char *) contents, realSize});
finalSink({static_cast<const char *>(contents), realSize});
if (paused) {
/* The callback has signaled that the transfer needs to be
paused. Already consumed data won't be returned twice unlike
@@ -288,7 +296,7 @@ struct curlFileTransfer : public FileTransfer
result.bodySize = 0;
statusMsg = trim(match.str(1));
acceptRanges = false;
encoding = "";
hasContentEncoding = false;
appendCurrentUrl();
} else {
@@ -311,8 +319,10 @@ struct curlFileTransfer : public FileTransfer
}
}
else if (name == "content-encoding")
encoding = trim(line.substr(i + 1));
else if (name == "content-encoding") {
auto value = toLower(trim(line.substr(i + 1)));
hasContentEncoding = !value.empty() && value != "identity";
}
else if (name == "accept-ranges" && toLower(trim(line.substr(i + 1))) == "bytes")
acceptRanges = true;
@@ -330,14 +340,10 @@ struct curlFileTransfer : public FileTransfer
}
return realSize;
} catch (...) {
#if LIBCURL_VERSION_NUM >= 0x075700
/* https://curl.se/libcurl/c/CURLOPT_HEADERFUNCTION.html:
You can also abort the transfer by returning CURL_WRITEFUNC_ERROR. */
callbackException = std::current_exception();
return CURL_WRITEFUNC_ERROR;
#else
return realSize;
#endif
}
static size_t headerCallbackWrapper(void * contents, size_t size, size_t nmemb, void * userp)
@@ -475,6 +481,16 @@ struct curlFileTransfer : public FileTransfer
}
curl_easy_setopt(req, CURLOPT_URL, request.uri.to_string().c_str());
/* Enable transparent decompression for downloads.
Skip for uploads (Accept-Encoding is meaningless when sending data)
and when resuming from an offset (byte ranges don't work with
compressed content). */
if (writtenToSink == 0 && !request.data)
/* Empty string means to enable all supported (that libcurl has
been linked to support) encodings. */
curl_easy_setopt(req, CURLOPT_ACCEPT_ENCODING, "");
curl_easy_setopt(req, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(req, CURLOPT_MAXREDIRS, 10);
curl_easy_setopt(req, CURLOPT_NOSIGNAL, 1);
@@ -621,14 +637,6 @@ struct curlFileTransfer : public FileTransfer
appendCurrentUrl();
if (decompressionSink) {
try {
decompressionSink->finish();
} catch (...) {
callbackException = std::current_exception();
}
}
if (code == CURLE_WRITE_ERROR && result.etag == request.expectedETag) {
code = CURLE_OK;
httpStatus = 304;
@@ -646,7 +654,9 @@ struct curlFileTransfer : public FileTransfer
if (httpStatus == 304 && result.etag == "")
result.etag = request.expectedETag;
act().progress(result.bodySize, result.bodySize);
curl_off_t dlSize = 0;
curl_easy_getinfo(req, CURLINFO_SIZE_DOWNLOAD_T, &dlSize);
act().progress(dlSize, dlSize);
done = true;
callback(std::move(result));
}
@@ -695,6 +705,7 @@ struct curlFileTransfer : public FileTransfer
case CURLE_TOO_MANY_REDIRECTS:
case CURLE_WRITE_ERROR:
case CURLE_UNSUPPORTED_PROTOCOL:
case CURLE_BAD_CONTENT_ENCODING:
err = Misc;
break;
default: // Shut up warnings
@@ -738,7 +749,7 @@ struct curlFileTransfer : public FileTransfer
sink, we can only retry if the server supports
ranged requests. */
if (err == Transient && attempt < fileTransfer.settings.tries
&& (!this->request.dataCallback || writtenToSink == 0 || (acceptRanges && encoding.empty()))) {
&& (!this->request.dataCallback || writtenToSink == 0 || (acceptRanges && !hasContentEncoding))) {
int ms = retryTimeMs
* std::pow(
2.0f, attempt - 1 + std::uniform_real_distribution<>(0.0, 0.5)(fileTransfer.mt19937));
@@ -746,7 +757,6 @@ struct curlFileTransfer : public FileTransfer
warn("%s; retrying from offset %d in %d ms", exc.what(), writtenToSink, ms);
else
warn("%s; retrying in %d ms", exc.what(), ms);
decompressionSink.reset();
errorSink.reset();
embargo = std::chrono::steady_clock::now() + std::chrono::milliseconds(ms);
try {
+53 -52
View File
@@ -35,13 +35,13 @@
namespace nix {
static std::string gcSocketPath = "/gc-socket/socket";
static std::string gcSocketPath = "gc-socket/socket";
static std::string gcRootsDir = "gcroots";
void LocalStore::addIndirectRoot(const Path & path)
void LocalStore::addIndirectRoot(const std::filesystem::path & path)
{
std::string hash = hashString(HashAlgorithm::SHA1, path).to_string(HashFormat::Nix32, false);
Path realRoot = canonPath(fmt("%1%/%2%/auto/%3%", config->stateDir, gcRootsDir, hash));
std::string hash = hashString(HashAlgorithm::SHA1, path.string()).to_string(HashFormat::Nix32, false);
auto realRoot = canonPath(config->stateDir.get() / gcRootsDir / "auto" / hash);
makeSymlink(realRoot, path);
}
@@ -57,11 +57,11 @@ void LocalStore::createTempRootsFile()
if (pathExists(fnTempRoots))
/* It *must* be stale, since there can be no two
processes with the same pid. */
unlink(fnTempRoots.c_str());
tryUnlink(fnTempRoots);
*fdTempRoots = openLockFile(fnTempRoots, true);
debug("acquiring write lock on '%s'", fnTempRoots);
debug("acquiring write lock on %s", PathFmt(fnTempRoots));
lockFile(fdTempRoots->get(), ltWrite, true);
/* Check whether the garbage collector didn't get in our
@@ -105,8 +105,8 @@ restart:
auto fdRootsSocket(_fdRootsSocket.lock());
if (!*fdRootsSocket) {
auto socketPath = config->stateDir.get() + gcSocketPath;
debug("connecting to '%s'", socketPath);
auto socketPath = config->stateDir.get() / gcSocketPath;
debug("connecting to '%s'", PathFmt(socketPath));
*fdRootsSocket = createUnixDomainSocket();
try {
nix::connect(toSocket(fdRootsSocket->get()), socketPath);
@@ -166,13 +166,13 @@ void LocalStore::findTempRoots(Roots & tempRoots, bool censor)
// those to keep the directory alive.
continue;
}
Path path = i.path().string();
auto path = i.path();
pid_t pid = std::stoi(name);
debug("reading temporary root file '%1%'", path);
debug("reading temporary root file %1%", PathFmt(path));
AutoCloseFD fd(toDescriptor(open(
path.c_str(),
path.string().c_str(),
#ifndef _WIN32
O_CLOEXEC |
#endif
@@ -182,15 +182,15 @@ void LocalStore::findTempRoots(Roots & tempRoots, bool censor)
/* It's okay if the file has disappeared. */
if (errno == ENOENT)
continue;
throw SysError("opening temporary roots file '%1%'", path);
throw SysError("opening temporary roots file %1%", PathFmt(path));
}
/* Try to acquire a write lock without blocking. This can
only succeed if the owning process has died. In that case
we don't care about its temporary roots. */
if (lockFile(fd.get(), ltWrite, false)) {
printInfo("removing stale temporary roots file '%1%'", path);
unlink(path.c_str());
printInfo("removing stale temporary roots file %1%", PathFmt(path));
tryUnlink(path);
writeFull(fd.get(), "d");
continue;
}
@@ -202,7 +202,7 @@ void LocalStore::findTempRoots(Roots & tempRoots, bool censor)
std::string::size_type pos = 0, end;
while ((end = contents.find((char) 0, pos)) != std::string::npos) {
Path root(contents, pos, end - pos);
auto root = std::string_view(contents).substr(pos, end - pos);
debug("got temporary root '%s'", root);
tempRoots[parseStorePath(root)].emplace(censor ? censored : fmt("{temp:%d}", pid));
pos = end + 1;
@@ -210,15 +210,15 @@ void LocalStore::findTempRoots(Roots & tempRoots, bool censor)
}
}
void LocalStore::findRoots(const Path & path, std::filesystem::file_type type, Roots & roots)
void LocalStore::findRoots(const std::filesystem::path & path, std::filesystem::file_type type, Roots & roots)
{
auto foundRoot = [&](const Path & path, const Path & target) {
auto foundRoot = [&](const std::filesystem::path & path, const std::filesystem::path & target) {
try {
auto storePath = toStorePath(target).first;
auto storePath = toStorePath(target.string()).first;
if (isValidPath(storePath))
roots[std::move(storePath)].emplace(path);
roots[std::move(storePath)].emplace(path.string());
else
printInfo("skipping invalid root from '%1%' to '%2%'", path, target);
printInfo("skipping invalid root from %1% to %2%", PathFmt(path), PathFmt(target));
} catch (BadStorePath &) {
}
};
@@ -231,37 +231,38 @@ void LocalStore::findRoots(const Path & path, std::filesystem::file_type type, R
if (type == std::filesystem::file_type::directory) {
for (auto & i : DirectoryIterator{path}) {
checkInterrupt();
findRoots(i.path().string(), i.symlink_status().type(), roots);
findRoots(i.path(), i.symlink_status().type(), roots);
}
}
else if (type == std::filesystem::file_type::symlink) {
Path target = readLink(path);
if (isInStore(target))
auto target = readLink(path);
if (isInStore(target.string()))
foundRoot(path, target);
/* Handle indirect roots. */
else {
target = absPath(target, dirOf(path));
auto parentPath = path.parent_path();
target = absPath(target, &parentPath);
if (!pathExists(target)) {
if (isInDir(path, std::filesystem::path{config->stateDir.get()} / gcRootsDir / "auto")) {
printInfo("removing stale link from '%1%' to '%2%'", path, target);
unlink(path.c_str());
if (isInDir(path, config->stateDir.get() / gcRootsDir / "auto")) {
printInfo("removing stale link from %1% to %2%", PathFmt(path), PathFmt(target));
tryUnlink(path);
}
} else {
if (!std::filesystem::is_symlink(target))
return;
Path target2 = readLink(target);
if (isInStore(target2))
auto target2 = readLink(target);
if (isInStore(target2.string()))
foundRoot(target, target2);
}
}
}
else if (type == std::filesystem::file_type::regular) {
auto storePath = maybeParseStorePath(storeDir + "/" + std::string(baseNameOf(path)));
auto storePath = maybeParseStorePath(storeDir + "/" + std::string(baseNameOf(path.string())));
if (storePath && isValidPath(*storePath))
roots[std::move(*storePath)].emplace(path);
roots[std::move(*storePath)].emplace(path.string());
}
}
@@ -270,16 +271,16 @@ void LocalStore::findRoots(const Path & path, std::filesystem::file_type type, R
/* We only ignore permanent failures. */
if (e.code() == std::errc::permission_denied || e.code() == std::errc::no_such_file_or_directory
|| e.code() == std::errc::not_a_directory)
printInfo("cannot read potential root '%1%'", path);
printInfo("cannot read potential root %1%", PathFmt(path));
else
throw SystemError(e.code(), "finding GC roots in '%1%'", path);
throw SystemError(e.code(), "finding GC roots in %1%", PathFmt(path));
}
catch (SystemError & e) {
/* We only ignore permanent failures. */
if (e.is(std::errc::permission_denied) || e.is(std::errc::no_such_file_or_directory)
|| e.is(std::errc::not_a_directory))
printInfo("cannot read potential root '%1%'", path);
printInfo("cannot read potential root %1%", PathFmt(path));
else
throw;
}
@@ -288,8 +289,8 @@ void LocalStore::findRoots(const Path & path, std::filesystem::file_type type, R
void LocalStore::findRootsNoTemp(Roots & roots, bool censor)
{
/* Process direct roots in {gcroots,profiles}. */
findRoots(config->stateDir + "/" + gcRootsDir, std::filesystem::file_type::unknown, roots);
findRoots(config->stateDir + "/profiles", std::filesystem::file_type::unknown, roots);
findRoots(config->stateDir.get() / gcRootsDir, std::filesystem::file_type::unknown, roots);
findRoots(config->stateDir.get() / "profiles", std::filesystem::file_type::unknown, roots);
/* Add additional roots returned by different platforms-specific
heuristics. This is typically used to add running programs to
@@ -398,8 +399,8 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
readFile(*p);
/* Start the server for receiving new roots. */
auto socketPath = config->stateDir.get() + gcSocketPath;
createDirs(dirOf(socketPath));
auto socketPath = config->stateDir.get() / gcSocketPath;
createDirs(socketPath.parent_path());
auto fdServer = createUnixDomainSocket(socketPath, 0666);
// TODO nonblocking socket on windows?
@@ -407,7 +408,7 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
throw UnimplementedError("External GC client not implemented yet");
#else
if (fcntl(fdServer.get(), F_SETFL, fcntl(fdServer.get(), F_GETFL) | O_NONBLOCK) == -1)
throw SysError("making socket '%1%' non-blocking", socketPath);
throw SysError("making socket %s non-blocking", PathFmt(socketPath));
Pipe shutdownPipe;
shutdownPipe.create();
@@ -538,16 +539,17 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
/* Helper function that deletes a path from the store and throws
GCLimitReached if we've deleted enough garbage. */
auto deleteFromStore = [&](std::string_view baseName, bool isKnownPath) {
assert(!std::filesystem::path(baseName).is_absolute());
Path path = storeDir + "/" + std::string(baseName);
Path realPath = config->realStoreDir + "/" + std::string(baseName);
auto realPath = config->realStoreDir.get() / std::string(baseName);
/* There may be temp directories in the store that are still in use
by another process. We need to be sure that we can acquire an
exclusive lock before deleting them. */
if (baseName.find("tmp-", 0) == 0) {
AutoCloseFD tmpDirFd = openDirectory(realPath);
auto tmpDirFd = openDirectory(realPath);
if (!tmpDirFd || !lockFile(tmpDirFd.get(), ltWrite, false)) {
debug("skipping locked tempdir '%s'", realPath);
debug("skipping locked tempdir %s", PathFmt(realPath));
return;
}
}
@@ -712,14 +714,14 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
printInfo("determining live/dead paths...");
try {
AutoCloseDir dir(opendir(config->realStoreDir.get().c_str()));
AutoCloseDir dir(opendir(config->realStoreDir.get().string().c_str()));
if (!dir)
throw SysError("opening directory '%1%'", config->realStoreDir);
throw SysError("opening directory %1%", PathFmt(config->realStoreDir.get()));
/* Read the store and delete all paths that are invalid or
unreachable. We don't use readDirectory() here so that
GCing can start faster. */
auto linksName = baseNameOf(linksDir);
auto linksName = linksDir.filename();
struct dirent * dirent;
while (errno = 0, dirent = readdir(dir.get())) {
checkInterrupt();
@@ -756,9 +758,9 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
if (options.action == GCOptions::gcDeleteDead || options.action == GCOptions::gcDeleteSpecific) {
printInfo("deleting unused links...");
AutoCloseDir dir(opendir(linksDir.c_str()));
AutoCloseDir dir(opendir(linksDir.string().c_str()));
if (!dir)
throw SysError("opening directory '%1%'", linksDir);
throw SysError("opening directory %1%", PathFmt(linksDir));
int64_t actualSize = 0, unsharedSize = 0;
@@ -768,7 +770,7 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
std::string name = dirent->d_name;
if (name == "." || name == "..")
continue;
Path path = linksDir + "/" + name;
auto path = linksDir / name;
auto st = lstat(path);
@@ -778,10 +780,9 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
continue;
}
printMsg(lvlTalkative, "deleting unused link '%1%'", path);
printMsg(lvlTalkative, "deleting unused link %1%", PathFmt(path));
if (unlink(path.c_str()) == -1)
throw SysError("deleting '%1%'", path);
unlink(path);
/* Do not account for deleted file here. Rely on deletePath()
accounting. */
@@ -818,7 +819,7 @@ void LocalStore::autoGC(bool sync)
struct statvfs st;
if (statvfs(config->realStoreDir.get().c_str(), &st))
throw SysError("getting filesystem info about '%s'", config->realStoreDir);
throw SysError("getting filesystem info about '%s'", PathFmt(config->realStoreDir.get()));
return (uint64_t) st.f_bavail * st.f_frsize;
};
+2 -12
View File
@@ -20,23 +20,13 @@ StringSet HttpBinaryCacheStoreConfig::uriSchemes()
return ret;
}
HttpBinaryCacheStoreConfig::HttpBinaryCacheStoreConfig(
std::string_view scheme, std::string_view _cacheUri, const Params & params)
: HttpBinaryCacheStoreConfig(
parseURL(
std::string{scheme} + "://"
+ (!_cacheUri.empty()
? _cacheUri
: throw UsageError("`%s` Store requires a non-empty authority in Store URL", scheme))),
params)
{
}
HttpBinaryCacheStoreConfig::HttpBinaryCacheStoreConfig(ParsedURL _cacheUri, const Params & params)
: StoreConfig(params)
, BinaryCacheStoreConfig(params)
, cacheUri(std::move(_cacheUri))
{
if (!uriSchemes().contains("file") && (!cacheUri.authority || cacheUri.authority->host.empty()))
throw UsageError("`%s` Store requires a non-empty authority in Store URL", cacheUri.scheme);
while (!cacheUri.path.empty() && cacheUri.path.back() == "")
cacheUri.path.pop_back();
}
@@ -39,7 +39,8 @@ struct BinaryCacheStoreConfig : virtual StoreConfig
fetch debug info on demand
)"};
Setting<Path> secretKeyFile{this, "", "secret-key", "Path to the secret key used to sign the binary cache."};
Setting<std::filesystem::path> secretKeyFile{
this, "", "secret-key", "Path to the secret key used to sign the binary cache."};
Setting<std::string> secretKeyFiles{
this, "", "secret-keys", "List of comma-separated paths to the secret keys used to sign the binary cache."};
@@ -2,6 +2,7 @@
///@file
#include "nix/store/store-api.hh"
#include "nix/util/fmt.hh"
namespace nix {
@@ -10,11 +11,11 @@ namespace nix {
*/
struct Package
{
Path path;
std::filesystem::path path;
bool active;
int priority;
Package(const Path & path, bool active, int priority)
Package(const std::filesystem::path & path, bool active, int priority)
: path{path}
, active{active}
, priority{priority}
@@ -25,18 +26,18 @@ struct Package
class BuildEnvFileConflictError final : public CloneableError<BuildEnvFileConflictError, Error>
{
public:
const Path fileA;
const Path fileB;
const std::filesystem::path fileA;
const std::filesystem::path fileB;
int priority;
BuildEnvFileConflictError(const Path fileA, const Path fileB, int priority)
BuildEnvFileConflictError(const std::filesystem::path fileA, const std::filesystem::path fileB, int priority)
: CloneableError(
"Unable to build profile. There is a conflict for the following files:\n"
"\n"
" %1%\n"
" %2%",
fileA,
fileB)
PathFmt(fileA),
PathFmt(fileB))
, fileA(fileA)
, fileB(fileB)
, priority(priority)
@@ -46,6 +47,6 @@ public:
typedef std::vector<Package> Packages;
void buildProfile(const Path & out, Packages && pkgs);
void buildProfile(const std::filesystem::path & out, Packages && pkgs);
} // namespace nix
@@ -12,10 +12,9 @@ struct CommonSSHStoreConfig : virtual StoreConfig
{
using StoreConfig::StoreConfig;
CommonSSHStoreConfig(std::string_view scheme, const ParsedURL::Authority & authority, const Params & params);
CommonSSHStoreConfig(std::string_view scheme, std::string_view authority, const Params & params);
CommonSSHStoreConfig(const ParsedURL::Authority & authority, const Params & params);
Setting<Path> sshKey{
Setting<std::filesystem::path> sshKey{
this, "", "ssh-key", "Path to the SSH private key used to authenticate to the remote machine."};
Setting<std::string> sshPublicHostKey{
@@ -16,9 +16,6 @@ struct HttpBinaryCacheStoreConfig : std::enable_shared_from_this<HttpBinaryCache
{
using BinaryCacheStoreConfig::BinaryCacheStoreConfig;
HttpBinaryCacheStoreConfig(
std::string_view scheme, std::string_view cacheUri, const Store::Config::Params & params);
HttpBinaryCacheStoreConfig(ParsedURL cacheUri, const Store::Config::Params & params);
ParsedURL cacheUri;
@@ -55,7 +55,7 @@ struct IndirectRootStore : public virtual LocalFSStore
* The implementation of this method is concrete, but it delegates
* to `addIndirectRoot()` which is abstract.
*/
Path addPermRoot(const StorePath & storePath, const Path & gcRoot) override final;
std::filesystem::path addPermRoot(const StorePath & storePath, const std::filesystem::path & gcRoot) override final;
/**
* Add an indirect root, which is a weak reference to the
@@ -66,10 +66,10 @@ struct IndirectRootStore : public virtual LocalFSStore
*
* The form this weak-reference takes is implementation-specific.
*/
virtual void addIndirectRoot(const Path & path) = 0;
virtual void addIndirectRoot(const std::filesystem::path & path) = 0;
protected:
void makeSymlink(const Path & link, const Path & target);
void makeSymlink(const std::filesystem::path & link, const std::filesystem::path & target);
};
} // namespace nix
@@ -14,7 +14,7 @@ struct LegacySSHStoreConfig : std::enable_shared_from_this<LegacySSHStoreConfig>
{
using CommonSSHStoreConfig::CommonSSHStoreConfig;
LegacySSHStoreConfig(std::string_view scheme, std::string_view authority, const Params & params);
LegacySSHStoreConfig(const ParsedURL::Authority & authority, const Params & params);
#ifndef _WIN32
// Hack for getting remote build log output.
@@ -12,7 +12,7 @@ struct LocalBinaryCacheStoreConfig : std::enable_shared_from_this<LocalBinaryCac
* @param binaryCacheDir `file://` is a short-hand for `file:///`
* for now.
*/
LocalBinaryCacheStoreConfig(std::string_view scheme, PathView binaryCacheDir, const Params & params);
LocalBinaryCacheStoreConfig(const std::filesystem::path & binaryCacheDir, const Params & params);
std::filesystem::path binaryCacheDir;
@@ -10,7 +10,8 @@ namespace nix {
struct LocalFSStoreConfig : virtual StoreConfig
{
private:
static OptionalPathSetting makeRootDirSetting(LocalFSStoreConfig & self, std::optional<Path> defaultValue)
static Setting<std::optional<std::filesystem::path>>
makeRootDirSetting(LocalFSStoreConfig & self, std::optional<std::filesystem::path> defaultValue)
{
return {
&self,
@@ -30,9 +31,9 @@ public:
*
* @todo Make this less error-prone with new store settings system.
*/
LocalFSStoreConfig(PathView path, const Params & params);
LocalFSStoreConfig(const std::filesystem::path & path, const Params & params);
OptionalPathSetting rootDir = makeRootDirSetting(*this, std::nullopt);
Setting<std::optional<std::filesystem::path>> rootDir = makeRootDirSetting(*this, std::nullopt);
private:
@@ -40,30 +41,36 @@ private:
* An indirection so that we don't need to refer to global settings
* in headers.
*/
static Path getDefaultStateDir();
static std::filesystem::path getDefaultStateDir();
/**
* An indirection so that we don't need to refer to global settings
* in headers.
*/
static Path getDefaultLogDir();
static std::filesystem::path getDefaultLogDir();
public:
PathSetting stateDir{
Setting<std::filesystem::path> stateDir{
this,
rootDir.get() ? *rootDir.get() + "/nix/var/nix" : getDefaultStateDir(),
rootDir.get() ? *rootDir.get() / "nix" / "var" / "nix" : getDefaultStateDir(),
"state",
"Directory where Nix stores state."};
"Directory where Nix stores state.",
};
PathSetting logDir{
Setting<std::filesystem::path> logDir{
this,
rootDir.get() ? *rootDir.get() + "/nix/var/log/nix" : getDefaultLogDir(),
rootDir.get() ? *rootDir.get() / "nix" / "var" / "log" / "nix" : getDefaultLogDir(),
"log",
"directory where Nix stores log files."};
"directory where Nix stores log files.",
};
PathSetting realStoreDir{
this, rootDir.get() ? *rootDir.get() + "/nix/store" : storeDir, "real", "Physical path of the Nix store."};
Setting<std::filesystem::path> realStoreDir{
this,
rootDir.get() ? *rootDir.get() / "nix" / "store" : std::filesystem::path{storeDir},
"real",
"Physical path of the Nix store.",
};
};
struct alignas(8) /* Work around ASAN failures on i686-linux. */
@@ -77,7 +84,7 @@ struct alignas(8) /* Work around ASAN failures on i686-linux. */
inline static std::string operationName = "Local Filesystem Store";
const static std::string drvsLogDir;
const static std::filesystem::path drvsLogDir;
LocalFSStore(const Config & params);
@@ -93,27 +100,21 @@ struct alignas(8) /* Work around ASAN failures on i686-linux. */
* @param gcRoot The location of the symlink.
*
* @param storePath The store object being rooted. The symlink will
* point to `toRealPath(store.printStorePath(storePath))`.
* point to `toRealPath(storePath)`.
*
* How the permanent GC root corresponding to this symlink is
* managed is implementation-specific.
*/
virtual Path addPermRoot(const StorePath & storePath, const Path & gcRoot) = 0;
virtual std::filesystem::path addPermRoot(const StorePath & storePath, const std::filesystem::path & gcRoot) = 0;
virtual Path getRealStoreDir()
virtual std::filesystem::path getRealStoreDir()
{
return config.realStoreDir;
}
Path toRealPath(const StorePath & storePath)
std::filesystem::path toRealPath(const StorePath & storePath)
{
return toRealPath(printStorePath(storePath));
}
Path toRealPath(const Path & storePath)
{
assert(isInStore(storePath));
return getRealStoreDir() + "/" + std::string(storePath, storeDir.size() + 1);
return getRealStoreDir() / storePath.to_string();
}
std::optional<std::string> getBuildLogExact(const StorePath & path) override;
@@ -8,14 +8,14 @@ namespace nix {
struct LocalOverlayStoreConfig : virtual LocalStoreConfig
{
LocalOverlayStoreConfig(const StringMap & params)
: LocalOverlayStoreConfig("local-overlay", "", params)
: LocalOverlayStoreConfig("", params)
{
}
LocalOverlayStoreConfig(std::string_view scheme, PathView path, const Params & params)
LocalOverlayStoreConfig(const std::filesystem::path & path, const Params & params)
: StoreConfig(params)
, LocalFSStoreConfig(path, params)
, LocalStoreConfig(scheme, path, params)
, LocalStoreConfig(path, params)
{
}
@@ -31,7 +31,7 @@ struct LocalOverlayStoreConfig : virtual LocalStoreConfig
Must be used as OverlayFS lower layer for this store's store dir.
)"};
PathSetting upperLayer{
const Setting<std::filesystem::path> upperLayer{
(StoreConfig *) this,
"",
"upper-layer",
@@ -53,7 +53,7 @@ struct LocalOverlayStoreConfig : virtual LocalStoreConfig
default, but can be disabled if needed.
)"};
PathSetting remountHook{
const Setting<std::filesystem::path> remountHook{
(StoreConfig *) this,
"",
"remount-hook",
@@ -99,7 +99,7 @@ protected:
* at that file path. It might be stored in the lower layer instead,
* or it might not be part of this store at all.
*/
Path toUpperPath(const StorePath & path) const;
std::filesystem::path toUpperPath(const StorePath & path) const;
friend struct LocalOverlayStore;
};
@@ -184,7 +184,7 @@ private:
* Check which layers the store object exists in to try to avoid
* needing to remount.
*/
void deleteStorePath(const Path & path, uint64_t & bytesFreed, bool isKnownPath) override;
void deleteStorePath(const std::filesystem::path & path, uint64_t & bytesFreed, bool isKnownPath) override;
/**
* Deduplicate by removing store objects from the upper layer that
+19 -15
View File
@@ -82,7 +82,7 @@ struct LocalStoreConfig : std::enable_shared_from_this<LocalStoreConfig>,
{
using LocalFSStoreConfig::LocalFSStoreConfig;
LocalStoreConfig(std::string_view scheme, std::string_view authority, const Params & params);
LocalStoreConfig(const std::filesystem::path & path, const Params & params);
private:
@@ -228,12 +228,12 @@ private:
public:
const Path dbDir;
const Path linksDir;
const Path reservedPath;
const Path schemaPath;
const Path tempRootsDir;
const Path fnTempRoots;
const std::filesystem::path dbDir;
const std::filesystem::path linksDir;
const std::filesystem::path reservedPath;
const std::filesystem::path schemaPath;
const std::filesystem::path tempRootsDir;
const std::filesystem::path fnTempRoots;
private:
@@ -244,7 +244,7 @@ public:
/**
* Hack for build-remote.cc.
*/
PathSet locksHeld;
PathSetNG locksHeld;
/**
* Initialise the local store, upgrading the schema if
@@ -319,7 +319,7 @@ public:
* The weak reference merely is a symlink to `path' from
* /nix/var/nix/gcroots/auto/<hash of `path'>.
*/
void addIndirectRoot(const Path & path) override;
void addIndirectRoot(const std::filesystem::path & path) override;
private:
@@ -353,7 +353,7 @@ public:
* @param isKnownPath true if this is a known store path, false if it's
* garbage/unknown content found in the store directory
*/
virtual void deleteStorePath(const Path & path, uint64_t & bytesFreed, bool isKnownPath);
virtual void deleteStorePath(const std::filesystem::path & path, uint64_t & bytesFreed, bool isKnownPath);
/**
* Optimise the disk space usage of the Nix store by hard-linking
@@ -367,7 +367,7 @@ public:
* Optimise a single store path. Optionally, test the encountered
* symlinks for corruption.
*/
void optimisePath(const Path & path, RepairFlag repair);
void optimisePath(const std::filesystem::path & path, RepairFlag repair);
bool verifyStore(bool checkContents, RepairFlag repair) override;
@@ -481,7 +481,7 @@ private:
PathSet queryValidPathsOld();
ValidPathInfo queryPathInfoOld(const Path & path);
void findRoots(const Path & path, std::filesystem::file_type type, Roots & roots);
void findRoots(const std::filesystem::path & path, std::filesystem::file_type type, Roots & roots);
void findRootsNoTemp(Roots & roots, bool censor);
@@ -492,9 +492,13 @@ private:
typedef boost::unordered_flat_set<ino_t> InodeHash;
InodeHash loadInodeHash();
Strings readDirectoryIgnoringInodes(const Path & path, const InodeHash & inodeHash);
void
optimisePath_(Activity * act, OptimiseStats & stats, const Path & path, InodeHash & inodeHash, RepairFlag repair);
Strings readDirectoryIgnoringInodes(const std::filesystem::path & path, const InodeHash & inodeHash);
void optimisePath_(
Activity * act,
OptimiseStats & stats,
const std::filesystem::path & path,
InodeHash & inodeHash,
RepairFlag repair);
// Internal versions that are not wrapped in retry_sqlite.
bool isValidPath_(State & state, const StorePath & path);
+1 -1
View File
@@ -17,7 +17,7 @@ struct Machine
const StoreReference storeUri;
const StringSet systemTypes;
const std::string sshKey;
const std::filesystem::path sshKey;
const unsigned int maxJobs;
const float speedFactor;
const StringSet supportedFeatures;
@@ -59,7 +59,7 @@ struct NarInfoDiskCache
*/
static ref<NarInfoDiskCache> get(const Settings & settings, SQLiteSettings);
static ref<NarInfoDiskCache> getTest(const Settings & settings, SQLiteSettings, Path dbPath);
static ref<NarInfoDiskCache> getTest(const Settings & settings, SQLiteSettings, std::filesystem::path dbPath);
};
} // namespace nix
@@ -4,6 +4,8 @@
#include <sys/stat.h>
#include <sys/time.h>
#include <filesystem>
#include "nix/util/types.hh"
#include "nix/util/error.hh"
#include "nix/store/config.hh"
@@ -60,11 +62,12 @@ struct CanonicalizePathMetadataOptions
* - the owner and group are set to the Nix user and group, if we're
* running as root. (Unix only.)
*/
void canonicalisePathMetaData(const Path & path, CanonicalizePathMetadataOptions options, InodesSeen & inodesSeen);
void canonicalisePathMetaData(
const std::filesystem::path & path, CanonicalizePathMetadataOptions options, InodesSeen & inodesSeen);
void canonicalisePathMetaData(const Path & path, CanonicalizePathMetadataOptions options);
void canonicalisePathMetaData(const std::filesystem::path & path, CanonicalizePathMetadataOptions options);
void canonicaliseTimestampAndPermissions(const Path & path);
void canonicaliseTimestampAndPermissions(const std::filesystem::path & path);
MakeError(PathInUse, Error);
@@ -11,7 +11,9 @@ struct S3BinaryCacheStoreConfig : HttpBinaryCacheStoreConfig
{
using HttpBinaryCacheStoreConfig::HttpBinaryCacheStoreConfig;
S3BinaryCacheStoreConfig(std::string_view uriScheme, std::string_view bucketName, const Params & params);
S3BinaryCacheStoreConfig(ParsedURL cacheUri, const Params & params);
S3BinaryCacheStoreConfig(std::string_view bucketName, const Params & params);
Setting<std::string> profile{
this,
+2 -2
View File
@@ -15,7 +15,7 @@ struct SSHStoreConfig : std::enable_shared_from_this<SSHStoreConfig>,
using CommonSSHStoreConfig::CommonSSHStoreConfig;
using RemoteStoreConfig::RemoteStoreConfig;
SSHStoreConfig(std::string_view scheme, std::string_view authority, const Params & params);
SSHStoreConfig(const ParsedURL::Authority & authority, const Params & params);
Setting<Strings> remoteProgram{
this, {"nix-daemon"}, "remote-program", "Path to the `nix-daemon` executable on the remote machine."};
@@ -40,7 +40,7 @@ struct SSHStoreConfig : std::enable_shared_from_this<SSHStoreConfig>,
struct MountedSSHStoreConfig : virtual SSHStoreConfig, virtual LocalFSStoreConfig
{
MountedSSHStoreConfig(StringMap params);
MountedSSHStoreConfig(std::string_view scheme, std::string_view host, StringMap params);
MountedSSHStoreConfig(const ParsedURL::Authority & authority, StringMap params);
static const std::string name()
{
+7 -7
View File
@@ -9,7 +9,7 @@
namespace nix {
Strings getNixSshOpts();
OsStrings getNixSshOpts();
class SSHMaster
{
@@ -18,7 +18,7 @@ private:
ParsedURL::Authority authority;
std::string hostnameAndUser;
bool fakeSSH;
const std::string keyFile;
const std::filesystem::path keyFile;
/**
* Raw bytes, not Base64 encoding.
*/
@@ -34,23 +34,23 @@ private:
#ifndef _WIN32 // TODO re-enable on Windows, once we can start processes.
Pid sshMaster;
#endif
Path socketPath;
std::filesystem::path socketPath;
};
Sync<State> state_;
void addCommonSSHOpts(Strings & args);
void addCommonSSHOpts(OsStrings & args);
bool isMasterRunning();
#ifndef _WIN32 // TODO re-enable on Windows, once we can start processes.
Path startMaster();
std::filesystem::path startMaster();
#endif
public:
SSHMaster(
const ParsedURL::Authority & authority,
std::string_view keyFile,
std::filesystem::path keyFile,
std::string_view sshPublicHostKey,
bool useMaster,
bool compress,
@@ -83,7 +83,7 @@ public:
* execute). Will not be used when "fake SSHing" to the local
* machine.
*/
std::unique_ptr<Connection> startCommand(Strings && command, Strings && extraSshArgs = {});
std::unique_ptr<Connection> startCommand(OsStrings && command, OsStrings && extraSshArgs = {});
};
} // namespace nix
+1 -1
View File
@@ -335,7 +335,7 @@ public:
/**
* Follow symlinks until we end up with a path in the Nix store.
*/
Path followLinksToStore(std::string_view path) const;
std::filesystem::path followLinksToStore(std::string_view path) const;
/**
* Same as followLinksToStore(), but apply toStorePath() to the
@@ -56,6 +56,7 @@ struct StoreReference
/**
* General case, a regular `scheme://authority` URL.
* @todo Consider making this pluggable instead of passing through the encoded authority + path.
*/
struct Specified
{
@@ -14,6 +14,7 @@
*/
#include "nix/store/store-api.hh"
#include "nix/util/url.hh"
namespace nix {
@@ -65,7 +66,16 @@ struct Implementations
.uriSchemes = TConfig::uriSchemes(),
.experimentalFeature = TConfig::experimentalFeature(),
.parseConfig = ([](auto scheme, auto uri, auto & params) -> ref<StoreConfig> {
return make_ref<TConfig>(scheme, uri, params);
if constexpr (std::is_constructible_v<TConfig, std::filesystem::path, StoreConfig::Params>) {
std::filesystem::path path = percentDecode(uri);
return make_ref<TConfig>(path.empty() ? std::filesystem::path{} : canonPath(path), params);
} else if constexpr (std::is_constructible_v<TConfig, ParsedURL, StoreConfig::Params>) {
return make_ref<TConfig>(parseURL(concatStrings(scheme, "://", uri)), params);
} else if constexpr (std::is_constructible_v<TConfig, ParsedURL::Authority, StoreConfig::Params>) {
return make_ref<TConfig>(ParsedURL::Authority::parse(uri), params);
} else {
return make_ref<TConfig>(scheme, uri, params);
}
}),
.getConfig = ([]() -> ref<StoreConfig> { return make_ref<TConfig>(Store::Config::Params{}); }),
};
@@ -11,15 +11,10 @@ struct UDSRemoteStoreConfig : std::enable_shared_from_this<UDSRemoteStoreConfig>
virtual LocalFSStoreConfig,
virtual RemoteStoreConfig
{
// TODO(fzakaria): Delete this constructor once moved over to the factory pattern
// outlined in https://github.com/NixOS/nix/issues/10766
using LocalFSStoreConfig::LocalFSStoreConfig;
using RemoteStoreConfig::RemoteStoreConfig;
/**
* @param authority is the socket path.
*/
UDSRemoteStoreConfig(std::string_view scheme, std::string_view authority, const Params & params);
UDSRemoteStoreConfig(const std::filesystem::path & path, const Params & params);
UDSRemoteStoreConfig(const Params & params);
@@ -36,7 +31,7 @@ struct UDSRemoteStoreConfig : std::enable_shared_from_this<UDSRemoteStoreConfig>
* The default is `settings.nixDaemonSocketFile`, but we don't write
* that below, instead putting in the constructor.
*/
Path path;
std::filesystem::path path;
static StringSet uriSchemes()
{
@@ -79,7 +74,7 @@ struct UDSRemoteStore : virtual IndirectRootStore, virtual RemoteStore
* owned managed by the client's user account, and the server makes
* the indirect symlink.
*/
void addIndirectRoot(const Path & path) override;
void addIndirectRoot(const std::filesystem::path & path) override;
private:
+9 -9
View File
@@ -2,28 +2,28 @@
namespace nix {
void IndirectRootStore::makeSymlink(const Path & link, const Path & target)
void IndirectRootStore::makeSymlink(const std::filesystem::path & link, const std::filesystem::path & target)
{
/* Create directories up to `gcRoot'. */
createDirs(dirOf(link));
createDirs(link.parent_path());
/* Create the new symlink. */
Path tempLink = fmt("%1%.tmp-%2%-%3%", link, getpid(), rand());
auto tempLink = std::filesystem::path(link) += fmt(".tmp-%1%-%2%", getpid(), rand());
createSymlink(target, tempLink);
/* Atomically replace the old one. */
std::filesystem::rename(tempLink, link);
}
Path IndirectRootStore::addPermRoot(const StorePath & storePath, const Path & _gcRoot)
std::filesystem::path IndirectRootStore::addPermRoot(const StorePath & storePath, const std::filesystem::path & _gcRoot)
{
Path gcRoot(canonPath(_gcRoot));
auto gcRoot = canonPath(_gcRoot);
if (isInStore(gcRoot))
if (isInStore(gcRoot.string()))
throw Error(
"creating a garbage collector root (%1%) in the Nix store is forbidden "
"(are you running nix-build inside the store?)",
gcRoot);
PathFmt(gcRoot));
/* Register this root with the garbage collector, if it's
running. This should be superfluous since the caller should
@@ -33,8 +33,8 @@ Path IndirectRootStore::addPermRoot(const StorePath & storePath, const Path & _g
/* Don't clobber the link if it already exists and doesn't
point to the Nix store. */
if (pathExists(gcRoot) && (!std::filesystem::is_symlink(gcRoot) || !isInStore(readLink(gcRoot))))
throw Error("cannot create symlink '%1%'; already exists", gcRoot);
if (pathExists(gcRoot) && (!std::filesystem::is_symlink(gcRoot) || !isInStore(readLink(gcRoot).string())))
throw Error("cannot create symlink %1%; already exists", PathFmt(gcRoot));
makeSymlink(gcRoot, printStorePath(storePath));
addIndirectRoot(gcRoot);
+3 -3
View File
@@ -18,9 +18,9 @@
namespace nix {
LegacySSHStoreConfig::LegacySSHStoreConfig(std::string_view scheme, std::string_view authority, const Params & params)
LegacySSHStoreConfig::LegacySSHStoreConfig(const ParsedURL::Authority & authority, const Params & params)
: StoreConfig(params)
, CommonSSHStoreConfig(scheme, ParsedURL::Authority::parse(authority), params)
, CommonSSHStoreConfig(authority, params)
{
}
@@ -62,7 +62,7 @@ ref<LegacySSHStore::Connection> LegacySSHStore::openConnection()
command.push_back("--store");
command.push_back(config->remoteStore.get());
}
conn->sshConn = master.startCommand(std::move(command), std::list{config->extraSshArgs});
conn->sshConn = master.startCommand(toOsStrings(std::move(command)), toOsStrings(std::list{config->extraSshArgs}));
if (config->connPipeSize) {
conn->sshConn->trySetBufferSize(*config->connPipeSize);
}
+14 -19
View File
@@ -3,34 +3,30 @@
#include "nix/store/nar-info-disk-cache.hh"
#include "nix/util/signals.hh"
#include "nix/store/store-registration.hh"
#include "nix/util/url.hh"
#include <atomic>
namespace nix {
static std::filesystem::path checkBinaryCachePath(const std::filesystem::path & root, std::string_view path)
static std::filesystem::path checkBinaryCachePath(const std::filesystem::path & root, const std::string & path)
{
/* Note: these checks aren't complete and don't guard against symlink shenanigans. */
auto p = std::filesystem::path(path);
auto p = std::filesystem::path(requireCString(path));
if (p.empty())
throw Error("local binary cache path must not be empty");
if (p.is_absolute())
/* Never happens unless the caller is messed up. */
throw Error("binary cache path '%s' must be relative", path);
throw Error("local binary cache path '%s' must not be absolute", path);
auto result = (root / p).lexically_normal();
for (const auto & segment : p) {
if (segment.native() == OS_STR("..") || segment.native() == OS_STR("."))
throw Error("local binary cache path '%s' must not contain '..' or '.' segments", path);
}
/* NB: lexically_normal() only does textual normalization and does
not resolve symlinks. This is acceptable because store/substituter
paths are already trusted, and this check is defense-in-depth
against ".." traversal. */
if (!isInDir(result, root.lexically_normal()))
throw Error("binary cache path '%s' escapes cache directory", path);
return result;
return root / p.relative_path();
}
LocalBinaryCacheStoreConfig::LocalBinaryCacheStoreConfig(
std::string_view scheme, PathView binaryCacheDir, const StoreReference::Params & params)
const std::filesystem::path & binaryCacheDir, const StoreReference::Params & params)
: Store::Config{params}
, BinaryCacheStoreConfig{params}
, binaryCacheDir(binaryCacheDir)
@@ -77,15 +73,13 @@ protected:
void upsertFile(
const std::string & path, RestartableSource & source, const std::string & mimeType, uint64_t sizeHint) override
{
/* TODO: Maybe use RestoreSink for writing stuff? It would have to gain the ability to write files
atomically (maybe with O_TMPFILE + linkat + AT_EMPTY_PATH when available or fallback to rename). */
auto path2 = checkBinaryCachePath(config->binaryCacheDir, path);
static std::atomic<int> counter{0};
createDirs(path2.parent_path());
auto tmp = path2;
tmp += fmt(".tmp.%d.%d", getpid(), ++counter);
AutoDelete del(tmp, false);
writeFile(tmp, source);
writeFile(tmp, source); /* TODO: Don't follow symlinks? */
std::filesystem::rename(tmp, path2);
del.cancel();
}
@@ -93,6 +87,7 @@ protected:
void getFile(const std::string & path, Sink & sink) override
{
try {
/* TODO: Don't follow symlinks? */
readFile(checkBinaryCachePath(config->binaryCacheDir, path), sink);
} catch (SystemError & e) {
if (e.is(std::errc::no_such_file_or_directory))
+11 -12
View File
@@ -8,17 +8,17 @@
namespace nix {
Path LocalFSStoreConfig::getDefaultStateDir()
std::filesystem::path LocalFSStoreConfig::getDefaultStateDir()
{
return settings.nixStateDir.string();
return settings.nixStateDir;
}
Path LocalFSStoreConfig::getDefaultLogDir()
std::filesystem::path LocalFSStoreConfig::getDefaultLogDir()
{
return settings.getLogFileSettings().nixLogDir.string();
return settings.getLogFileSettings().nixLogDir;
}
LocalFSStoreConfig::LocalFSStoreConfig(PathView rootDir, const Params & params)
LocalFSStoreConfig::LocalFSStoreConfig(const std::filesystem::path & rootDir, const Params & params)
: StoreConfig(params)
/* Default `?root` from `rootDir` if non set
* NOTE: We would like to just do rootDir.set(...), which would take care of
@@ -29,8 +29,7 @@ LocalFSStoreConfig::LocalFSStoreConfig(PathView rootDir, const Params & params)
* manually repeat the same normalization logic.
*/
, rootDir{makeRootDirSetting(
*this,
!rootDir.empty() && params.count("root") == 0 ? std::optional<Path>{canonPath(rootDir)} : std::nullopt)}
*this, !rootDir.empty() && params.count("root") == 0 ? std::optional{canonPath(rootDir)} : std::nullopt)}
{
}
@@ -112,7 +111,7 @@ std::shared_ptr<SourceAccessor> LocalFSStore::getFSAccessor(const StorePath & pa
return std::make_shared<PosixSourceAccessor>(std::move(absPath));
}
const std::string LocalFSStore::drvsLogDir = "drvs";
const std::filesystem::path LocalFSStore::drvsLogDir = "drvs";
std::optional<std::string> LocalFSStore::getBuildLogExact(const StorePath & path)
{
@@ -120,10 +119,10 @@ std::optional<std::string> LocalFSStore::getBuildLogExact(const StorePath & path
for (int j = 0; j < 2; j++) {
Path logPath =
j == 0 ? fmt("%s/%s/%s/%s", config.logDir.get(), drvsLogDir, baseName.substr(0, 2), baseName.substr(2))
: fmt("%s/%s/%s", config.logDir.get(), drvsLogDir, baseName);
Path logBz2Path = logPath + ".bz2";
auto logPath = config.logDir.get()
/ (j == 0 ? drvsLogDir / baseName.substr(0, 2) / baseName.substr(2) : drvsLogDir / baseName);
auto logBz2Path = logPath;
logBz2Path += ".bz2";
if (pathExists(logPath))
return readFile(logPath);
+2 -2
View File
@@ -128,8 +128,8 @@ Roots findRuntimeRootsUnchecked(const StoreDirConfig & config)
if (getEnv("_NIX_TEST_NO_LSOF") != "1") {
try {
boost::regex lsofRegex(R"(^n(/.*)$)");
auto lsofLines =
tokenizeString<std::vector<std::string>>(runProgram(LSOF, true, {"-n", "-w", "-F", "n"}), "\n");
auto lsofLines = tokenizeString<std::vector<std::string>>(
runProgram(LSOF, true, {OS_STR("-n"), OS_STR("-w"), OS_STR("-F"), OS_STR("n")}), "\n");
for (const auto & line : lsofLines) {
boost::smatch match;
if (boost::regex_match(line, match, lsofRegex))
+18 -18
View File
@@ -2,6 +2,7 @@
#include "nix/store/local-overlay-store.hh"
#include "nix/util/callback.hh"
#include "nix/util/os-string.hh"
#include "nix/store/realisation.hh"
#include "nix/util/processes.hh"
#include "nix/util/url.hh"
@@ -33,9 +34,9 @@ StoreReference LocalOverlayStoreConfig::getReference() const
};
}
Path LocalOverlayStoreConfig::toUpperPath(const StorePath & path) const
std::filesystem::path LocalOverlayStoreConfig::toUpperPath(const StorePath & path) const
{
return upperLayer + "/" + path.to_string();
return upperLayer.get() / path.to_string();
}
LocalOverlayStore::LocalOverlayStore(ref<const Config> config)
@@ -49,7 +50,7 @@ LocalOverlayStore::LocalOverlayStore(ref<const Config> config)
std::smatch match;
std::string mountInfo;
auto mounts = readFile(std::filesystem::path{"/proc/self/mounts"});
auto regex = std::regex(R"((^|\n)overlay )" + config->realStoreDir.get() + R"( .*(\n|$))");
auto regex = std::regex(R"((^|\n)overlay )" + config->realStoreDir.get().string() + R"( .*(\n|$))");
// Mount points can be stacked, so there might be multiple matching entries.
// Loop until the last match, which will be the current state of the mount point.
@@ -58,16 +59,16 @@ LocalOverlayStore::LocalOverlayStore(ref<const Config> config)
mounts = match.suffix();
}
auto checkOption = [&](std::string option, std::string value) {
return std::regex_search(mountInfo, std::regex("\\b" + option + "=" + value + "( |,)"));
auto checkOption = [&](std::string_view option, const std::filesystem::path & value) {
return std::regex_search(mountInfo, std::regex("\\b" + option + "=" + value.string() + "( |,)"));
};
auto expectedLowerDir = lowerStore->config.realStoreDir.get();
if (!checkOption("lowerdir", expectedLowerDir) || !checkOption("upperdir", config->upperLayer)) {
debug("expected lowerdir: %s", expectedLowerDir);
debug("expected upperdir: %s", config->upperLayer);
if (!checkOption("lowerdir", expectedLowerDir) || !checkOption("upperdir", config->upperLayer.get())) {
debug("expected lowerdir: %s", PathFmt(lowerStore->config.realStoreDir.get()));
debug("expected upperdir: %s", PathFmt(config->upperLayer.get()));
debug("actual mount: %s", mountInfo);
throw Error("overlay filesystem '%s' mounted incorrectly", config->realStoreDir.get());
throw Error("overlay filesystem %s mounted incorrectly", PathFmt(config->realStoreDir.get()));
}
}
}
@@ -204,19 +205,18 @@ void LocalOverlayStore::collectGarbage(const GCOptions & options, GCResults & re
remountIfNecessary();
}
void LocalOverlayStore::deleteStorePath(const Path & path, uint64_t & bytesFreed, bool isKnownPath)
void LocalOverlayStore::deleteStorePath(const std::filesystem::path & path, uint64_t & bytesFreed, bool isKnownPath)
{
auto mergedDir = config->realStoreDir.get() + "/";
if (path.substr(0, mergedDir.length()) != mergedDir) {
warn("local-overlay: unexpected gc path '%s' ", path);
if (path.parent_path() != config->realStoreDir.get()) {
warn("local-overlay: unexpected gc path %s", PathFmt(path));
return;
}
StorePath storePath = {path.substr(mergedDir.length())};
StorePath storePath = {path.filename().string()};
auto upperPath = config->toUpperPath(storePath);
if (pathExists(upperPath)) {
debug("upper exists: %s", path);
debug("upper exists: %s", PathFmt(path));
if (lowerStore->isValidPath(storePath)) {
debug("lower exists: %s", storePath.to_string());
// Path also exists in lower store.
@@ -260,7 +260,7 @@ LocalStore::VerificationResult LocalOverlayStore::verifyAllValidPaths(RepairFlag
StorePathSet done;
auto existsInStoreDir = [&](const StorePath & storePath) {
return pathExists(config->realStoreDir.get() + "/" + storePath.to_string());
return pathExists((config->realStoreDir.get() / storePath.to_string()).string());
};
bool errors = false;
@@ -281,9 +281,9 @@ void LocalOverlayStore::remountIfNecessary()
return;
if (config->remountHook.get().empty()) {
warn("'%s' needs remounting, set remount-hook to do this automatically", config->realStoreDir.get());
warn("%s needs remounting, set remount-hook to do this automatically", PathFmt(config->realStoreDir.get()));
} else {
runProgram(config->remountHook, false, {config->realStoreDir});
runProgram(config->remountHook.get(), false, {config->realStoreDir.get().native()});
}
_remountRequired = false;
+41 -34
View File
@@ -56,9 +56,9 @@
namespace nix {
LocalStoreConfig::LocalStoreConfig(std::string_view scheme, std::string_view authority, const Params & params)
LocalStoreConfig::LocalStoreConfig(const std::filesystem::path & path, const Params & params)
: StoreConfig(params)
, LocalFSStoreConfig(authority, params)
, LocalFSStoreConfig(path, params)
{
}
@@ -119,12 +119,12 @@ LocalStore::LocalStore(ref<const Config> config)
, LocalFSStore{*config}
, config{config}
, _state(make_ref<Sync<State>>())
, dbDir(config->stateDir + "/db")
, linksDir(config->realStoreDir + "/.links")
, reservedPath(dbDir + "/reserved")
, schemaPath(dbDir + "/schema")
, tempRootsDir(config->stateDir + "/temproots")
, fnTempRoots(fmt("%s/%d", tempRootsDir, getpid()))
, dbDir(config->stateDir.get() / "db")
, linksDir(config->realStoreDir.get() / ".links")
, reservedPath(dbDir / "reserved")
, schemaPath(dbDir / "schema")
, tempRootsDir(config->stateDir.get() / "temproots")
, fnTempRoots(tempRootsDir / std::to_string(getpid()))
{
auto state(_state->lock());
state->stmts = std::make_unique<State::Stmts>();
@@ -137,16 +137,19 @@ LocalStore::LocalStore(ref<const Config> config)
makeStoreWritable();
}
createDirs(linksDir);
Path profilesDir = config->stateDir + "/profiles";
auto profilesDir = config->stateDir.get() / "profiles";
createDirs(profilesDir);
createDirs(tempRootsDir);
createDirs(dbDir);
Path gcRootsDir = config->stateDir + "/gcroots";
auto gcRootsDir = config->stateDir.get() / "gcroots";
const auto & localSettings = config->getLocalSettings();
const auto & gcSettings = localSettings.getGCSettings();
createDirs(gcRootsDir);
if (!pathExists(gcRootsDir)) {
createDirs(gcRootsDir);
replaceSymlink(profilesDir, gcRootsDir / "profiles");
}
for (auto & perUserDir : {profilesDir + "/per-user", gcRootsDir + "/per-user"}) {
for (auto & perUserDir : {profilesDir / "per-user", gcRootsDir / "per-user"}) {
createDirs(perUserDir);
if (!config->readOnly) {
// Skip chmod call if the directory already has the correct permissions (0755).
@@ -172,7 +175,7 @@ LocalStore::LocalStore(ref<const Config> config)
if (st.st_uid != 0 || st.st_gid != gr->gr_gid || (st.st_mode & ~S_IFMT) != perm) {
if (chown(config->realStoreDir.get().c_str(), 0, gr->gr_gid) == -1)
throw SysError("changing ownership of path '%1%'", config->realStoreDir);
throw SysError("changing ownership of path %s", PathFmt(config->realStoreDir.get()));
chmod(config->realStoreDir.get(), perm);
}
}
@@ -201,7 +204,7 @@ LocalStore::LocalStore(ref<const Config> config)
auto st = maybeStat(reservedPath);
if (!st || st->st_size != gcSettings.reservedSize) {
AutoCloseFD fd = toDescriptor(open(
reservedPath.c_str(),
reservedPath.string().c_str(),
O_WRONLY | O_CREAT
#ifndef _WIN32
| O_CLOEXEC
@@ -230,9 +233,9 @@ LocalStore::LocalStore(ref<const Config> config)
/* Acquire the big fat lock in shared mode to make sure that no
schema upgrade is in progress. */
if (!config->readOnly) {
Path globalLockPath = dbDir + "/big-lock";
auto globalLockPath = dbDir / "big-lock";
try {
globalLock = openLockFile(globalLockPath.c_str(), true);
globalLock = openLockFile(globalLockPath, true);
} catch (SystemError & e) {
if (e.is(std::errc::permission_denied) || e.is(std::errc::operation_not_permitted)) {
e.addTrace(
@@ -392,9 +395,9 @@ LocalStore::LocalStore(ref<const Config> config)
AutoCloseFD LocalStore::openGCLock()
{
Path fnGCLock = config->stateDir + "/gc.lock";
auto fnGCLock = config->stateDir.get() / "gc.lock";
auto fdGCLock = open(
fnGCLock.c_str(),
fnGCLock.string().c_str(),
O_RDWR | O_CREAT
#ifndef _WIN32
| O_CLOEXEC
@@ -402,11 +405,11 @@ AutoCloseFD LocalStore::openGCLock()
,
0600);
if (!fdGCLock)
throw SysError("opening global GC lock '%1%'", fnGCLock);
throw SysError("opening global GC lock %1%", PathFmt(fnGCLock));
return toDescriptor(fdGCLock);
}
void LocalStore::deleteStorePath(const Path & path, uint64_t & bytesFreed, bool isKnownPath)
void LocalStore::deleteStorePath(const std::filesystem::path & path, uint64_t & bytesFreed, bool isKnownPath)
{
try {
deletePath(path, bytesFreed);
@@ -414,15 +417,15 @@ void LocalStore::deleteStorePath(const Path & path, uint64_t & bytesFreed, bool
if (config->ignoreGcDeleteFailure) {
logWarning(
{.msg = HintFmt(
isKnownPath ? "ignoring failure to remove store path '%1%': %2%"
: "ignoring failure to remove garbage in store directory '%1%': %2%",
path,
isKnownPath ? "ignoring failure to remove store path %1%: %2%"
: "ignoring failure to remove garbage in store directory %1%: %2%",
PathFmt(path),
e.info().msg)});
} else {
e.addTrace(
{},
isKnownPath ? "While deleting store path '%1%'" : "While deleting garbage in store directory '%1%'",
path);
isKnownPath ? "While deleting store path %1%" : "While deleting garbage in store directory %1%",
PathFmt(path));
throw;
}
}
@@ -447,7 +450,7 @@ LocalStore::~LocalStore()
auto fdTempRoots(_fdTempRoots.lock());
if (*fdTempRoots) {
fdTempRoots->close();
unlink(fnTempRoots.c_str());
tryUnlink(fnTempRoots);
}
} catch (...) {
ignoreExceptionInDestructor();
@@ -465,11 +468,13 @@ StoreReference LocalStoreConfig::getReference() const
/* Back-compatibility kludge. Tools like nix-output-monitor expect 'local'
and can't parse 'local://'. */
if (params.empty())
/* TODO: Add the rootDir here as the authority? */
return {.variant = StoreReference::Local{}};
return {
.variant =
StoreReference::Specified{
.scheme = *uriSchemes().begin(),
/* TODO: Add the rootDir here as the authority? */
},
.params = std::move(params),
};
@@ -487,7 +492,7 @@ int LocalStore::getSchema()
auto s = readFile(schemaPath);
auto n = string2Int<int>(s);
if (!n)
throw Error("'%1%' is corrupt", schemaPath);
throw Error("%1% is corrupt", PathFmt(schemaPath));
curSchema = *n;
}
return curSchema;
@@ -499,15 +504,15 @@ void LocalStore::openDB(State & state, bool create)
throw Error("cannot create database while in read-only mode");
}
if (access(dbDir.c_str(), R_OK | (config->readOnly ? 0 : W_OK)))
throw SysError("Nix database directory '%1%' is not writable", dbDir);
if (access(dbDir.string().c_str(), R_OK | (config->readOnly ? 0 : W_OK)))
throw SysError("Nix database directory %1% is not writable", PathFmt(dbDir));
/* Open the Nix database. */
auto & db(state.db);
auto openMode = config->readOnly ? SQLiteOpenMode::Immutable
: create ? SQLiteOpenMode::Normal
: SQLiteOpenMode::NoCreate;
state.db = SQLite(std::filesystem::path(dbDir) / "db.sqlite", {.mode = openMode, .useWAL = settings.useSQLiteWAL});
state.db = SQLite(dbDir / "db.sqlite", {.mode = openMode, .useWAL = settings.useSQLiteWAL});
#ifdef __CYGWIN__
/* The cygwin version of sqlite3 has a patch which calls
@@ -620,7 +625,7 @@ void LocalStore::makeStoreWritable()
if (stat.f_flag & ST_RDONLY) {
if (mount(0, config->realStoreDir.get().c_str(), "none", MS_REMOUNT | MS_BIND, 0) == -1)
throw SysError("remounting %1% writable", config->realStoreDir);
throw SysError("remounting %s writable", PathFmt(config->realStoreDir.get()));
}
#endif
}
@@ -1587,14 +1592,16 @@ void LocalStore::addBuildLog(const StorePath & drvPath, std::string_view log)
auto baseName = drvPath.to_string();
auto logPath = fmt("%s/%s/%s/%s.bz2", config->logDir, drvsLogDir, baseName.substr(0, 2), baseName.substr(2));
auto logPath =
config->logDir.get() / drvsLogDir / baseName.substr(0, 2) / (std::string(baseName.substr(2)) + ".bz2");
if (pathExists(logPath))
return;
createDirs(dirOf(logPath));
createDirs(logPath.parent_path());
auto tmpFile = fmt("%s.tmp.%d", logPath, getpid());
auto tmpFile = logPath;
tmpFile += ".tmp." + std::to_string(getpid());
writeFile(tmpFile, compress(CompressionAlgo::bzip2, log));
+2 -2
View File
@@ -69,8 +69,8 @@ StoreReference Machine::completeStoreReference() const
}
if (generic && (generic->scheme == "ssh" || generic->scheme == "ssh-ng")) {
if (sshKey != "")
storeUri.params["ssh-key"] = sshKey;
if (!sshKey.empty())
storeUri.params["ssh-key"] = sshKey.string();
if (sshPublicHostKey != "")
storeUri.params["base64-ssh-public-host-key"] = sshPublicHostKey;
}
+4 -11
View File
@@ -115,17 +115,10 @@ boost = dependency(
# put in `deps_other`.
deps_other += boost
curl = dependency('libcurl', 'curl', version : '>= 7.75.0')
if curl.version().version_compare('>=8.16.0') and curl.version().version_compare(
'<8.17.0',
)
# Out of precaution, avoid building with libcurl version that suffer from https://github.com/curl/curl/issues/19334.
error(
'curl @0@ has issues with write pausing, please use libcurl < 8.16 or >= 8.17, see https://github.com/curl/curl/issues/19334'.format(
curl.version(),
),
)
endif
# This is quite new, but curl has a bunch of known issues with write pausing and decompression.
# Please use libcurl >= 8.17. See https://github.com/curl/curl/issues/19334, https://github.com/curl/curl/issues/16280, https://github.com/curl/curl/issues/16955 if in doubt.
# Patch out this check at your own risk.
curl = dependency('libcurl', 'curl', version : '>= 8.17.0')
deps_private += curl
+4 -3
View File
@@ -84,12 +84,12 @@ struct NarInfoDiskCacheImpl : NarInfoDiskCache
NarInfoDiskCacheImpl(
const Settings & settings,
SQLiteSettings sqliteSettings,
Path dbPath = (getCacheDir() / "binary-cache-v7.sqlite").string())
std::filesystem::path dbPath = getCacheDir() / "binary-cache-v7.sqlite")
: NarInfoDiskCache{settings}
{
auto state(_state.lock());
createDirs(dirOf(dbPath));
createDirs(dbPath.parent_path());
state->db = SQLite(dbPath, SQLite::Settings{sqliteSettings});
@@ -377,7 +377,8 @@ ref<NarInfoDiskCache> NarInfoDiskCache::get(const Settings & settings, SQLiteSet
return cache;
}
ref<NarInfoDiskCache> NarInfoDiskCache::getTest(const Settings & settings, SQLiteSettings sqliteSettings, Path dbPath)
ref<NarInfoDiskCache>
NarInfoDiskCache::getTest(const Settings & settings, SQLiteSettings sqliteSettings, std::filesystem::path dbPath)
{
return make_ref<NarInfoDiskCacheImpl>(settings, sqliteSettings, dbPath);
}
+28 -28
View File
@@ -18,7 +18,7 @@
namespace nix {
static void makeWritable(const Path & path)
static void makeWritable(const std::filesystem::path & path)
{
auto st = lstat(path);
chmod(path, st.st_mode | S_IWUSR);
@@ -26,10 +26,10 @@ static void makeWritable(const Path & path)
struct MakeReadOnly
{
Path path;
std::filesystem::path path;
MakeReadOnly(const PathView path)
: path(path)
MakeReadOnly(std::filesystem::path path)
: path(std::move(path))
{
}
@@ -37,8 +37,8 @@ struct MakeReadOnly
{
try {
/* This will make the path read-only. */
if (path != "")
canonicaliseTimestampAndPermissions(path);
if (!path.empty())
canonicaliseTimestampAndPermissions(path.string());
} catch (...) {
ignoreExceptionInDestructor();
}
@@ -50,9 +50,9 @@ LocalStore::InodeHash LocalStore::loadInodeHash()
debug("loading hash inodes in memory");
InodeHash inodeHash;
AutoCloseDir dir(opendir(linksDir.c_str()));
AutoCloseDir dir(opendir(linksDir.string().c_str()));
if (!dir)
throw SysError("opening directory '%1%'", linksDir);
throw SysError("opening directory %1%", PathFmt(linksDir));
struct dirent * dirent;
while (errno = 0, dirent = readdir(dir.get())) { /* sic */
@@ -61,20 +61,20 @@ LocalStore::InodeHash LocalStore::loadInodeHash()
inodeHash.insert(dirent->d_ino);
}
if (errno)
throw SysError("reading directory '%1%'", linksDir);
throw SysError("reading directory %1%", PathFmt(linksDir));
printMsg(lvlTalkative, "loaded %1% hash inodes", inodeHash.size());
return inodeHash;
}
Strings LocalStore::readDirectoryIgnoringInodes(const Path & path, const InodeHash & inodeHash)
Strings LocalStore::readDirectoryIgnoringInodes(const std::filesystem::path & path, const InodeHash & inodeHash)
{
Strings names;
AutoCloseDir dir(opendir(path.c_str()));
AutoCloseDir dir(opendir(path.string().c_str()));
if (!dir)
throw SysError("opening directory '%1%'", path);
throw SysError("opening directory %s", PathFmt(path));
struct dirent * dirent;
while (errno = 0, dirent = readdir(dir.get())) { /* sic */
@@ -91,13 +91,13 @@ Strings LocalStore::readDirectoryIgnoringInodes(const Path & path, const InodeHa
names.push_back(name);
}
if (errno)
throw SysError("reading directory '%1%'", path);
throw SysError("reading directory %s", PathFmt(path));
return names;
}
void LocalStore::optimisePath_(
Activity * act, OptimiseStats & stats, const Path & path, InodeHash & inodeHash, RepairFlag repair)
Activity * act, OptimiseStats & stats, const std::filesystem::path & path, InodeHash & inodeHash, RepairFlag repair)
{
checkInterrupt();
@@ -110,8 +110,8 @@ void LocalStore::optimisePath_(
See https://github.com/NixOS/nix/issues/1443 and
https://github.com/NixOS/nix/pull/2230 for more discussion. */
if (std::regex_search(path, std::regex("\\.app/Contents/.+$"))) {
debug("'%1%' is not allowed to be linked in macOS", path);
if (std::regex_search(path.string(), std::regex("\\.app/Contents/.+$"))) {
debug("%s is not allowed to be linked in macOS", PathFmt(path));
return;
}
#endif
@@ -119,7 +119,7 @@ void LocalStore::optimisePath_(
if (S_ISDIR(st.st_mode)) {
Strings names = readDirectoryIgnoringInodes(path, inodeHash);
for (auto & i : names)
optimisePath_(act, stats, path + "/" + i, inodeHash, repair);
optimisePath_(act, stats, path / i, inodeHash, repair);
return;
}
@@ -136,13 +136,13 @@ void LocalStore::optimisePath_(
NixOS (example: $fontconfig/var/cache being modified). Skip
those files. FIXME: check the modification time. */
if (S_ISREG(st.st_mode) && (st.st_mode & S_IWUSR)) {
warn("skipping suspicious writable file '%1%'", path);
warn("skipping suspicious writable file '%s'", PathFmt(path));
return;
}
/* This can still happen on top-level files. */
if (st.st_nlink > 1 && inodeHash.count(st.st_ino)) {
debug("'%s' is already linked, with %d other file(s)", path, st.st_nlink - 2);
debug("%s is already linked, with %d other file(s)", PathFmt(path), st.st_nlink - 2);
return;
}
@@ -157,12 +157,12 @@ void LocalStore::optimisePath_(
the contents of the target (which may not even exist). */
Hash hash = ({
hashPath(
{make_ref<PosixSourceAccessor>(), CanonPath(path)},
{make_ref<PosixSourceAccessor>(), CanonPath(path.string())},
FileSerialisationMethod::NixArchive,
HashAlgorithm::SHA256)
.hash;
});
debug("'%1%' has hash '%2%'", path, hash.to_string(HashFormat::Nix32, true));
debug("%s has hash '%s'", PathFmt(path), hash.to_string(HashFormat::Nix32, true));
/* Check if this is a known hash. */
std::filesystem::path linkPath = std::filesystem::path{linksDir} / hash.to_string(HashFormat::Nix32, false);
@@ -203,12 +203,12 @@ void LocalStore::optimisePath_(
just effectively disable deduplication of this
file.
*/
printInfo("cannot link %s to '%s': %s", PathFmt(linkPath), path, e.code().message());
printInfo("cannot link %s to '%s': %s", PathFmt(linkPath), PathFmt(path), e.code().message());
return;
}
else
throw SystemError(e.code(), "creating hard link from %1% to %2%", PathFmt(linkPath), path);
throw SystemError(e.code(), "creating hard link from %1% to %2%", PathFmt(linkPath), PathFmt(path));
}
}
@@ -226,14 +226,14 @@ void LocalStore::optimisePath_(
/* Make the containing directory writable, but only if it's not
the store itself (we don't want or need to mess with its
permissions). */
const Path dirOfPath(dirOf(path));
const auto dirOfPath = path.parent_path();
bool mustToggle = dirOfPath != config->realStoreDir.get();
if (mustToggle)
makeWritable(dirOfPath);
/* When we're done, make the directory read-only again and reset
its timestamp back to 0. */
MakeReadOnly makeReadOnly(mustToggle ? dirOfPath : "");
MakeReadOnly makeReadOnly(mustToggle ? dirOfPath : std::filesystem::path{});
std::filesystem::path tempLink = makeTempPath(config->realStoreDir.get(), ".tmp-link");
@@ -270,7 +270,7 @@ void LocalStore::optimisePath_(
debug("%s has reached maximum number of links", PathFmt(linkPath));
return;
}
throw SystemError(e.code(), "renaming %1% to %2%", PathFmt(tempLink), path);
throw SystemError(e.code(), "renaming %1% to %2%", PathFmt(tempLink), PathFmt(path));
}
stats.filesLinked++;
@@ -304,7 +304,7 @@ void LocalStore::optimiseStore(OptimiseStats & stats)
continue; /* path was GC'ed, probably */
{
Activity act(*logger, lvlTalkative, actUnknown, fmt("optimising path '%s'", printStorePath(i)));
optimisePath_(&act, stats, config->realStoreDir + "/" + std::string(i.to_string()), inodeHash, NoRepair);
optimisePath_(&act, stats, config->realStoreDir.get() / i.to_string(), inodeHash, NoRepair);
}
done++;
act.progress(done, paths.size());
@@ -320,7 +320,7 @@ void LocalStore::optimiseStore()
printInfo("%s freed by hard-linking %d files", renderSize(stats.bytesFreed), stats.filesLinked);
}
void LocalStore::optimisePath(const Path & path, RepairFlag repair)
void LocalStore::optimisePath(const std::filesystem::path & path, RepairFlag repair)
{
OptimiseStats stats;
InodeHash inodeHash;
+15 -14
View File
@@ -15,7 +15,7 @@ namespace nix {
const time_t mtimeStore = 1; /* 1 second into the epoch */
static void canonicaliseTimestampAndPermissions(const Path & path, const PosixStat & st)
static void canonicaliseTimestampAndPermissions(const std::filesystem::path & path, const PosixStat & st)
{
if (!S_ISLNK(st.st_mode)) {
@@ -36,13 +36,13 @@ static void canonicaliseTimestampAndPermissions(const Path & path, const PosixSt
#endif
}
void canonicaliseTimestampAndPermissions(const Path & path)
void canonicaliseTimestampAndPermissions(const std::filesystem::path & path)
{
canonicaliseTimestampAndPermissions(path, lstat(path));
}
static void
canonicalisePathMetaData_(const Path & path, CanonicalizePathMetadataOptions options, InodesSeen & inodesSeen)
static void canonicalisePathMetaData_(
const std::filesystem::path & path, CanonicalizePathMetadataOptions options, InodesSeen & inodesSeen)
{
checkInterrupt();
@@ -52,7 +52,7 @@ canonicalisePathMetaData_(const Path & path, CanonicalizePathMetadataOptions opt
setattrlist() to remove other attributes as well. */
if (lchflags(path.c_str(), 0)) {
if (errno != ENOTSUP)
throw SysError("clearing flags of path '%1%'", path);
throw SysError("clearing flags of path %1%", PathFmt(path));
}
#endif
@@ -60,7 +60,7 @@ canonicalisePathMetaData_(const Path & path, CanonicalizePathMetadataOptions opt
/* Really make sure that the path is of a supported type. */
if (!(S_ISREG(st.st_mode) || S_ISDIR(st.st_mode) || S_ISLNK(st.st_mode)))
throw Error("file '%1%' has an unsupported type", path);
throw Error("file %1% has an unsupported type", PathFmt(path));
#if NIX_SUPPORT_ACL
/* Remove extended attributes / ACLs. */
@@ -68,18 +68,18 @@ canonicalisePathMetaData_(const Path & path, CanonicalizePathMetadataOptions opt
if (eaSize < 0) {
if (errno != ENOTSUP && errno != ENODATA)
throw SysError("querying extended attributes of '%s'", path);
throw SysError("querying extended attributes of %s", PathFmt(path));
} else if (eaSize > 0) {
std::vector<char> eaBuf(eaSize);
if ((eaSize = llistxattr(path.c_str(), eaBuf.data(), eaBuf.size())) < 0)
throw SysError("querying extended attributes of '%s'", path);
throw SysError("querying extended attributes of %s", PathFmt(path));
for (auto & eaName : tokenizeString<Strings>(std::string(eaBuf.data(), eaSize), std::string("\000", 1))) {
if (options.ignoredAcls.count(eaName))
continue;
if (lremovexattr(path.c_str(), eaName.c_str()) == -1)
throw SysError("removing extended attribute '%s' from '%s'", eaName, path);
throw SysError("removing extended attribute '%s' from %s", eaName, PathFmt(path));
}
}
#endif
@@ -93,7 +93,7 @@ canonicalisePathMetaData_(const Path & path, CanonicalizePathMetadataOptions opt
(i.e. "touch $out/foo; ln $out/foo $out/bar"). */
if (options.uidRange && (st.st_uid < options.uidRange->first || st.st_uid > options.uidRange->second)) {
if (S_ISDIR(st.st_mode) || !inodesSeen.count(Inode(st.st_dev, st.st_ino)))
throw BuildError(BuildResult::Failure::OutputRejected, "invalid ownership on file '%1%'", path);
throw BuildError(BuildResult::Failure::OutputRejected, "invalid ownership on file %1%", PathFmt(path));
mode_t mode = st.st_mode & ~S_IFMT;
assert(
S_ISLNK(st.st_mode)
@@ -110,24 +110,25 @@ canonicalisePathMetaData_(const Path & path, CanonicalizePathMetadataOptions opt
/* Change ownership to the current uid. */
if (st.st_uid != geteuid()) {
if (lchown(path.c_str(), geteuid(), getegid()) == -1)
throw SysError("changing owner of '%1%' to %2%", path, geteuid());
throw SysError("changing owner of %1% to %2%", PathFmt(path), geteuid());
}
#endif
if (S_ISDIR(st.st_mode)) {
for (auto & i : DirectoryIterator{path}) {
checkInterrupt();
canonicalisePathMetaData_(i.path().string(), options, inodesSeen);
canonicalisePathMetaData_(i.path(), options, inodesSeen);
}
}
}
void canonicalisePathMetaData(const Path & path, CanonicalizePathMetadataOptions options, InodesSeen & inodesSeen)
void canonicalisePathMetaData(
const std::filesystem::path & path, CanonicalizePathMetadataOptions options, InodesSeen & inodesSeen)
{
canonicalisePathMetaData_(path, options, inodesSeen);
}
void canonicalisePathMetaData(const Path & path, CanonicalizePathMetadataOptions options)
void canonicalisePathMetaData(const std::filesystem::path & path, CanonicalizePathMetadataOptions options)
{
InodesSeen inodesSeen;
canonicalisePathMetaData_(path, options, inodesSeen);
+2 -2
View File
@@ -53,7 +53,7 @@ struct RestrictedStore : public virtual IndirectRootStore, public virtual GcStor
{
}
Path getRealStoreDir() override
std::filesystem::path getRealStoreDir() override
{
return next->config->realStoreDir;
}
@@ -125,7 +125,7 @@ struct RestrictedStore : public virtual IndirectRootStore, public virtual GcStor
void addTempRoot(const StorePath & path) override {}
void addIndirectRoot(const Path & path) override {}
void addIndirectRoot(const std::filesystem::path & path) override {}
Roots findRoots(bool censor) override
{
Loaded 100 of 223 files, more files were not shown because too many files have changed in this diff. Show more