Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dee3b49920 | ||
|
|
2d9bb33ba2 | ||
|
|
db06ac411c | ||
|
|
d9dd677448 | ||
|
|
ee955b3206 | ||
|
|
89dd96efbf | ||
|
|
6481e75283 | ||
|
|
b9ef088e80 | ||
|
|
02bb3d032d | ||
|
|
89a4412673 | ||
|
|
06a1511bff | ||
|
|
f02bc896ef | ||
|
|
4cf6843acf | ||
|
|
5184f844bb | ||
|
|
fa07d9d055 | ||
|
|
ca0f40f29e | ||
|
|
ae33d09589 | ||
|
|
d4b9a81956 | ||
|
|
91688d4a34 | ||
|
|
b8caabe25f | ||
|
|
76eca8fef3 | ||
|
|
2334977863 | ||
|
|
c8b02e6ff3 | ||
|
|
1210100421 | ||
|
|
473d54ed5f | ||
|
|
937a076844 | ||
|
|
a2d1346852 | ||
|
|
7275556d61 | ||
|
|
2c6c3864ce | ||
|
|
82f471f48e | ||
|
|
16f10c1321 | ||
|
|
d5dafb35c3 | ||
|
|
f4dfbca04d | ||
|
|
cf1ead7872 | ||
|
|
56735e9d0f | ||
|
|
5b9c41f1b7 | ||
|
|
63845dd9b3 | ||
|
|
b84a42f4cc | ||
|
|
003b64476e | ||
|
|
1e499e616a | ||
|
|
246c3fe8d3 | ||
|
|
ade94a5c0e | ||
|
|
a5a256265f | ||
|
|
be7b9a33ed | ||
|
|
5ce241cbfd | ||
|
|
3bfd64c3cd | ||
|
|
3f419cfa4e | ||
|
|
994137dcf7 | ||
|
|
9242d74bc1 | ||
|
|
6cddf03b5a | ||
|
|
afccf1d2d3 | ||
|
|
de16ef8be6 | ||
|
|
7cd7930344 | ||
|
|
d89400d052 | ||
|
|
658c775f01 | ||
|
|
b1ad42e6d5 | ||
|
|
761139f31c | ||
|
|
c6d93828bd | ||
|
|
614072adcb | ||
|
|
42f6e9933d | ||
|
|
6808bfab92 | ||
|
|
92942071c7 | ||
|
|
8899af09c1 | ||
|
|
6363c1bf00 | ||
|
|
5adb6a36b6 | ||
|
|
b10cb6596e | ||
|
|
c0e849b696 | ||
|
|
2470b7981a | ||
|
|
5c1939e315 | ||
|
|
9799023545 | ||
|
|
ae4e229c9f | ||
|
|
b63f5d1914 | ||
|
|
31d87afc5a | ||
|
|
204618c9d8 | ||
|
|
f0d90d3bdb | ||
|
|
0730dcb4a8 | ||
|
|
9b363e1e5c | ||
|
|
3df67a8347 | ||
|
|
dd4b73a44d | ||
|
|
fd4eee9d62 | ||
|
|
100e9a4436 | ||
|
|
17f344cdda | ||
|
|
c33d9e31cc | ||
|
|
89158eedb5 | ||
|
|
c33c82f345 | ||
|
|
40abcebbe1 | ||
|
|
3bf690a407 | ||
|
|
360ff05e73 | ||
|
|
100e7cc337 | ||
|
|
247cc7013a | ||
|
|
9e865ae4ff | ||
|
|
fef83c9f9c | ||
|
|
8491e26cd4 | ||
|
|
e5fa203d7f | ||
|
|
987ecca24a | ||
|
|
a98b43b994 | ||
|
|
6733f2e5ce | ||
|
|
08ce8dbfba | ||
|
|
bbcf2041e1 | ||
|
|
96bcf5928f | ||
|
|
db853cf4fb | ||
|
|
663db5b48b | ||
|
|
c486e78235 | ||
|
|
4fff871383 | ||
|
|
b9acea908e | ||
|
|
c3f0670b4e | ||
|
|
7cd4359a8b | ||
|
|
6e725093e6 | ||
|
|
5c42b84a17 | ||
|
|
96fef69755 | ||
|
|
16b0bb7548 | ||
|
|
ebcd31e434 | ||
|
|
f940ab5146 | ||
|
|
3df91bea62 | ||
|
|
aaabe82483 | ||
|
|
a81f83604b | ||
|
|
c1bfa30303 | ||
|
|
509694d5f0 | ||
|
|
0b7629da08 | ||
|
|
6429f2fd6c | ||
|
|
1a2d73dc2b | ||
|
|
e7e5eaaa37 | ||
|
|
974545290e | ||
|
|
be6e72f11b | ||
|
|
27782fcc42 | ||
|
|
06d4d5779f | ||
|
|
a32cd16f64 | ||
|
|
a3e99602c0 | ||
|
|
46a4a554ca | ||
|
|
cc0b489967 | ||
|
|
af7e585009 | ||
|
|
2ccb8a9a56 | ||
|
|
fefa66880a | ||
|
|
a53391fd0e | ||
|
|
3083226336 | ||
|
|
771421a34e | ||
|
|
5aaa0cc4a6 | ||
|
|
0749ec4e55 | ||
|
|
4cc97150df | ||
|
|
2bbd1094a2 | ||
|
|
95251a51dd | ||
|
|
0e39aa2068 | ||
|
|
02d9f4ecb4 | ||
|
|
3269c71e9d | ||
|
|
ad0055e67c | ||
|
|
d3d63a4b5b | ||
|
|
6a5ee08737 | ||
|
|
ac2dd58b6f | ||
|
|
4f91e9599f | ||
|
|
5ee5e6e8a0 | ||
|
|
0f2754a682 |
No files matched your search
@@ -26,7 +26,7 @@ jobs:
|
||||
# required to find all branches
|
||||
fetch-depth: 0
|
||||
- name: Create backport PRs
|
||||
uses: korthout/backport-action@c656f5d5851037b2b38fb5db2691a03fa229e3b2 # v4.0.1
|
||||
uses: korthout/backport-action@01619ebc9a6e3f6820274221b9956b3e7365000a # v4.1.0
|
||||
id: backport
|
||||
with:
|
||||
# Config README: https://github.com/korthout/backport-action#backport-action
|
||||
|
||||
@@ -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:
|
||||
@@ -174,7 +192,7 @@ jobs:
|
||||
echo "installer-url=file://$GITHUB_WORKSPACE/out" >> "$GITHUB_OUTPUT"
|
||||
TARBALL_PATH="$(find "$GITHUB_WORKSPACE/out" -name 'nix*.tar.xz' -print | head -n 1)"
|
||||
echo "tarball-path=file://$TARBALL_PATH" >> "$GITHUB_OUTPUT"
|
||||
- uses: cachix/install-nix-action@4e002c8ec80594ecd40e759629461e26c8abed15 # v31.9.0
|
||||
- uses: cachix/install-nix-action@2126ae7fc54c9df00dd18f7f18754393182c73cd # v31.9.1
|
||||
if: ${{ !matrix.experimental-installer }}
|
||||
with:
|
||||
install_url: ${{ format('{0}/install', steps.installer-tarball-url.outputs.installer-url) }}
|
||||
@@ -222,12 +240,12 @@ jobs:
|
||||
id: installer-tarball-url
|
||||
run: |
|
||||
echo "installer-url=file://$GITHUB_WORKSPACE/out" >> "$GITHUB_OUTPUT"
|
||||
- uses: cachix/install-nix-action@4e002c8ec80594ecd40e759629461e26c8abed15 # v31.9.0
|
||||
- uses: cachix/install-nix-action@2126ae7fc54c9df00dd18f7f18754393182c73cd # v31.9.1
|
||||
with:
|
||||
install_url: ${{ format('{0}/install', steps.installer-tarball-url.outputs.installer-url) }}
|
||||
install_options: ${{ format('--tarball-url-prefix {0}', steps.installer-tarball-url.outputs.installer-url) }}
|
||||
- name: Run flake regressions tests
|
||||
run: MAX_FLAKES=25 flake-regressions/eval-all.sh
|
||||
run: MAX_FLAKES=100000 flake-regressions/eval-all.sh
|
||||
|
||||
profile_build:
|
||||
needs: tests
|
||||
|
||||
@@ -39,6 +39,17 @@ jobs:
|
||||
role-to-assume: "arn:aws:iam::080433136561:role/nix-release"
|
||||
role-session-name: nix-release-oidc-${{ github.run_id }}
|
||||
aws-region: eu-west-1
|
||||
- name: Disable containerd image store
|
||||
run: |
|
||||
# Docker 28+ defaults to the containerd image store, which
|
||||
# pushes layers uncompressed instead of gzip. OCI clients
|
||||
# that only support gzip (e.g. go-containerregistry) fail
|
||||
# with "gzip: invalid header". Disabling the containerd
|
||||
# snapshotter restores the classic storage driver, which
|
||||
# preserves gzip-compressed layers through the
|
||||
# `docker load` / `docker push` pipeline.
|
||||
echo '{"features":{"containerd-snapshotter":false}}' | sudo tee /etc/docker/daemon.json > /dev/null
|
||||
sudo systemctl restart docker
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
|
||||
with:
|
||||
|
||||
@@ -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,23 @@
|
||||
---
|
||||
synopsis: "C API: Errors returned from your primops are not treated as recoverable by default"
|
||||
prs: [15286, 13930]
|
||||
---
|
||||
|
||||
Nix 2.34 by default remembers the error in the thunk that triggered it.
|
||||
|
||||
Previously the following sequence of events worked:
|
||||
|
||||
1. Have a thunk that invokes a primop that's defined through the C API
|
||||
2. The primop returns an error
|
||||
3. Force the thunk again
|
||||
4. The primop returns a value
|
||||
5. The thunk evaluated successfully
|
||||
|
||||
**Resolution**
|
||||
|
||||
C API consumers that rely on this must change their recoverable error calls:
|
||||
|
||||
```diff
|
||||
-nix_set_err_msg(context, NIX_ERR_*, msg);
|
||||
+nix_set_err_msg(context, NIX_ERR_RECOVERABLE, msg);
|
||||
```
|
||||
@@ -0,0 +1,40 @@
|
||||
---
|
||||
synopsis: "Attribute set equality now compares in lexicographic order of attribute names"
|
||||
prs: [15327]
|
||||
---
|
||||
|
||||
Attribute set equality (`==`) now compares attributes in lexicographic order of attribute names, rather than the internal symbol table order. Comparing attribute sets with mismatching `attrNames` now never evaluates any values, whereas previously that was undefined and depended on the unspecified symbol table order.
|
||||
|
||||
Previously, the evaluation order of attribute values during comparison was non-deterministic, meaning expressions like the following could silently succeed or fail depending on evaluation history or unspecified order of evaluation.
|
||||
|
||||
For example, depending on the order in which attribute names `a` and `b` have been seen by the evaluator, the following code would either yield `false` or fail to evaluate.
|
||||
|
||||
```nix
|
||||
{ a = throw "oops"; b = 2; } == { a = 2; b = 1; }
|
||||
```
|
||||
|
||||
|
||||
```
|
||||
nix-repl> a = 1
|
||||
|
||||
nix-repl> b = 2
|
||||
|
||||
nix-repl> { a = throw "oops"; b = 2; } == { a = 2; b = 1; }
|
||||
error:
|
||||
… while calling the 'throw' builtin
|
||||
at «string»:1:7:
|
||||
1| { a = throw "oops"; b = 2; } == { a = 2; b = 1; }
|
||||
| ^
|
||||
|
||||
error: oops
|
||||
```
|
||||
|
||||
```
|
||||
nix-repl> b = 2
|
||||
|
||||
nix-repl> a = 1
|
||||
|
||||
nix-repl> { a = throw "oops"; b = 2; } == { a = 2; b = 1; }
|
||||
false
|
||||
```
|
||||
|
||||
@@ -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).
|
||||
@@ -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.
|
||||
@@ -0,0 +1,6 @@
|
||||
---
|
||||
synopsis: New setting `narinfo-cache-meta-ttl`
|
||||
prs: [15287]
|
||||
---
|
||||
|
||||
The new setting `narinfo-cache-meta-ttl` controls how long binary cache metadata (i.e. `/nix-cache-info`) is cached locally, in seconds. This was previously hard-coded to 7 days, which is still the default. As a result, you can now use `nix store info --refresh` to check whether a binary cache is still valid.
|
||||
@@ -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; }
|
||||
```
|
||||
@@ -0,0 +1,11 @@
|
||||
---
|
||||
synopsis: New command `nix store roots-daemon` for serving GC roots
|
||||
prs: [15143]
|
||||
---
|
||||
|
||||
New command [`nix store roots-daemon`](@docroot@/command-ref/new-cli/nix3-store-roots-daemon.md) runs a daemon that serves garbage collector roots over a Unix domain socket.
|
||||
It enables the garbage collector to discover runtime roots when the main Nix daemon doesn't have `CAP_SYS_PTRACE` capability and therefore cannot scan `/proc`.
|
||||
|
||||
The garbage collector can be configured to use this daemon via the [`use-roots-daemon`](@docroot@/store/types/local-store.md#store-experimental-option-use-roots-daemon) store setting.
|
||||
|
||||
This feature requires the [`local-overlay-store` experimental feature](@docroot@/development/experimental-features.md#xp-feature-local-overlay-store).
|
||||
@@ -188,13 +188,14 @@ All comparison operators are implemented in terms of `<`, and the following equi
|
||||
|
||||
## Equality
|
||||
|
||||
- [Attribute sets][attribute set] are compared first by attribute names and then by items until a difference is found.
|
||||
- [Attribute sets][attribute set] are compared by size first and then by attribute names and their values until a difference is found.
|
||||
- [Lists][list] are compared first by length and then by items until a difference is found.
|
||||
- Comparison of distinct [functions][function] returns `false`, but identical functions may be subject to [value identity optimization](#value-identity-optimization).
|
||||
- Numbers are type-compatible, see [arithmetic] operators.
|
||||
- Floating point numbers only differ up to a limited precision.
|
||||
|
||||
The `==` operator is [strict](@docroot@/language/evaluation.md#strictness) in both arguments; when comparing composite types ([attribute sets][attribute set] and [lists][list]), it is partially strict in their contained values: they are evaluated until a difference is found. <!-- this is woefully underspecified, affecting which expressions evaluate correctly; not just "ordering" or error messages. -->
|
||||
The `==` operator is [strict](@docroot@/language/evaluation.md#strictness) in both arguments; when comparing composite types ([attribute sets][attribute set] and [lists][list]), it is partially strict in their contained values: they are evaluated until a difference is found. On `attrNames` mismatches, no contained values are evaluated. Attribute set comparison `a == b` behaves equivalently to `(builtins.attrNames a) == (builtins.attrNames b) && (builtins.attrValues a == builtins.attrValues b)` if [value identity optimization](#value-identity-optimization) is not taken into account.
|
||||
Equality comparison of contained values happens in canonical order: attributes are compared in lexicographic order of attribute names and list elements are compared in the order in which they appear in the list.
|
||||
|
||||
### Value identity optimization
|
||||
|
||||
|
||||
@@ -358,7 +358,6 @@ dockerTools.buildLayeredImageWithNixDb {
|
||||
|
||||
extraCommands = ''
|
||||
rm -rf nix-support
|
||||
ln -s /nix/var/nix/profiles nix/var/nix/gcroots/profiles
|
||||
'';
|
||||
fakeRootCommands = ''
|
||||
chmod 1777 tmp
|
||||
|
||||
Generated
+4
-4
@@ -63,11 +63,11 @@
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1769089682,
|
||||
"narHash": "sha256-Xu+7iYcAuOvsI2wdkUcIEmkqEJbvvE6n7qR9QNjJyP4=",
|
||||
"rev": "078d69f03934859a181e81ba987c2bb033eebfc5",
|
||||
"lastModified": 1771903837,
|
||||
"narHash": "sha256-jEA8WggGKtMFeNeCKq3NK8cLEjJmG6/RLUElYYbBZ0E=",
|
||||
"rev": "e764fc9a405871f1f6ca3d1394fb422e0a0c3951",
|
||||
"type": "tarball",
|
||||
"url": "https://releases.nixos.org/nixos/25.11/nixos-25.11.4506.078d69f03934/nixexprs.tar.xz"
|
||||
"url": "https://releases.nixos.org/nixos/25.11/nixos-25.11.6495.e764fc9a4058/nixexprs.tar.xz"
|
||||
},
|
||||
"original": {
|
||||
"type": "tarball",
|
||||
|
||||
@@ -115,6 +115,9 @@
|
||||
}
|
||||
// lib.optionalAttrs (crossSystem == "x86_64-unknown-freebsd13") {
|
||||
useLLVM = true;
|
||||
}
|
||||
// lib.optionalAttrs (crossSystem == "x86_64-w64-mingw32") {
|
||||
emulator = pkgs: "${pkgs.buildPackages.wineWow64Packages.stable_11}/bin/wine";
|
||||
};
|
||||
overlays = [
|
||||
(overlayFor (pkgs: pkgs.${stdenv}))
|
||||
@@ -406,7 +409,9 @@
|
||||
|
||||
"nix-cmd" = { };
|
||||
|
||||
"nix-nswrapper" = { };
|
||||
"nix-nswrapper" = {
|
||||
linuxOnly = true;
|
||||
};
|
||||
|
||||
"nix-cli" = { };
|
||||
|
||||
@@ -428,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 =
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -27,13 +27,19 @@ add_project_arguments(
|
||||
'-Wignored-qualifiers',
|
||||
'-Wimplicit-fallthrough',
|
||||
'-Wno-deprecated-declarations',
|
||||
'-Wno-interference-size', # Used for C++ ABI only. We don't provide any guarantees about different march tunings.
|
||||
language : 'cpp',
|
||||
)
|
||||
|
||||
# GCC doesn't benefit much from precompiled headers.
|
||||
do_pch = cxx.get_id() == 'clang'
|
||||
|
||||
if cxx.get_id() == 'gcc'
|
||||
add_project_arguments(
|
||||
'-Wno-interference-size', # Used for C++ ABI only. We don't provide any guarantees about different march tunings.
|
||||
language : 'cpp',
|
||||
)
|
||||
endif
|
||||
|
||||
# This is a clang-only option for improving build times.
|
||||
# It forces the instantiation of templates in the PCH itself and
|
||||
# not every translation unit it's included in.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
runCommand,
|
||||
system,
|
||||
stdenv,
|
||||
buildPackages,
|
||||
cacert,
|
||||
nix,
|
||||
@@ -9,6 +9,8 @@
|
||||
|
||||
let
|
||||
|
||||
inherit (stdenv.hostPlatform) system;
|
||||
|
||||
installerClosureInfo = buildPackages.closureInfo {
|
||||
rootPaths = [
|
||||
nix
|
||||
|
||||
@@ -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
@@ -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);
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include "nix/cmd/command.hh"
|
||||
#include "nix/cmd/legacy.hh"
|
||||
#include "nix/cmd/markdown.hh"
|
||||
#include "nix/main/shared.hh"
|
||||
#include "nix/store/globals.hh"
|
||||
#include "nix/store/store-open.hh"
|
||||
#include "nix/store/local-fs-store.hh"
|
||||
@@ -76,7 +75,7 @@ ref<StoreConfig> StoreConfigCommand::getStoreConfig()
|
||||
|
||||
ref<StoreConfig> StoreConfigCommand::createStoreConfig()
|
||||
{
|
||||
return resolveStoreConfig(settings, StoreReference{settings.storeUri.get()});
|
||||
return resolveStoreConfig(StoreReference{settings.storeUri.get()});
|
||||
}
|
||||
|
||||
void StoreConfigCommand::run()
|
||||
@@ -130,7 +129,7 @@ CopyCommand::CopyCommand()
|
||||
|
||||
ref<StoreConfig> CopyCommand::createStoreConfig()
|
||||
{
|
||||
return !srcUri ? StoreCommand::createStoreConfig() : resolveStoreConfig(settings, StoreReference{*srcUri});
|
||||
return !srcUri ? StoreCommand::createStoreConfig() : resolveStoreConfig(StoreReference{*srcUri});
|
||||
}
|
||||
|
||||
ref<Store> CopyCommand::getDstStore()
|
||||
@@ -138,7 +137,7 @@ ref<Store> CopyCommand::getDstStore()
|
||||
if (!srcUri && !dstUri)
|
||||
throw UsageError("you must pass '--from' and/or '--to'");
|
||||
|
||||
return !dstUri ? openStore(settings) : openStore(settings, StoreReference{*dstUri});
|
||||
return !dstUri ? openStore() : openStore(StoreReference{*dstUri});
|
||||
}
|
||||
|
||||
EvalCommand::EvalCommand()
|
||||
@@ -160,7 +159,7 @@ EvalCommand::~EvalCommand()
|
||||
ref<Store> EvalCommand::getEvalStore()
|
||||
{
|
||||
if (!evalStore)
|
||||
evalStore = evalStoreUrl ? openStore(settings, StoreReference{*evalStoreUrl}) : getStore();
|
||||
evalStore = evalStoreUrl ? openStore(StoreReference{*evalStoreUrl}) : getStore();
|
||||
return ref<Store>(evalStore);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,12 +19,12 @@
|
||||
|
||||
namespace nix {
|
||||
|
||||
fetchers::Settings fetchSettings{settings};
|
||||
fetchers::Settings fetchSettings;
|
||||
|
||||
static GlobalConfig::Register rFetchSettings(&fetchSettings);
|
||||
|
||||
EvalSettings evalSettings{
|
||||
settings,
|
||||
settings.readOnlyMode,
|
||||
{
|
||||
{
|
||||
"flake",
|
||||
@@ -135,7 +135,7 @@ MixEvalArgs::MixEvalArgs()
|
||||
fetchers::overrideRegistry(from.input, to.input, extraAttrs);
|
||||
}},
|
||||
.completer = {[&](AddCompletions & completions, size_t, std::string_view prefix) {
|
||||
completeFlakeRef(completions, openStore(settings), prefix);
|
||||
completeFlakeRef(completions, openStore(), prefix);
|
||||
}},
|
||||
});
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
|
||||
namespace nix {
|
||||
|
||||
std::string fetchBuildLog(Settings & settings, ref<Store> store, const StorePath & path, std::string_view what)
|
||||
std::string fetchBuildLog(ref<Store> store, const StorePath & path, std::string_view what)
|
||||
{
|
||||
auto subs = getDefaultSubstituters(settings);
|
||||
auto subs = getDefaultSubstituters();
|
||||
|
||||
subs.push_front(store);
|
||||
|
||||
|
||||
@@ -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{}},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
|
||||
namespace nix {
|
||||
|
||||
class Settings;
|
||||
|
||||
/**
|
||||
* Fetch the build log for a store path, searching the store and its
|
||||
* substituters.
|
||||
@@ -20,6 +18,6 @@ class Settings;
|
||||
* @return The build log content.
|
||||
* @throws Error if the build log is not available.
|
||||
*/
|
||||
std::string fetchBuildLog(Settings & settings, ref<Store> store, const StorePath & path, std::string_view what);
|
||||
std::string fetchBuildLog(ref<Store> store, const StorePath & path, std::string_view what);
|
||||
|
||||
} // namespace nix
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
///@file
|
||||
|
||||
#include "nix/store/globals.hh"
|
||||
#include "nix/cmd/installable-value.hh"
|
||||
#include "nix/store/outputs-spec.hh"
|
||||
#include "nix/cmd/command.hh"
|
||||
|
||||
@@ -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,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
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
|
||||
@@ -40,8 +40,8 @@ void sigintHandler(int signo)
|
||||
static detail::ReplCompleterMixin * curRepl; // ugly
|
||||
|
||||
#if !USE_READLINE
|
||||
static char * completionCallback(char * s, int * match)
|
||||
{
|
||||
static char * completionCallback(char * s, int * match) noexcept
|
||||
try {
|
||||
auto possible = curRepl->completePrefix(s);
|
||||
if (possible.size() == 1) {
|
||||
*match = 1;
|
||||
@@ -73,10 +73,12 @@ static char * completionCallback(char * s, int * match)
|
||||
|
||||
*match = 0;
|
||||
return nullptr;
|
||||
} catch (...) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static int listPossibleCallback(char * s, char *** avp)
|
||||
{
|
||||
static int listPossibleCallback(char * s, char *** avp) noexcept
|
||||
try {
|
||||
auto possible = curRepl->completePrefix(s);
|
||||
|
||||
if (possible.size() > (std::numeric_limits<int>::max() / sizeof(char *)))
|
||||
@@ -105,6 +107,9 @@ static int listPossibleCallback(char * s, char *** avp)
|
||||
*avp = vp;
|
||||
|
||||
return ac;
|
||||
} catch (...) {
|
||||
*avp = nullptr;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -113,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; });
|
||||
@@ -203,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
|
||||
+56
-33
@@ -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,15 +553,15 @@ 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; });
|
||||
RunPager pager;
|
||||
auto log = fetchBuildLog(settings, state->store, drvPath, drvPathRaw);
|
||||
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();
|
||||
@@ -710,7 +711,7 @@ void NixRepl::loadFlake(const std::string & flakeRefS)
|
||||
try {
|
||||
cwd = std::filesystem::current_path();
|
||||
} catch (std::filesystem::filesystem_error & e) {
|
||||
throw SysError("cannot determine current working directory");
|
||||
throw SystemError(e.code(), "cannot determine current working directory");
|
||||
}
|
||||
|
||||
auto flakeRef = parseFlakeRef(fetchSettings, flakeRefS, cwd.string(), true);
|
||||
@@ -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",
|
||||
|
||||
@@ -132,8 +132,9 @@ nix_eval_state_builder * nix_eval_state_builder_new(nix_c_context * context, Sto
|
||||
return unsafe_new_with_self<nix_eval_state_builder>([&](auto * self) {
|
||||
return nix_eval_state_builder{
|
||||
.store = nix::ref<nix::Store>(store->ptr),
|
||||
.settings = nix::EvalSettings{cStoreSettings},
|
||||
.fetchSettings = nix::fetchers::Settings{cStoreSettings},
|
||||
.settings = nix::EvalSettings{/* &bool */ self->readOnlyMode},
|
||||
.fetchSettings = nix::fetchers::Settings{},
|
||||
.readOnlyMode = true,
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -152,7 +153,8 @@ nix_err nix_eval_state_builder_load(nix_c_context * context, nix_eval_state_buil
|
||||
if (context)
|
||||
context->last_err_code = NIX_OK;
|
||||
try {
|
||||
loadConfFile(cStoreSettings);
|
||||
// TODO: load in one go?
|
||||
builder->settings.readOnlyMode = nix::settings.readOnlyMode;
|
||||
loadConfFile(builder->settings);
|
||||
loadConfFile(builder->fetchSettings);
|
||||
}
|
||||
@@ -183,7 +185,9 @@ EvalState * nix_eval_state_build(nix_c_context * context, nix_eval_state_builder
|
||||
return EvalState{
|
||||
.fetchSettings = std::move(builder->fetchSettings),
|
||||
.settings = std::move(builder->settings),
|
||||
.state = nix::EvalState(builder->lookupPath, builder->store, self->fetchSettings, self->settings),
|
||||
.statePtr = std::make_shared<nix::EvalState>(
|
||||
builder->lookupPath, builder->store, self->fetchSettings, self->settings),
|
||||
.state = *self->statePtr,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@@ -16,13 +16,16 @@ struct nix_eval_state_builder
|
||||
nix::EvalSettings settings;
|
||||
nix::fetchers::Settings fetchSettings;
|
||||
nix::LookupPath lookupPath;
|
||||
// TODO: make an EvalSettings setting own this instead?
|
||||
bool readOnlyMode;
|
||||
};
|
||||
|
||||
struct EvalState
|
||||
{
|
||||
nix::fetchers::Settings fetchSettings;
|
||||
nix::EvalSettings settings;
|
||||
nix::EvalState state;
|
||||
std::shared_ptr<nix::EvalState> statePtr;
|
||||
nix::EvalState & state;
|
||||
};
|
||||
|
||||
struct BindingsBuilder
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "nix/expr/attr-set.hh"
|
||||
#include "nix/expr/eval-error.hh"
|
||||
#include "nix/util/configuration.hh"
|
||||
#include "nix/expr/eval.hh"
|
||||
#include "nix/store/globals.hh"
|
||||
@@ -107,8 +108,13 @@ static void nix_c_primop_wrapper(
|
||||
f(userdata, &ctx, (EvalState *) &state, external_args.data(), vTmpPtr);
|
||||
|
||||
if (ctx.last_err_code != NIX_OK) {
|
||||
/* TODO: Throw different errors depending on the error code */
|
||||
state.error<nix::EvalError>("Error from custom function: %s", *ctx.last_err).atPos(pos).debugThrow();
|
||||
if (ctx.last_err_code == NIX_ERR_RECOVERABLE) {
|
||||
state.error<nix::RecoverableEvalError>("Recoverable error from custom function: %s", *ctx.last_err)
|
||||
.atPos(pos)
|
||||
.debugThrow();
|
||||
} else {
|
||||
state.error<nix::EvalError>("Error from custom function: %s", *ctx.last_err).atPos(pos).debugThrow();
|
||||
}
|
||||
}
|
||||
|
||||
if (!vTmp.isValid()) {
|
||||
@@ -194,6 +200,8 @@ ValueType nix_get_type(nix_c_context * context, const nix_value * value)
|
||||
switch (v.type()) {
|
||||
case nThunk:
|
||||
return NIX_TYPE_THUNK;
|
||||
case nFailed:
|
||||
return NIX_TYPE_FAILED;
|
||||
case nInt:
|
||||
return NIX_TYPE_INT;
|
||||
case nFloat:
|
||||
|
||||
@@ -100,7 +100,8 @@ typedef enum {
|
||||
/** @brief External value from C++ plugins or C API
|
||||
* @see Externals
|
||||
*/
|
||||
NIX_TYPE_EXTERNAL
|
||||
NIX_TYPE_EXTERNAL,
|
||||
NIX_TYPE_FAILED,
|
||||
} ValueType;
|
||||
|
||||
// forward declarations
|
||||
|
||||
@@ -26,18 +26,18 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
LibExprTest(auto && makeEvalSettings, auto &&... args)
|
||||
: LibStoreTest(args...)
|
||||
, evalSettings(makeEvalSettings(settings))
|
||||
LibExprTest(ref<Store> store, auto && makeEvalSettings)
|
||||
: LibStoreTest()
|
||||
, evalSettings(makeEvalSettings(readOnlyMode))
|
||||
, state({}, store, fetchSettings, evalSettings, nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
LibExprTest()
|
||||
: LibExprTest([](Settings & settings) {
|
||||
EvalSettings evalSettings{settings};
|
||||
evalSettings.nixPath = {};
|
||||
return evalSettings;
|
||||
: LibExprTest(openStore("dummy://"), [](bool & readOnlyMode) {
|
||||
EvalSettings settings{readOnlyMode};
|
||||
settings.nixPath = {};
|
||||
return settings;
|
||||
})
|
||||
{
|
||||
}
|
||||
@@ -66,8 +66,8 @@ protected:
|
||||
}
|
||||
|
||||
bool readOnlyMode = true;
|
||||
fetchers::Settings fetchSettings{settings};
|
||||
EvalSettings evalSettings{settings};
|
||||
fetchers::Settings fetchSettings{};
|
||||
EvalSettings evalSettings{readOnlyMode};
|
||||
EvalState state;
|
||||
};
|
||||
|
||||
|
||||
@@ -37,7 +37,8 @@ static void BM_EvalDynamicAttrs(benchmark::State & state)
|
||||
EvalSettings evalSettings{readOnlyMode};
|
||||
evalSettings.nixPath = {};
|
||||
|
||||
EvalState st({}, store, fetchSettings, evalSettings, nullptr);
|
||||
auto stPtr = std::make_shared<EvalState>(LookupPath{}, store, fetchSettings, evalSettings, nullptr);
|
||||
auto & st = *stPtr;
|
||||
Expr * expr = st.parseExprFromString(exprStr, st.rootPath(CanonPath::root));
|
||||
|
||||
Value v;
|
||||
|
||||
@@ -179,15 +179,12 @@ class PureEvalTest : public LibExprTest
|
||||
{
|
||||
public:
|
||||
PureEvalTest()
|
||||
: LibExprTest{
|
||||
[](auto & settings) {
|
||||
EvalSettings evalSettings{settings};
|
||||
evalSettings.pureEval = true;
|
||||
evalSettings.restrictEval = true;
|
||||
return evalSettings;
|
||||
},
|
||||
[](auto & settings) { return openStore(settings, "dummy://", {{"read-only", "false"}}); },
|
||||
}
|
||||
: LibExprTest(openStore("dummy://", {{"read-only", "false"}}), [](bool & readOnlyMode) {
|
||||
EvalSettings settings{readOnlyMode};
|
||||
settings.pureEval = true;
|
||||
settings.restrictEval = true;
|
||||
return settings;
|
||||
})
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
@@ -16,7 +16,8 @@ struct GetDerivationsEnv
|
||||
fetchers::Settings fetchSettings{};
|
||||
bool readOnlyMode = true;
|
||||
EvalSettings evalSettings{readOnlyMode};
|
||||
EvalState state;
|
||||
std::shared_ptr<EvalState> statePtr;
|
||||
EvalState & state;
|
||||
|
||||
Bindings * autoArgs = nullptr;
|
||||
Value attrsValue;
|
||||
@@ -27,7 +28,8 @@ struct GetDerivationsEnv
|
||||
settings.nixPath = {};
|
||||
return settings;
|
||||
}())
|
||||
, state({}, store, fetchSettings, evalSettings, nullptr)
|
||||
, statePtr(std::make_shared<EvalState>(LookupPath{}, store, fetchSettings, evalSettings, nullptr))
|
||||
, state(*statePtr)
|
||||
{
|
||||
autoArgs = state.buildBindings(0).finish();
|
||||
|
||||
|
||||
@@ -517,4 +517,106 @@ TEST_F(nix_api_expr_test, nix_expr_attrset_update)
|
||||
assert_ctx_ok();
|
||||
}
|
||||
|
||||
// The following is a test case for retryable thunks. This is a requirement
|
||||
// for the current way in which NixOps4 evaluates its deployment expressions.
|
||||
// An alternative strategy could be implemented, but unwinding the stack may
|
||||
// be a more efficient way to deal with many suspensions/resumptions, compared
|
||||
// to e.g. using a thread or coroutine stack for each suspended dependency.
|
||||
// This test models the essential bits of a deployment tool that uses such
|
||||
// a strategy.
|
||||
|
||||
// State for the retryable primop - simulates deployment resource availability
|
||||
struct DeploymentResourceState
|
||||
{
|
||||
bool vm_created = false;
|
||||
};
|
||||
|
||||
static void primop_load_resource_input(
|
||||
void * user_data, nix_c_context * context, EvalState * state, nix_value ** args, nix_value * ret)
|
||||
{
|
||||
assert(context);
|
||||
assert(state);
|
||||
auto * resource_state = static_cast<DeploymentResourceState *>(user_data);
|
||||
|
||||
// Get the resource input name argument
|
||||
std::string input_name;
|
||||
if (nix_get_string(context, args[0], OBSERVE_STRING(input_name)) != NIX_OK)
|
||||
return;
|
||||
|
||||
// Only handle "vm_id" input - throw for anything else
|
||||
if (input_name != "vm_id") {
|
||||
std::string error_msg = "unknown resource input: " + input_name;
|
||||
nix_set_err_msg(context, NIX_ERR_NIX_ERROR, error_msg.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if (resource_state->vm_created) {
|
||||
// VM has been created, return the ID
|
||||
nix_init_string(context, ret, "vm-12345");
|
||||
} else {
|
||||
// VM not created yet, fail with dependency error
|
||||
nix_set_err_msg(context, NIX_ERR_RECOVERABLE, "VM not yet created");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(nix_api_expr_test, nix_expr_thunk_re_evaluation_after_deployment)
|
||||
{
|
||||
// This test demonstrates NixOps4's requirement: a thunk calling a primop should be
|
||||
// re-evaluable when deployment resources become available that were not available initially.
|
||||
|
||||
DeploymentResourceState resource_state;
|
||||
|
||||
PrimOp * primop = nix_alloc_primop(
|
||||
ctx,
|
||||
primop_load_resource_input,
|
||||
1,
|
||||
"loadResourceInput",
|
||||
nullptr,
|
||||
"load a deployment resource input",
|
||||
&resource_state);
|
||||
assert_ctx_ok();
|
||||
|
||||
nix_value * primopValue = nix_alloc_value(ctx, state);
|
||||
assert_ctx_ok();
|
||||
nix_init_primop(ctx, primopValue, primop);
|
||||
assert_ctx_ok();
|
||||
|
||||
nix_value * inputName = nix_alloc_value(ctx, state);
|
||||
assert_ctx_ok();
|
||||
nix_init_string(ctx, inputName, "vm_id");
|
||||
assert_ctx_ok();
|
||||
|
||||
// Create a single thunk by using nix_init_apply instead of nix_value_call
|
||||
// This creates a lazy application that can be forced multiple times
|
||||
nix_value * thunk = nix_alloc_value(ctx, state);
|
||||
assert_ctx_ok();
|
||||
nix_init_apply(ctx, thunk, primopValue, inputName);
|
||||
assert_ctx_ok();
|
||||
|
||||
// First force: VM not created yet, should fail
|
||||
nix_value_force(ctx, state, thunk);
|
||||
ASSERT_EQ(NIX_ERR_NIX_ERROR, nix_err_code(ctx));
|
||||
ASSERT_THAT(nix_err_msg(nullptr, ctx, nullptr), testing::HasSubstr("VM not yet created"));
|
||||
|
||||
// Clear the error context for the next attempt
|
||||
nix_c_context_free(ctx);
|
||||
ctx = nix_c_context_create();
|
||||
|
||||
// Simulate deployment process: VM gets created
|
||||
resource_state.vm_created = true;
|
||||
|
||||
// Second force of the SAME thunk: this is where the "failed" value issue appears
|
||||
// With failed value caching, this should fail because the thunk is marked as permanently failed
|
||||
// Without failed value caching (or with retryable failures), this should succeed
|
||||
nix_value_force(ctx, state, thunk);
|
||||
|
||||
// If we get here without error, the thunk was successfully re-evaluated
|
||||
assert_ctx_ok();
|
||||
|
||||
std::string result;
|
||||
nix_get_string(ctx, thunk, OBSERVE_STRING(result));
|
||||
assert_ctx_ok();
|
||||
ASSERT_STREQ("vm-12345", result.c_str());
|
||||
}
|
||||
|
||||
} // namespace nixC
|
||||
@@ -27,7 +27,8 @@ static void BM_EvalManyBuiltinsMatchSameRegex(benchmark::State & state)
|
||||
EvalSettings evalSettings{readOnlyMode};
|
||||
evalSettings.nixPath = {};
|
||||
|
||||
EvalState st({}, store, fetchSettings, evalSettings, nullptr);
|
||||
auto stPtr = std::make_shared<EvalState>(LookupPath{}, store, fetchSettings, evalSettings, nullptr);
|
||||
auto & st = *stPtr;
|
||||
Expr * expr = st.parseExprFromString(std::string(exprStr), st.rootPath(CanonPath::root));
|
||||
|
||||
Value v;
|
||||
|
||||
@@ -188,6 +188,22 @@ TEST_F(ValuePrintingTests, vBlackhole)
|
||||
test(vBlackhole, "«potential infinite recursion»");
|
||||
}
|
||||
|
||||
TEST_F(ValuePrintingTests, vFailed)
|
||||
{
|
||||
Value v;
|
||||
try {
|
||||
throw Error("nope");
|
||||
} catch (...) {
|
||||
v.mkFailed(std::current_exception(), nullptr);
|
||||
}
|
||||
|
||||
// Historically, a tried and then ignored value (e.g. through tryEval) was
|
||||
// reverted to the original thunk.
|
||||
|
||||
test(v, "«thunk»");
|
||||
test(v, ANSI_MAGENTA "«thunk»" ANSI_NORMAL, PrintOptions{.ansiColors = true});
|
||||
}
|
||||
|
||||
TEST_F(ValuePrintingTests, depthAttrs)
|
||||
{
|
||||
Value vOne;
|
||||
|
||||
@@ -13,8 +13,7 @@ TEST_F(ValueTest, unsetValue)
|
||||
{
|
||||
Value unsetValue;
|
||||
ASSERT_EQ(false, unsetValue.isValid());
|
||||
ASSERT_EQ(nThunk, unsetValue.type(true));
|
||||
ASSERT_DEATH(unsetValue.type(), "");
|
||||
ASSERT_EQ(nThunk, unsetValue.type</*invalidIsThunk=*/true>());
|
||||
}
|
||||
|
||||
TEST_F(ValueTest, vInt)
|
||||
|
||||
@@ -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
|
||||
@@ -11,7 +11,7 @@
|
||||
namespace nix::eval_cache {
|
||||
|
||||
CachedEvalError::CachedEvalError(ref<AttrCursor> cursor, Symbol attr)
|
||||
: EvalError(cursor->root->state, "cached failure of attribute '%s'", cursor->getAttrPathStr(attr))
|
||||
: CloneableError(cursor->root->state, "cached failure of attribute '%s'", cursor->getAttrPathStr(attr))
|
||||
, cursor(cursor)
|
||||
, attr(attr)
|
||||
{
|
||||
@@ -63,19 +63,19 @@ struct AttrDb
|
||||
|
||||
SymbolTable & symbols;
|
||||
|
||||
AttrDb(bool useSQLiteWAL, const StoreDirConfig & cfg, const Hash & fingerprint, SymbolTable & symbols)
|
||||
AttrDb(const StoreDirConfig & cfg, const Hash & fingerprint, SymbolTable & symbols)
|
||||
: cfg(cfg)
|
||||
, _state(std::make_unique<Sync<State>>())
|
||||
, symbols(symbols)
|
||||
{
|
||||
auto state(_state->lock());
|
||||
|
||||
auto cacheDir = std::filesystem::path(getCacheDir()) / "eval-cache-v6";
|
||||
auto cacheDir = getCacheDir() / "eval-cache-v6";
|
||||
createDirs(cacheDir);
|
||||
|
||||
auto dbPath = cacheDir / (fingerprint.to_string(HashFormat::Base16, false) + ".sqlite");
|
||||
|
||||
state->db = SQLite(dbPath, {.useWAL = useSQLiteWAL});
|
||||
state->db = SQLite(dbPath, {.useWAL = settings.useSQLiteWAL});
|
||||
state->db.isCache();
|
||||
state->db.exec(schema);
|
||||
|
||||
@@ -287,11 +287,10 @@ struct AttrDb
|
||||
}
|
||||
};
|
||||
|
||||
static std::shared_ptr<AttrDb>
|
||||
makeAttrDb(bool useSQLiteWAL, const StoreDirConfig & cfg, const Hash & fingerprint, SymbolTable & symbols)
|
||||
static std::shared_ptr<AttrDb> makeAttrDb(const StoreDirConfig & cfg, const Hash & fingerprint, SymbolTable & symbols)
|
||||
{
|
||||
try {
|
||||
return std::make_shared<AttrDb>(useSQLiteWAL, cfg, fingerprint, symbols);
|
||||
return std::make_shared<AttrDb>(cfg, fingerprint, symbols);
|
||||
} catch (SQLiteError &) {
|
||||
ignoreExceptionExceptInterrupt();
|
||||
return nullptr;
|
||||
@@ -300,8 +299,7 @@ makeAttrDb(bool useSQLiteWAL, const StoreDirConfig & cfg, const Hash & fingerpri
|
||||
|
||||
EvalCache::EvalCache(
|
||||
std::optional<std::reference_wrapper<const Hash>> useCache, EvalState & state, RootLoader rootLoader)
|
||||
: db(useCache ? makeAttrDb(state.store->config.settings.useSQLiteWAL, *state.store, *useCache, state.symbols)
|
||||
: nullptr)
|
||||
: db(useCache ? makeAttrDb(*state.store, *useCache, state.symbols) : nullptr)
|
||||
, state(state)
|
||||
, rootLoader(rootLoader)
|
||||
{
|
||||
@@ -709,7 +707,7 @@ StorePath AttrCursor::forceDerivation()
|
||||
auto aDrvPath = getAttr(root->state.s.drvPath);
|
||||
auto drvPath = root->state.store->parseStorePath(aDrvPath->getString());
|
||||
drvPath.requireDerivation();
|
||||
if (!root->state.store->isValidPath(drvPath) && !root->state.store->config.settings.readOnlyMode) {
|
||||
if (!root->state.store->isValidPath(drvPath) && !settings.readOnlyMode) {
|
||||
/* The eval cache contains 'drvPath', but the actual path has
|
||||
been garbage-collected. So force it to be regenerated. */
|
||||
aDrvPath->forceValue();
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
@@ -114,5 +121,6 @@ template class EvalErrorBuilder<InfiniteRecursionError>;
|
||||
template class EvalErrorBuilder<StackOverflowError>;
|
||||
template class EvalErrorBuilder<InvalidPathError>;
|
||||
template class EvalErrorBuilder<IFDError>;
|
||||
template class EvalErrorBuilder<RecoverableEvalError>;
|
||||
|
||||
} // namespace nix
|
||||
@@ -137,7 +137,7 @@ public:
|
||||
: state(state)
|
||||
, sampleInterval(period)
|
||||
, profileFd([&]() {
|
||||
AutoCloseFD fd = openNewFileForWrite(
|
||||
auto fd = openNewFileForWrite(
|
||||
profileFile,
|
||||
0660,
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
@@ -48,8 +69,8 @@ Strings EvalSettings::parseNixPath(const std::string & s)
|
||||
return res;
|
||||
}
|
||||
|
||||
EvalSettings::EvalSettings(nix::Settings & storeSettings, EvalSettings::LookupPathHooks lookupPathHooks)
|
||||
: storeSettings{storeSettings}
|
||||
EvalSettings::EvalSettings(bool & readOnlyMode, EvalSettings::LookupPathHooks lookupPathHooks)
|
||||
: readOnlyMode{readOnlyMode}
|
||||
, lookupPathHooks{lookupPathHooks}
|
||||
{
|
||||
auto var = getEnv("NIX_ABORT_ON_WARN");
|
||||
@@ -57,7 +78,7 @@ EvalSettings::EvalSettings(nix::Settings & storeSettings, EvalSettings::LookupPa
|
||||
builtinsAbortOnWarn = true;
|
||||
}
|
||||
|
||||
Strings EvalSettings::getDefaultNixPath(nix::Settings & settings)
|
||||
Strings EvalSettings::getDefaultNixPath()
|
||||
{
|
||||
Strings res;
|
||||
auto add = [&](const std::filesystem::path & p, const std::string & s = std::string()) {
|
||||
@@ -70,7 +91,7 @@ Strings EvalSettings::getDefaultNixPath(nix::Settings & settings)
|
||||
}
|
||||
};
|
||||
|
||||
add(std::filesystem::path{getNixDefExpr(settings)} / "channels");
|
||||
add(getNixDefExpr() / "channels");
|
||||
auto profilesDirOpts = settings.getProfileDirsOptions();
|
||||
add(rootChannelsDir(profilesDirOpts) / "nixpkgs", "nixpkgs");
|
||||
add(rootChannelsDir(profilesDirOpts));
|
||||
@@ -101,10 +122,10 @@ std::string EvalSettings::resolvePseudoUrl(std::string_view url)
|
||||
const std::string & EvalSettings::getCurrentSystem() const
|
||||
{
|
||||
const auto & evalSystem = currentSystem.get();
|
||||
return evalSystem != "" ? evalSystem : storeSettings.thisSystem.get();
|
||||
return evalSystem != "" ? evalSystem : settings.thisSystem.get();
|
||||
}
|
||||
|
||||
std::filesystem::path getNixDefExpr(const Settings & settings)
|
||||
std::filesystem::path getNixDefExpr()
|
||||
{
|
||||
return settings.useXDGBaseDirectories ? getStateDir() / "defexpr" : getHome() / ".nix-defexpr";
|
||||
}
|
||||
|
||||
+187
-41
@@ -1,4 +1,5 @@
|
||||
#include "nix/expr/eval.hh"
|
||||
#include "nix/expr/eval-error.hh"
|
||||
#include "nix/expr/eval-settings.hh"
|
||||
#include "nix/expr/primops.hh"
|
||||
#include "nix/expr/print-options.hh"
|
||||
@@ -15,7 +16,6 @@
|
||||
#include "nix/store/filetransfer.hh"
|
||||
#include "nix/expr/function-trace.hh"
|
||||
#include "nix/store/profiles.hh"
|
||||
#include "nix/store/globals.hh"
|
||||
#include "nix/expr/print.hh"
|
||||
#include "nix/fetchers/filtering-source-accessor.hh"
|
||||
#include "nix/util/memory-source-accessor.hh"
|
||||
@@ -32,6 +32,7 @@
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
@@ -156,6 +157,8 @@ std::string_view showType(ValueType type, bool withArticle)
|
||||
return WA("a", "float");
|
||||
case nThunk:
|
||||
return WA("a", "thunk");
|
||||
case nFailed:
|
||||
return WA("an", "error");
|
||||
}
|
||||
unreachable();
|
||||
}
|
||||
@@ -331,7 +334,7 @@ EvalState::EvalState(
|
||||
lookupPath.elements.emplace_back(LookupPath::Elem::parse(i));
|
||||
}
|
||||
if (!settings.restrictEval) {
|
||||
for (auto & i : EvalSettings::getDefaultNixPath(store->config.settings)) {
|
||||
for (auto & i : EvalSettings::getDefaultNixPath()) {
|
||||
lookupPath.elements.emplace_back(LookupPath::Elem::parse(i));
|
||||
}
|
||||
}
|
||||
@@ -423,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)
|
||||
@@ -467,7 +477,7 @@ void EvalState::addConstant(const std::string & name, Value * v, Constant info)
|
||||
|
||||
We might know the type of a thunk in advance, so be allowed
|
||||
to just write it down in that case. */
|
||||
if (auto gotType = v->type(true); gotType != nThunk)
|
||||
if (auto gotType = v->type</*invalidIsThunk=*/true>(); gotType != nThunk)
|
||||
assert(info.type == gotType);
|
||||
|
||||
/* Install value the base environment. */
|
||||
@@ -886,7 +896,7 @@ void Value::mkPath(const SourcePath & path, EvalMemory & mem)
|
||||
mkPath(&*path.accessor, StringData::make(mem, path.path.abs()));
|
||||
}
|
||||
|
||||
inline Value * EvalState::lookupVar(Env * env, const ExprVar & var, bool noEval)
|
||||
[[gnu::always_inline]] inline Value * EvalState::lookupVar(Env * env, const ExprVar & var, bool noEval)
|
||||
{
|
||||
for (auto l = var.level; l; --l, env = env->up)
|
||||
;
|
||||
@@ -904,11 +914,11 @@ inline Value * EvalState::lookupVar(Env * env, const ExprVar & var, bool noEval)
|
||||
while (1) {
|
||||
forceAttrs(*env->values[0], fromWith->pos, "while evaluating the first subexpression of a with expression");
|
||||
if (auto j = env->values[0]->attrs()->get(var.name)) {
|
||||
if (countCalls)
|
||||
if (countCalls) [[unlikely]]
|
||||
attrSelects[j->pos]++;
|
||||
return j->value;
|
||||
}
|
||||
if (!fromWith->parentWith)
|
||||
if (!fromWith->parentWith) [[unlikely]]
|
||||
error<UndefinedVarError>("undefined variable '%1%'", symbols[var.name])
|
||||
.atPos(var.pos)
|
||||
.withFrame(*env, var)
|
||||
@@ -1988,11 +1998,15 @@ void ExprOpUpdate::eval(EvalState & state, Env & env, Value & v)
|
||||
UpdateQueue q;
|
||||
evalForUpdate(state, env, q);
|
||||
|
||||
v.mkAttrs(&Bindings::emptyBindings);
|
||||
Value vTmp;
|
||||
vTmp.mkAttrs(&Bindings::emptyBindings);
|
||||
|
||||
for (auto & rhs : std::views::reverse(q)) {
|
||||
/* Remember that queue is sorted rightmost attrset first. */
|
||||
eval(state, /*v=*/v, /*v1=*/v, /*v2=*/rhs);
|
||||
eval(state, /*v=*/vTmp, /*v1=*/vTmp, /*v2=*/rhs);
|
||||
}
|
||||
|
||||
v = vTmp;
|
||||
}
|
||||
|
||||
void Expr::evalForUpdate(EvalState & state, Env & env, UpdateQueue & q, std::string_view errorCtx)
|
||||
@@ -2175,6 +2189,54 @@ void ExprBlackHole::eval(EvalState & state, [[maybe_unused]] Env & env, Value &
|
||||
// always force this to be separate, otherwise forceValue may inline it and take
|
||||
// a massive perf hit
|
||||
[[gnu::noinline]]
|
||||
void EvalState::handleEvalExceptionForThunk(Env * env, Expr * expr, Value & v, const PosIdx pos)
|
||||
{
|
||||
if (!env)
|
||||
tryFixupBlackHolePos(v, pos);
|
||||
|
||||
auto e = std::current_exception();
|
||||
Value * recovery = nullptr;
|
||||
try {
|
||||
std::rethrow_exception(e);
|
||||
} catch (const RecoverableEvalError & e) {
|
||||
recovery = allocValue();
|
||||
} catch (...) {
|
||||
}
|
||||
if (recovery) {
|
||||
recovery->mkThunk(env, expr);
|
||||
}
|
||||
v.mkFailed(e, recovery);
|
||||
}
|
||||
|
||||
[[gnu::noinline]]
|
||||
void EvalState::handleEvalExceptionForApp(Value & v, const Value & savedApp)
|
||||
{
|
||||
auto e = std::current_exception();
|
||||
Value * recovery = nullptr;
|
||||
try {
|
||||
std::rethrow_exception(e);
|
||||
} catch (const RecoverableEvalError & e) {
|
||||
recovery = allocValue();
|
||||
} catch (...) {
|
||||
}
|
||||
if (recovery) {
|
||||
*recovery = savedApp;
|
||||
}
|
||||
v.mkFailed(e, recovery);
|
||||
}
|
||||
|
||||
[[gnu::noinline]]
|
||||
void EvalState::handleEvalFailed(Value & v, const PosIdx pos)
|
||||
{
|
||||
assert(v.isFailed());
|
||||
if (auto recoveryValue = v.failed().recoveryValue) {
|
||||
v = *recoveryValue;
|
||||
forceValue(v, pos);
|
||||
} else {
|
||||
v.failed().rethrow();
|
||||
}
|
||||
}
|
||||
|
||||
void EvalState::tryFixupBlackHolePos(Value & v, PosIdx pos)
|
||||
{
|
||||
if (!v.isBlackhole())
|
||||
@@ -2183,7 +2245,8 @@ void EvalState::tryFixupBlackHolePos(Value & v, PosIdx pos)
|
||||
try {
|
||||
std::rethrow_exception(e);
|
||||
} catch (InfiniteRecursionError & e) {
|
||||
e.atPos(positions[pos]);
|
||||
if (!e.hasPos())
|
||||
e.atPos(positions[pos]);
|
||||
} catch (...) {
|
||||
}
|
||||
}
|
||||
@@ -2509,7 +2572,7 @@ StorePath EvalState::copyPathToStore(NixStringContext & context, const SourcePat
|
||||
fetchSettings,
|
||||
*store,
|
||||
path.resolveSymlinks(SymlinkResolution::Ancestors),
|
||||
settings.storeSettings.readOnlyMode ? FetchMode::DryRun : FetchMode::Copy,
|
||||
settings.readOnlyMode ? FetchMode::DryRun : FetchMode::Copy,
|
||||
path.baseName(),
|
||||
ContentAddressMethod::Raw::NixArchive,
|
||||
nullptr,
|
||||
@@ -2731,9 +2794,12 @@ void EvalState::assertEqValues(Value & v1, Value & v2, const PosIdx pos, std::st
|
||||
return;
|
||||
|
||||
case nAttrs: {
|
||||
const Bindings & attrs1 = *v1.attrs();
|
||||
const Bindings & attrs2 = *v2.attrs();
|
||||
|
||||
if (isDerivation(v1) && isDerivation(v2)) {
|
||||
auto i = v1.attrs()->get(s.outPath);
|
||||
auto j = v2.attrs()->get(s.outPath);
|
||||
auto i = attrs1.get(s.outPath);
|
||||
auto j = attrs2.get(s.outPath);
|
||||
if (i && j) {
|
||||
try {
|
||||
assertEqValues(*i->value, *j->value, pos, errorCtx);
|
||||
@@ -2746,7 +2812,7 @@ void EvalState::assertEqValues(Value & v1, Value & v2, const PosIdx pos, std::st
|
||||
}
|
||||
}
|
||||
|
||||
if (v1.attrs()->size() != v2.attrs()->size()) {
|
||||
if (attrs1.size() != attrs2.size()) {
|
||||
error<AssertionError>(
|
||||
"attribute names of attribute set '%s' differs from attribute set '%s'",
|
||||
ValuePrinter(*this, v1, errorPrintOptions),
|
||||
@@ -2754,12 +2820,8 @@ void EvalState::assertEqValues(Value & v1, Value & v2, const PosIdx pos, std::st
|
||||
.debugThrow();
|
||||
}
|
||||
|
||||
// Like normal comparison, we compare the attributes in non-deterministic Symbol index order.
|
||||
// This function is called when eqValues has found a difference, so to reliably
|
||||
// report about its result, we should follow in its literal footsteps and not
|
||||
// try anything fancy that could lead to an error.
|
||||
Bindings::const_iterator i, j;
|
||||
for (i = v1.attrs()->begin(), j = v2.attrs()->begin(); i != v1.attrs()->end(); ++i, ++j) {
|
||||
/* This mirrors what EvalState::eqValues does. See the corresponding comment there. */
|
||||
for (auto i = attrs1.begin(), j = attrs2.begin(); i != attrs1.end(); ++i, ++j) {
|
||||
if (i->name != j->name) {
|
||||
// A difference in a sorted list means that one attribute is not contained in the other, but we don't
|
||||
// know which. Let's find out. Could use <, but this is more clear.
|
||||
@@ -2781,6 +2843,22 @@ void EvalState::assertEqValues(Value & v1, Value & v2, const PosIdx pos, std::st
|
||||
}
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
/* Comparing in lexicographical order is crucial for determinism. Short-circuiting
|
||||
the comparison without a canonical ordering of iteration would mean that depending
|
||||
on the global symbol table order this could either fail or successfully evaluate if
|
||||
forcing an attribute leads to an error.
|
||||
This function is called when eqValues has found a difference, so to reliably
|
||||
report about its result, we should follow in its literal footsteps and not
|
||||
try anything fancy that could lead to an error. */
|
||||
boost::container::small_vector<Attr, conservativeStackReservation> sorted1;
|
||||
v1.attrs()->lexicographicOrder(sorted1, symbols);
|
||||
boost::container::small_vector<Attr, conservativeStackReservation> sorted2;
|
||||
v2.attrs()->lexicographicOrder(sorted2, symbols);
|
||||
|
||||
for (auto i = sorted1.begin(), j = sorted2.begin(); i != sorted1.end(); ++i, ++j) {
|
||||
assert(i->name == j->name);
|
||||
try {
|
||||
assertEqValues(*i->value, *j->value, pos, errorCtx);
|
||||
} catch (Error & e) {
|
||||
@@ -2822,8 +2900,11 @@ void EvalState::assertEqValues(Value & v1, Value & v2, const PosIdx pos, std::st
|
||||
}
|
||||
return;
|
||||
|
||||
case nThunk: // Must not be left by forceValue
|
||||
assert(false);
|
||||
// Cannot be returned by forceValue().
|
||||
case nThunk:
|
||||
case nFailed:
|
||||
unreachable();
|
||||
|
||||
default: // Note that we pass compiler flags that should make `default:` unreachable.
|
||||
// Also note that this probably ran after `eqValues`, which implements
|
||||
// the same logic more efficiently (without having to unwind stacks),
|
||||
@@ -2885,23 +2966,46 @@ bool EvalState::eqValues(Value & v1, Value & v2, const PosIdx pos, std::string_v
|
||||
return true;
|
||||
|
||||
case nAttrs: {
|
||||
const Bindings & attrs1 = *v1.attrs();
|
||||
const Bindings & attrs2 = *v2.attrs();
|
||||
|
||||
/* If both sets denote a derivation (type = "derivation"),
|
||||
then compare their outPaths. */
|
||||
if (isDerivation(v1) && isDerivation(v2)) {
|
||||
auto i = v1.attrs()->get(s.outPath);
|
||||
auto j = v2.attrs()->get(s.outPath);
|
||||
auto i = attrs1.get(s.outPath);
|
||||
auto j = attrs2.get(s.outPath);
|
||||
if (i && j)
|
||||
return eqValues(*i->value, *j->value, pos, errorCtx);
|
||||
}
|
||||
|
||||
if (v1.attrs()->size() != v2.attrs()->size())
|
||||
if (attrs1.size() != attrs2.size())
|
||||
return false;
|
||||
|
||||
/* Otherwise, compare the attributes one by one. */
|
||||
Bindings::const_iterator i, j;
|
||||
for (i = v1.attrs()->begin(), j = v2.attrs()->begin(); i != v1.attrs()->end(); ++i, ++j)
|
||||
if (i->name != j->name || !eqValues(*i->value, *j->value, pos, errorCtx))
|
||||
/* Compare in 2 passes: first make sure the attribute keys are equal
|
||||
without evaluating or recursing into values. Historically, attribute
|
||||
set comparison has been done in undefined symbol table order. This
|
||||
approach is compatible with nondeterministic iteration order. */
|
||||
for (auto i = attrs1.begin(), j = attrs2.begin(); i != attrs1.end(); ++i, ++j) {
|
||||
/* If we do SoA transformation for Bindings then this could just be a memcmp. */
|
||||
if (i->name != j->name)
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Comparing in lexicographical order is crucial for determinism. Short-circuiting
|
||||
the comparison without a canonical ordering of iteration would mean that depending
|
||||
on the global symbol table order this could either fail or successfully evaluate if
|
||||
forcing an attribute leads to an error. */
|
||||
boost::container::small_vector<Attr, conservativeStackReservation> sorted1;
|
||||
v1.attrs()->lexicographicOrder(sorted1, symbols);
|
||||
boost::container::small_vector<Attr, conservativeStackReservation> sorted2;
|
||||
v2.attrs()->lexicographicOrder(sorted2, symbols);
|
||||
|
||||
/* Otherwise, compare the attributes one by one. */
|
||||
for (auto i = sorted1.begin(), j = sorted2.begin(); i != sorted1.end(); ++i, ++j) {
|
||||
assert(i->name == j->name);
|
||||
if (!eqValues(*i->value, *j->value, pos, errorCtx))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -2917,8 +3021,11 @@ bool EvalState::eqValues(Value & v1, Value & v2, const PosIdx pos, std::string_v
|
||||
// !!!
|
||||
return v1.fpoint() == v2.fpoint();
|
||||
|
||||
case nThunk: // Must not be left by forceValue
|
||||
assert(false);
|
||||
// Cannot be returned by forceValue().
|
||||
case nThunk:
|
||||
case nFailed:
|
||||
unreachable();
|
||||
|
||||
default: // Note that we pass compiler flags that should make `default:` unreachable.
|
||||
error<EvalError>("eqValues: cannot compare %1% with %2%", showType(v1), showType(v2))
|
||||
.withTrace(pos, errorCtx)
|
||||
@@ -3139,6 +3246,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
|
||||
@@ -3280,6 +3402,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];
|
||||
|
||||
@@ -414,6 +414,29 @@ public:
|
||||
|
||||
void sort();
|
||||
|
||||
/**
|
||||
* Get the attributes in lexicographically sorted order. Needed for deterministic
|
||||
* iteration order.
|
||||
*
|
||||
* @note Unlike the overload returning a vector of const Attr *, this
|
||||
* copies the attribute values into a @ref out container by value. This is
|
||||
* to reduce the amount of indirection. Note that the resulting attribute
|
||||
* values are copies and one must not use a pointer to the Attr object for
|
||||
* any purpose other than reading its members.
|
||||
*/
|
||||
template<typename C>
|
||||
void lexicographicOrder(C & out, const SymbolTable & symbols) const
|
||||
{
|
||||
out.reserve(size());
|
||||
for (auto attr : *this)
|
||||
out.push_back(attr);
|
||||
assert(out.size() == size());
|
||||
std::sort(out.begin(), out.end(), [&symbols](const Attr & a, const Attr & b) {
|
||||
std::string_view sa = symbols[a.name], sb = symbols[b.name];
|
||||
return sa < sb;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the attributes in lexicographically sorted order.
|
||||
*/
|
||||
|
||||
@@ -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
|
||||
@@ -14,7 +14,7 @@ namespace nix::eval_cache {
|
||||
struct AttrDb;
|
||||
class AttrCursor;
|
||||
|
||||
struct CachedEvalError : EvalError
|
||||
struct CachedEvalError : CloneableError<CachedEvalError, EvalError>
|
||||
{
|
||||
const ref<AttrCursor> cursor;
|
||||
const Symbol attr;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "nix/util/error.hh"
|
||||
#include "nix/util/pos-idx.hh"
|
||||
#include "nix/store/path.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
@@ -18,7 +19,7 @@ class EvalErrorBuilder;
|
||||
*
|
||||
* Most subclasses should inherit from `EvalError` instead of this class.
|
||||
*/
|
||||
class EvalBaseError : public Error
|
||||
class EvalBaseError : public CloneableError<EvalBaseError, Error>
|
||||
{
|
||||
template<class T>
|
||||
friend class EvalErrorBuilder;
|
||||
@@ -26,14 +27,14 @@ public:
|
||||
EvalState & state;
|
||||
|
||||
EvalBaseError(EvalState & state, ErrorInfo && errorInfo)
|
||||
: Error(errorInfo)
|
||||
: CloneableError(errorInfo)
|
||||
, state(state)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
explicit EvalBaseError(EvalState & state, const std::string & formatString, const Args &... formatArgs)
|
||||
: Error(formatString, formatArgs...)
|
||||
: CloneableError(formatString, formatArgs...)
|
||||
, state(state)
|
||||
{
|
||||
}
|
||||
@@ -60,25 +61,30 @@ MakeError(InfiniteRecursionError, EvalError);
|
||||
* Inherits from EvalBaseError (not EvalError) because resource exhaustion
|
||||
* should not be cached.
|
||||
*/
|
||||
struct StackOverflowError : public EvalBaseError
|
||||
struct StackOverflowError : public CloneableError<StackOverflowError, EvalBaseError>
|
||||
{
|
||||
StackOverflowError(EvalState & state)
|
||||
: EvalBaseError(state, "stack overflow; max-call-depth exceeded")
|
||||
: CloneableError(state, "stack overflow; max-call-depth exceeded")
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
MakeError(IFDError, EvalBaseError);
|
||||
|
||||
struct InvalidPathError : public EvalError
|
||||
/**
|
||||
* An evaluation error which should be retried instead of rethrown.
|
||||
*
|
||||
* A RecoverableEvalError is not an EvalError, because we shouldn't cache it in
|
||||
* the eval cache, as it should be retried anyway.
|
||||
*/
|
||||
MakeError(RecoverableEvalError, EvalBaseError);
|
||||
|
||||
struct InvalidPathError : public CloneableError<InvalidPathError, EvalError>
|
||||
{
|
||||
public:
|
||||
Path path;
|
||||
StorePath path;
|
||||
|
||||
InvalidPathError(EvalState & state, const Path & path)
|
||||
: EvalError(state, "path '%s' is not valid", path)
|
||||
{
|
||||
}
|
||||
InvalidPathError(EvalState & state, const StorePath & path);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,6 +33,9 @@ using gc_allocator = std::allocator<T>;
|
||||
struct gc
|
||||
{};
|
||||
|
||||
struct gc_cleanup
|
||||
{};
|
||||
|
||||
#endif
|
||||
|
||||
namespace nix {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "nix/expr/eval.hh"
|
||||
#include "nix/expr/eval-error.hh"
|
||||
#include "nix/expr/eval-settings.hh"
|
||||
#include <exception>
|
||||
|
||||
namespace nix {
|
||||
|
||||
@@ -91,18 +92,25 @@ void EvalState::forceValue(Value & v, const PosIdx pos)
|
||||
Expr * expr = v.thunk().expr;
|
||||
try {
|
||||
v.mkBlackhole();
|
||||
// checkInterrupt();
|
||||
if (env) [[likely]]
|
||||
expr->eval(*this, *env, v);
|
||||
else
|
||||
ExprBlackHole::throwInfiniteRecursionError(*this, v);
|
||||
} catch (...) {
|
||||
v.mkThunk(env, expr);
|
||||
tryFixupBlackHolePos(v, pos);
|
||||
handleEvalExceptionForThunk(env, expr, v, pos);
|
||||
throw;
|
||||
}
|
||||
} else if (v.isApp())
|
||||
callFunction(*v.app().left, *v.app().right, v, pos);
|
||||
} else if (v.isApp()) {
|
||||
Value savedApp = v;
|
||||
try {
|
||||
callFunction(*v.app().left, *v.app().right, v, pos);
|
||||
} catch (...) {
|
||||
handleEvalExceptionForApp(v, savedApp);
|
||||
throw;
|
||||
}
|
||||
} else if (v.isFailed()) {
|
||||
handleEvalFailed(v, pos);
|
||||
}
|
||||
}
|
||||
|
||||
[[gnu::always_inline]]
|
||||
|
||||
@@ -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"
|
||||
@@ -9,15 +10,39 @@ namespace nix {
|
||||
|
||||
class EvalState;
|
||||
struct PrimOp;
|
||||
class Settings;
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
/**
|
||||
* Reference to the "parent" store-layer settings.
|
||||
*/
|
||||
nix::Settings & storeSettings;
|
||||
|
||||
/**
|
||||
* Function used to interpret look path entries of a given scheme.
|
||||
*
|
||||
@@ -44,9 +69,11 @@ struct EvalSettings : Config
|
||||
*/
|
||||
using LookupPathHooks = std::map<std::string, std::function<LookupPathHook>>;
|
||||
|
||||
EvalSettings(nix::Settings & settings, LookupPathHooks lookupPathHooks = {});
|
||||
EvalSettings(bool & readOnlyMode, LookupPathHooks lookupPathHooks = {});
|
||||
|
||||
static Strings getDefaultNixPath(nix::Settings & settings);
|
||||
bool & readOnlyMode;
|
||||
|
||||
static Strings getDefaultNixPath();
|
||||
|
||||
static bool isPseudoUrl(std::string_view s);
|
||||
|
||||
@@ -332,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,
|
||||
@@ -370,6 +447,6 @@ struct EvalSettings : Config
|
||||
/**
|
||||
* Conventionally part of the default nix path in impure mode.
|
||||
*/
|
||||
std::filesystem::path getNixDefExpr(const Settings & settings);
|
||||
std::filesystem::path getNixDefExpr();
|
||||
|
||||
} // namespace nix
|
||||
@@ -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();
|
||||
|
||||
/**
|
||||
@@ -652,8 +664,28 @@ public:
|
||||
*/
|
||||
inline void forceValue(Value & v, const PosIdx pos);
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Internal support function for forceValue
|
||||
*
|
||||
* This code is factored out so that it's not in the heavily inlined hot path.
|
||||
*/
|
||||
void handleEvalExceptionForThunk(Env * env, Expr * expr, Value & v, const PosIdx pos);
|
||||
|
||||
/**
|
||||
* Internal support function for forceValue
|
||||
*
|
||||
* This code is factored out so that it's not in the heavily inlined hot path.
|
||||
*/
|
||||
void handleEvalExceptionForApp(Value & v, const Value & savedApp);
|
||||
|
||||
void handleEvalFailed(Value & v, PosIdx pos);
|
||||
|
||||
void tryFixupBlackHolePos(Value & v, PosIdx pos);
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Force a value, then recursively force list elements and
|
||||
* attributes.
|
||||
@@ -867,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.
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <memory_resource>
|
||||
#include <exception>
|
||||
#include <span>
|
||||
#include <string_view>
|
||||
#include <type_traits>
|
||||
@@ -35,27 +36,32 @@ class BindingsBuilder;
|
||||
* about how this is mapped into the alignment bits to save significant memory.
|
||||
* This also restricts the number of internal types represented with distinct memory layouts.
|
||||
*/
|
||||
typedef enum {
|
||||
enum InternalType {
|
||||
tUninitialized = 0,
|
||||
/* layout: Single/zero field payload */
|
||||
tInt = 1,
|
||||
tBool,
|
||||
tNull,
|
||||
tFloat,
|
||||
tFailed,
|
||||
tExternal,
|
||||
tPrimOp,
|
||||
tAttrs,
|
||||
/* layout: Pair of pointers payload */
|
||||
tListSmall,
|
||||
tFirstPairOfPointers,
|
||||
tListSmall = tFirstPairOfPointers,
|
||||
tPrimOpApp,
|
||||
tApp,
|
||||
tThunk,
|
||||
tLambda,
|
||||
tLastPairOfPointers = tLambda,
|
||||
/* layout: Single untaggable field */
|
||||
tListN,
|
||||
tFirstSingleUntaggable,
|
||||
tListN = tFirstSingleUntaggable,
|
||||
tString,
|
||||
tPath,
|
||||
} InternalType;
|
||||
tNumberOfInternalTypes, // Must be last
|
||||
};
|
||||
|
||||
/**
|
||||
* This type abstracts over all actual value types in the language,
|
||||
@@ -64,6 +70,7 @@ typedef enum {
|
||||
*/
|
||||
typedef enum {
|
||||
nThunk,
|
||||
nFailed,
|
||||
nInt,
|
||||
nFloat,
|
||||
nBool,
|
||||
@@ -420,6 +427,36 @@ struct ValueBase
|
||||
size_t size;
|
||||
Value * const * elems;
|
||||
};
|
||||
|
||||
struct Failed : gc_cleanup
|
||||
{
|
||||
std::exception_ptr ex;
|
||||
/**
|
||||
* Optional value for recovering `RecoverableEvalError`
|
||||
* Must be set iff `ex` is an instance of `RecoverableEvalError`.
|
||||
*/
|
||||
Value * recoveryValue;
|
||||
|
||||
Failed(std::exception_ptr ex, Value * recoveryValue)
|
||||
: ex(ex)
|
||||
, recoveryValue(recoveryValue)
|
||||
{
|
||||
}
|
||||
|
||||
[[noreturn]] void rethrow() const
|
||||
{
|
||||
try {
|
||||
std::rethrow_exception(ex);
|
||||
} catch (BaseError & e) {
|
||||
/* Rethrow the copy of the exception - not the original one.
|
||||
Stack tracing mechanisms rely on being able to modify the exceptions
|
||||
they catch by reference. */
|
||||
e.throwClone();
|
||||
} catch (...) {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
@@ -446,6 +483,7 @@ struct PayloadTypeToInternalType
|
||||
MACRO(PrimOp *, primOp, tPrimOp) \
|
||||
MACRO(ValueBase::PrimOpApplicationThunk, primOpApp, tPrimOpApp) \
|
||||
MACRO(ExternalValueBase *, external, tExternal) \
|
||||
MACRO(ValueBase::Failed *, failed, tFailed) \
|
||||
MACRO(NixFloat, fpoint, tFloat)
|
||||
|
||||
#define NIX_VALUE_PAYLOAD_TYPE(T, FIELD_NAME, DISCRIMINATOR) \
|
||||
@@ -633,7 +671,7 @@ class alignas(16)
|
||||
template<InternalType type, typename T, typename U>
|
||||
void setPairOfPointersPayload(T * firstPtrField, U * secondPtrField) noexcept
|
||||
{
|
||||
static_assert(type >= tListSmall && type <= tLambda);
|
||||
static_assert(type >= tFirstPairOfPointers && type <= tLastPairOfPointers);
|
||||
{
|
||||
auto firstFieldPayload = std::bit_cast<PackedPointer>(firstPtrField);
|
||||
assertAligned(firstFieldPayload);
|
||||
@@ -642,7 +680,7 @@ class alignas(16)
|
||||
{
|
||||
auto secondFieldPayload = std::bit_cast<PackedPointer>(secondPtrField);
|
||||
assertAligned(secondFieldPayload);
|
||||
payload[1] = (type - tListSmall) | secondFieldPayload;
|
||||
payload[1] = (type - tFirstPairOfPointers) | secondFieldPayload;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -670,11 +708,11 @@ protected:
|
||||
case pdListN:
|
||||
case pdString:
|
||||
case pdPath:
|
||||
return static_cast<InternalType>(tListN + (pd - pdListN));
|
||||
return static_cast<InternalType>(tFirstSingleUntaggable + (pd - pdListN));
|
||||
case pdPairOfPointers:
|
||||
return static_cast<InternalType>(tListSmall + (payload[1] & discriminatorMask));
|
||||
return static_cast<InternalType>(tFirstPairOfPointers + (payload[1] & discriminatorMask));
|
||||
[[unlikely]] default:
|
||||
unreachable();
|
||||
nixUnreachableWhenHardened();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -750,6 +788,11 @@ protected:
|
||||
path.path = std::bit_cast<const StringData *>(payload[1]);
|
||||
}
|
||||
|
||||
void getStorage(Failed *& failed) const noexcept
|
||||
{
|
||||
failed = std::bit_cast<Failed *>(payload[1]);
|
||||
}
|
||||
|
||||
void setStorage(NixInt integer) noexcept
|
||||
{
|
||||
setSingleDWordPayload<tInt>(integer.value);
|
||||
@@ -799,6 +842,11 @@ protected:
|
||||
{
|
||||
setUntaggablePayload<pdPath>(path.accessor, path.path);
|
||||
}
|
||||
|
||||
void setStorage(Failed * failed) noexcept
|
||||
{
|
||||
setSingleDWordPayload<tFailed>(std::bit_cast<PackedPointer>(failed));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -1027,7 +1075,7 @@ private:
|
||||
T getStorage() const noexcept
|
||||
{
|
||||
if (getInternalType() != detail::payloadTypeToInternalType<T>) [[unlikely]]
|
||||
unreachable();
|
||||
nixUnreachableWhenHardened();
|
||||
T out;
|
||||
ValueStorage::getStorage(out);
|
||||
return out;
|
||||
@@ -1050,12 +1098,12 @@ public:
|
||||
inline bool isThunk() const
|
||||
{
|
||||
return isa<tThunk>();
|
||||
};
|
||||
}
|
||||
|
||||
inline bool isApp() const
|
||||
{
|
||||
return isa<tApp>();
|
||||
};
|
||||
}
|
||||
|
||||
inline bool isBlackhole() const;
|
||||
|
||||
@@ -1063,61 +1111,66 @@ public:
|
||||
inline bool isLambda() const
|
||||
{
|
||||
return isa<tLambda>();
|
||||
};
|
||||
}
|
||||
|
||||
inline bool isPrimOp() const
|
||||
{
|
||||
return isa<tPrimOp>();
|
||||
};
|
||||
}
|
||||
|
||||
inline bool isPrimOpApp() const
|
||||
{
|
||||
return isa<tPrimOpApp>();
|
||||
};
|
||||
}
|
||||
|
||||
inline bool isFailed() const
|
||||
{
|
||||
return isa<tFailed>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the normal type of a Value. This only returns nThunk if
|
||||
* the Value hasn't been forceValue'd
|
||||
*
|
||||
* @param invalidIsThunk Instead of aborting an an invalid (probably
|
||||
* @param invalidIsThunk Instead of UB an an invalid (probably
|
||||
* 0, so uninitialized) internal type, return `nThunk`.
|
||||
*/
|
||||
inline ValueType type(bool invalidIsThunk = false) const
|
||||
template<bool invalidIsThunk = false>
|
||||
inline ValueType type() const
|
||||
{
|
||||
switch (getInternalType()) {
|
||||
case tUninitialized:
|
||||
break;
|
||||
case tInt:
|
||||
return nInt;
|
||||
case tBool:
|
||||
return nBool;
|
||||
case tString:
|
||||
return nString;
|
||||
case tPath:
|
||||
return nPath;
|
||||
case tNull:
|
||||
return nNull;
|
||||
case tAttrs:
|
||||
return nAttrs;
|
||||
case tListSmall:
|
||||
case tListN:
|
||||
return nList;
|
||||
case tLambda:
|
||||
case tPrimOp:
|
||||
case tPrimOpApp:
|
||||
return nFunction;
|
||||
case tExternal:
|
||||
return nExternal;
|
||||
case tFloat:
|
||||
return nFloat;
|
||||
case tThunk:
|
||||
case tApp:
|
||||
return nThunk;
|
||||
/* Explicit lookup table. switch() might compile down (and it does at least with GCC 14)
|
||||
to a jump table. Let's help the compiler a bit here. */
|
||||
static constexpr auto table = [] {
|
||||
std::array<ValueType, tNumberOfInternalTypes> t{};
|
||||
t[tUninitialized] = nThunk;
|
||||
t[tInt] = nInt;
|
||||
t[tBool] = nBool;
|
||||
t[tNull] = nNull;
|
||||
t[tFloat] = nFloat;
|
||||
t[tFailed] = nFailed;
|
||||
t[tExternal] = nExternal;
|
||||
t[tAttrs] = nAttrs;
|
||||
t[tPrimOp] = nFunction;
|
||||
t[tLambda] = nFunction;
|
||||
t[tPrimOpApp] = nFunction;
|
||||
t[tApp] = nThunk;
|
||||
t[tThunk] = nThunk;
|
||||
t[tListSmall] = nList;
|
||||
t[tListN] = nList;
|
||||
t[tString] = nString;
|
||||
t[tPath] = nPath;
|
||||
return t;
|
||||
}();
|
||||
|
||||
auto it = getInternalType();
|
||||
if (it == tUninitialized || it >= tNumberOfInternalTypes) [[unlikely]] {
|
||||
if constexpr (invalidIsThunk)
|
||||
return nThunk;
|
||||
else
|
||||
nixUnreachableWhenHardened();
|
||||
}
|
||||
if (invalidIsThunk)
|
||||
return nThunk;
|
||||
else
|
||||
unreachable();
|
||||
|
||||
return table[it];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1232,6 +1285,11 @@ public:
|
||||
setStorage(n);
|
||||
}
|
||||
|
||||
inline void mkFailed(std::exception_ptr e, Value * recovery) noexcept
|
||||
{
|
||||
setStorage(new Value::Failed(e, recovery));
|
||||
}
|
||||
|
||||
bool isList() const noexcept
|
||||
{
|
||||
return isa<tListSmall, tListN>();
|
||||
@@ -1346,6 +1404,13 @@ public:
|
||||
{
|
||||
return getStorage<Path>().accessor;
|
||||
}
|
||||
|
||||
Failed & failed() const noexcept
|
||||
{
|
||||
auto p = getStorage<Failed *>();
|
||||
assert(p);
|
||||
return *p;
|
||||
}
|
||||
};
|
||||
|
||||
extern ExprBlackHole eBlackHole;
|
||||
|
||||
@@ -9,14 +9,14 @@
|
||||
|
||||
namespace nix {
|
||||
|
||||
class BadNixStringContextElem : public Error
|
||||
class BadNixStringContextElem final : public CloneableError<BadNixStringContextElem, Error>
|
||||
{
|
||||
public:
|
||||
std::string_view raw;
|
||||
|
||||
template<typename... Args>
|
||||
BadNixStringContextElem(std::string_view raw_, const Args &... args)
|
||||
: Error("")
|
||||
: CloneableError("")
|
||||
{
|
||||
raw = raw_;
|
||||
auto hf = HintFmt(args...);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,7 +28,7 @@ deps_public_maybe_subproject = [
|
||||
subdir('nix-meson-build-support/subprojects')
|
||||
subdir('nix-meson-build-support/big-objs')
|
||||
|
||||
# Check for each of these functions, and create a define like `#define HAVE_LCHOWN 1`.
|
||||
# Check for each of these functions, and create a define like `#define HAVE_SYSCONF 1`.
|
||||
check_funcs = [
|
||||
'sysconf',
|
||||
]
|
||||
@@ -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
@@ -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"
|
||||
@@ -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)
|
||||
|
||||
+50
-49
@@ -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));
|
||||
@@ -562,6 +563,7 @@ static void prim_typeOf(EvalState & state, const PosIdx pos, Value ** args, Valu
|
||||
v.mkStringNoCopy("float"_sds);
|
||||
break;
|
||||
case nThunk:
|
||||
case nFailed:
|
||||
unreachable();
|
||||
}
|
||||
}
|
||||
@@ -1312,11 +1314,12 @@ static void prim_warn(EvalState & state, const PosIdx pos, Value ** args, Value
|
||||
state.forceString(*args[0], pos, "while evaluating the first argument; the message passed to builtins.warn");
|
||||
|
||||
{
|
||||
BaseError msg(std::string{msgStr});
|
||||
msg.atPos(state.positions[pos]);
|
||||
auto info = msg.info();
|
||||
info.level = lvlWarn;
|
||||
info.isFromExpr = true;
|
||||
ErrorInfo info{
|
||||
.level = lvlWarn,
|
||||
.msg = HintFmt(std::string(msgStr)),
|
||||
.pos = state.positions[pos],
|
||||
.isFromExpr = true,
|
||||
};
|
||||
logWarning(info);
|
||||
}
|
||||
|
||||
@@ -1819,8 +1822,8 @@ static void derivationStrictInternal(EvalState & state, std::string_view drvName
|
||||
Unless we are in read-only mode, that is, in which case we do not
|
||||
write anything. Users commonly do this to speed up evaluation in
|
||||
contexts where they don't actually want to build anything. */
|
||||
auto drvPath = state.settings.storeSettings.readOnlyMode ? computeStorePath(*state.store, drv)
|
||||
: state.store->writeDerivation(drv, state.repair);
|
||||
auto drvPath =
|
||||
settings.readOnlyMode ? computeStorePath(*state.store, drv) : state.store->writeDerivation(drv, state.repair);
|
||||
auto drvPathS = state.store->printStorePath(drvPath);
|
||||
|
||||
printMsg(lvlChatty, "instantiated '%1%' -> '%2%'", drvName, drvPathS);
|
||||
@@ -1931,11 +1934,11 @@ 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;
|
||||
if (!state.settings.storeSettings.readOnlyMode)
|
||||
if (!settings.readOnlyMode)
|
||||
state.store->ensurePath(path2);
|
||||
context.insert(NixStringContextElem::Opaque{.path = path2});
|
||||
v.mkString(path.abs(), context, state.mem);
|
||||
@@ -2152,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();
|
||||
}
|
||||
@@ -2676,24 +2679,23 @@ static void prim_toFile(EvalState & state, const PosIdx pos, Value ** args, Valu
|
||||
.debugThrow();
|
||||
}
|
||||
|
||||
auto storePath = state.settings.storeSettings.readOnlyMode
|
||||
? state.store->makeFixedOutputPathFromCA(
|
||||
name,
|
||||
TextInfo{
|
||||
.hash = hashString(HashAlgorithm::SHA256, contents),
|
||||
.references = std::move(refs),
|
||||
})
|
||||
: ({
|
||||
StringSource s{contents};
|
||||
state.store->addToStoreFromDump(
|
||||
s,
|
||||
name,
|
||||
FileSerialisationMethod::Flat,
|
||||
ContentAddressMethod::Raw::Text,
|
||||
HashAlgorithm::SHA256,
|
||||
refs,
|
||||
state.repair);
|
||||
});
|
||||
auto storePath = settings.readOnlyMode ? state.store->makeFixedOutputPathFromCA(
|
||||
name,
|
||||
TextInfo{
|
||||
.hash = hashString(HashAlgorithm::SHA256, contents),
|
||||
.references = std::move(refs),
|
||||
})
|
||||
: ({
|
||||
StringSource s{contents};
|
||||
state.store->addToStoreFromDump(
|
||||
s,
|
||||
name,
|
||||
FileSerialisationMethod::Flat,
|
||||
ContentAddressMethod::Raw::Text,
|
||||
HashAlgorithm::SHA256,
|
||||
refs,
|
||||
state.repair);
|
||||
});
|
||||
|
||||
/* Note: we don't need to add `context' to the context of the
|
||||
result, since `storePath' itself has references to the paths
|
||||
@@ -2837,24 +2839,23 @@ static void addPath(
|
||||
|
||||
if (!expectedHash || !state.store->isValidPath(*expectedStorePath)) {
|
||||
// FIXME: support refs in fetchToStore()?
|
||||
auto dstPath = refs.empty()
|
||||
? fetchToStore(
|
||||
state.fetchSettings,
|
||||
*state.store,
|
||||
path.resolveSymlinks(),
|
||||
state.settings.storeSettings.readOnlyMode ? FetchMode::DryRun : FetchMode::Copy,
|
||||
name,
|
||||
method,
|
||||
filter.get(),
|
||||
state.repair)
|
||||
: state.store->addToStore(
|
||||
name,
|
||||
path.resolveSymlinks(),
|
||||
method,
|
||||
HashAlgorithm::SHA256,
|
||||
refs,
|
||||
filter ? *filter.get() : defaultPathFilter,
|
||||
state.repair);
|
||||
auto dstPath = refs.empty() ? fetchToStore(
|
||||
state.fetchSettings,
|
||||
*state.store,
|
||||
path.resolveSymlinks(),
|
||||
settings.readOnlyMode ? FetchMode::DryRun : FetchMode::Copy,
|
||||
name,
|
||||
method,
|
||||
filter.get(),
|
||||
state.repair)
|
||||
: state.store->addToStore(
|
||||
name,
|
||||
path.resolveSymlinks(),
|
||||
method,
|
||||
HashAlgorithm::SHA256,
|
||||
refs,
|
||||
filter ? *filter.get() : defaultPathFilter,
|
||||
state.repair);
|
||||
if (expectedHash && expectedStorePath != dstPath)
|
||||
state.error<EvalError>("store path mismatch in (possibly filtered) path added from '%s'", path)
|
||||
.atPos(pos)
|
||||
|
||||
@@ -271,7 +271,7 @@ static void prim_appendContext(EvalState & state, const PosIdx pos, Value ** arg
|
||||
if (!state.store->isStorePath(name))
|
||||
state.error<EvalError>("context key '%s' is not a store path", name).atPos(i.pos).debugThrow();
|
||||
auto namePath = state.store->parseStorePath(name);
|
||||
if (!state.settings.storeSettings.readOnlyMode)
|
||||
if (!settings.readOnlyMode)
|
||||
state.store->ensurePath(namePath);
|
||||
state.forceAttrs(*i.value, i.pos, "while evaluating the value of a string context");
|
||||
|
||||
|
||||
@@ -209,7 +209,7 @@ static void prim_fetchClosure(EvalState & state, const PosIdx pos, Value ** args
|
||||
{.msg = HintFmt("'fetchClosure' does not support URL query parameters (in '%s')", *fromStoreUrl),
|
||||
.pos = state.positions[pos]});
|
||||
|
||||
auto fromStore = openStore(state.settings.storeSettings, std::move(storeRef));
|
||||
auto fromStore = openStore(std::move(storeRef));
|
||||
|
||||
if (toPath)
|
||||
runFetchClosureWithRewrite(state, pos, *fromStore, *fromPath, *toPath, v);
|
||||
|
||||
@@ -73,6 +73,11 @@ void printAmbiguous(EvalState & state, Value & v, std::ostream & str, std::set<c
|
||||
str << "«potential infinite recursion»";
|
||||
}
|
||||
break;
|
||||
case nFailed:
|
||||
// Historically, a tried and then ignored value (e.g. through tryEval) was
|
||||
// reverted to the original thunk.
|
||||
str << "<CODE>";
|
||||
break;
|
||||
case nFunction:
|
||||
if (v.isLambda()) {
|
||||
str << "<LAMBDA>";
|
||||
|
||||
@@ -509,6 +509,17 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
void printFailed()
|
||||
{
|
||||
if (options.ansiColors)
|
||||
output << ANSI_MAGENTA;
|
||||
// Historically, a tried and then ignored value (e.g. through tryEval) was
|
||||
// reverted to the original thunk.
|
||||
output << "«thunk»";
|
||||
if (options.ansiColors)
|
||||
output << ANSI_NORMAL;
|
||||
}
|
||||
|
||||
void printExternal(Value & v)
|
||||
{
|
||||
v.external()->print(output);
|
||||
@@ -590,6 +601,10 @@ private:
|
||||
printFunction(v);
|
||||
break;
|
||||
|
||||
case nFailed:
|
||||
printFailed();
|
||||
break;
|
||||
|
||||
case nThunk:
|
||||
printThunk(v);
|
||||
break;
|
||||
|
||||
@@ -98,6 +98,7 @@ json printValueAsJSON(
|
||||
break;
|
||||
|
||||
case nThunk:
|
||||
case nFailed:
|
||||
case nFunction:
|
||||
state.error<TypeError>("cannot convert %1% to JSON", showType(v)).atPos(v.determinePos(pos)).debugThrow();
|
||||
}
|
||||
|
||||
@@ -171,7 +171,11 @@ static void printValueAsXML(
|
||||
break;
|
||||
|
||||
case nThunk:
|
||||
// Historically, a tried and then ignored value (e.g. through tryEval) was
|
||||
// reverted to the original thunk.
|
||||
case nFailed:
|
||||
doc.writeEmptyElement("unevaluated");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
#include "nix_api_fetchers.h"
|
||||
#include "nix_api_fetchers_internal.hh"
|
||||
#include "nix_api_util_internal.h"
|
||||
#include "nix_api_store_internal.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
nix_fetchers_settings * nix_fetchers_settings_new(nix_c_context * context)
|
||||
{
|
||||
try {
|
||||
auto fetchersSettings = nix::make_ref<nix::fetchers::Settings>(nix::fetchers::Settings{cStoreSettings});
|
||||
auto fetchersSettings = nix::make_ref<nix::fetchers::Settings>(nix::fetchers::Settings{});
|
||||
return new nix_fetchers_settings{
|
||||
.settings = fetchersSettings,
|
||||
};
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "nix/util/json-utils.hh"
|
||||
#include "nix/store/globals.hh"
|
||||
#include "nix/fetchers/fetchers.hh"
|
||||
#include "nix/fetchers/fetch-settings.hh"
|
||||
|
||||
#include "nix/store/tests/test-main.hh"
|
||||
#include "nix/util/json-utils.hh"
|
||||
#include "nix/util/tests/characterization.hh"
|
||||
|
||||
namespace nix::fetchers {
|
||||
@@ -28,8 +25,7 @@ public:
|
||||
|
||||
TEST_F(AccessKeysTest, singleOrgGitHub)
|
||||
{
|
||||
auto settings = getTestSettings();
|
||||
fetchers::Settings fetchSettings = fetchers::Settings{settings};
|
||||
fetchers::Settings fetchSettings = fetchers::Settings{};
|
||||
fetchSettings.accessTokens.get().insert({"github.com/a", "token"});
|
||||
auto i = Input::fromURL(fetchSettings, "github:a/b");
|
||||
|
||||
@@ -39,8 +35,7 @@ TEST_F(AccessKeysTest, singleOrgGitHub)
|
||||
|
||||
TEST_F(AccessKeysTest, nonMatches)
|
||||
{
|
||||
auto settings = getTestSettings();
|
||||
fetchers::Settings fetchSettings = fetchers::Settings{settings};
|
||||
fetchers::Settings fetchSettings = fetchers::Settings{};
|
||||
fetchSettings.accessTokens.get().insert({"github.com", "token"});
|
||||
auto i = Input::fromURL(fetchSettings, "gitlab:github.com/evil");
|
||||
|
||||
@@ -50,8 +45,7 @@ TEST_F(AccessKeysTest, nonMatches)
|
||||
|
||||
TEST_F(AccessKeysTest, noPartialMatches)
|
||||
{
|
||||
auto settings = getTestSettings();
|
||||
fetchers::Settings fetchSettings = fetchers::Settings{settings};
|
||||
fetchers::Settings fetchSettings = fetchers::Settings{};
|
||||
fetchSettings.accessTokens.get().insert({"github.com/partial", "token"});
|
||||
auto i = Input::fromURL(fetchSettings, "github:partial-match/repo");
|
||||
|
||||
@@ -61,8 +55,7 @@ TEST_F(AccessKeysTest, noPartialMatches)
|
||||
|
||||
TEST_F(AccessKeysTest, repoGitHub)
|
||||
{
|
||||
auto settings = getTestSettings();
|
||||
fetchers::Settings fetchSettings = fetchers::Settings{settings};
|
||||
fetchers::Settings fetchSettings = fetchers::Settings{};
|
||||
fetchSettings.accessTokens.get().insert({"github.com", "token"});
|
||||
fetchSettings.accessTokens.get().insert({"github.com/a/b", "another_token"});
|
||||
fetchSettings.accessTokens.get().insert({"github.com/a/c", "yet_another_token"});
|
||||
@@ -80,8 +73,7 @@ TEST_F(AccessKeysTest, repoGitHub)
|
||||
|
||||
TEST_F(AccessKeysTest, multipleGitLab)
|
||||
{
|
||||
auto settings = getTestSettings();
|
||||
fetchers::Settings fetchSettings = fetchers::Settings{settings};
|
||||
fetchers::Settings fetchSettings = fetchers::Settings{};
|
||||
fetchSettings.accessTokens.get().insert({"gitlab.com", "token"});
|
||||
fetchSettings.accessTokens.get().insert({"gitlab.com/a/b", "another_token"});
|
||||
auto i = Input::fromURL(fetchSettings, "gitlab:a/b");
|
||||
@@ -95,8 +87,7 @@ TEST_F(AccessKeysTest, multipleGitLab)
|
||||
|
||||
TEST_F(AccessKeysTest, multipleSourceHut)
|
||||
{
|
||||
auto settings = getTestSettings();
|
||||
fetchers::Settings fetchSettings = fetchers::Settings{settings};
|
||||
fetchers::Settings fetchSettings = fetchers::Settings{};
|
||||
fetchSettings.accessTokens.get().insert({"git.sr.ht", "token"});
|
||||
fetchSettings.accessTokens.get().insert({"git.sr.ht/~a/b", "another_token"});
|
||||
auto i = Input::fromURL(fetchSettings, "sourcehut:a/b");
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
#include "nix/fetchers/fetchers.hh"
|
||||
#include "nix/fetchers/git-utils.hh"
|
||||
|
||||
#include "nix/store/tests/test-main.hh"
|
||||
|
||||
#include <git2.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
@@ -182,15 +180,13 @@ TEST_F(GitTest, submodulePeriodSupport)
|
||||
// 6) Commit the addition in super
|
||||
commitAll(super.get(), "Add submodule with branch='.'");
|
||||
|
||||
auto settings = getTestSettings();
|
||||
|
||||
auto store = [&] {
|
||||
auto cfg = make_ref<DummyStoreConfig>(settings, StoreReference::Params{});
|
||||
auto store = [] {
|
||||
auto cfg = make_ref<DummyStoreConfig>(StoreReference::Params{});
|
||||
cfg->readOnly = false;
|
||||
return cfg->openStore();
|
||||
}();
|
||||
|
||||
auto fetchSettings = fetchers::Settings{settings};
|
||||
auto settings = fetchers::Settings{};
|
||||
auto input = fetchers::Input::fromAttrs(
|
||||
settings,
|
||||
{
|
||||
@@ -200,7 +196,7 @@ TEST_F(GitTest, submodulePeriodSupport)
|
||||
{"ref", "main"},
|
||||
});
|
||||
|
||||
auto [accessor, i] = input.getAccessor(fetchSettings, *store);
|
||||
auto [accessor, i] = input.getAccessor(settings, *store);
|
||||
|
||||
ASSERT_EQ(accessor->readFile(CanonPath("deps/sub/lib.txt")), "hello from submodule\n");
|
||||
}
|
||||
@@ -1,11 +1,7 @@
|
||||
#include "nix/store/globals.hh"
|
||||
|
||||
#include "nix/fetchers/fetch-settings.hh"
|
||||
#include "nix/fetchers/attrs.hh"
|
||||
#include "nix/fetchers/fetchers.hh"
|
||||
|
||||
#include "nix/store/tests/test-main.hh"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <string>
|
||||
@@ -27,8 +23,7 @@ class InputFromAttrsTest : public ::testing::WithParamInterface<InputFromAttrsTe
|
||||
|
||||
TEST_P(InputFromAttrsTest, attrsAreCorrectAndRoundTrips)
|
||||
{
|
||||
auto settings = getTestSettings();
|
||||
fetchers::Settings fetchSettings{settings};
|
||||
fetchers::Settings fetchSettings;
|
||||
|
||||
const auto & testCase = GetParam();
|
||||
|
||||
|
||||
@@ -44,10 +44,10 @@ struct CacheImpl : Cache
|
||||
{
|
||||
auto state(_state.lock());
|
||||
|
||||
auto dbPath = (getCacheDir() / "fetcher-cache-v4.sqlite").string();
|
||||
createDirs(dirOf(dbPath));
|
||||
auto dbPath = getCacheDir() / "fetcher-cache-v4.sqlite";
|
||||
createDirs(dbPath.parent_path());
|
||||
|
||||
state->db = SQLite(dbPath, {.useWAL = settings.storeSettings.useSQLiteWAL});
|
||||
state->db = SQLite(dbPath, {.useWAL = nix::settings.useSQLiteWAL});
|
||||
state->db.isCache();
|
||||
state->db.exec(schema);
|
||||
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
|
||||
namespace nix::fetchers {
|
||||
|
||||
Settings::Settings(const nix::Settings & storeSettings)
|
||||
: storeSettings(storeSettings)
|
||||
{
|
||||
}
|
||||
Settings::Settings() {}
|
||||
|
||||
} // namespace nix::fetchers
|
||||
@@ -47,6 +47,12 @@ std::pair<StorePath, Hash> fetchToStore2(
|
||||
auto hash = Hash::parseSRI(fetchers::getStrAttr(*res, "hash"));
|
||||
auto storePath =
|
||||
store.makeFixedOutputPathFromCA(name, ContentAddressWithReferences::fromParts(method, hash, {}));
|
||||
|
||||
/* Add a temproot before the call to isValidPath to prevent accidental GC in case the
|
||||
input is cached. Note that this must be done before to avoid races. */
|
||||
if (mode != FetchMode::DryRun)
|
||||
store.addTempRoot(storePath);
|
||||
|
||||
if (mode == FetchMode::DryRun || store.isValidPath(storePath)) {
|
||||
debug(
|
||||
"source path '%s' cache hit in '%s' (hash '%s')",
|
||||
@@ -76,8 +82,8 @@ std::pair<StorePath, Hash> fetchToStore2(
|
||||
auto [storePath, hash] =
|
||||
mode == FetchMode::DryRun
|
||||
? [&]() {
|
||||
auto [storePath, hash] = store.computeStorePath(
|
||||
store.config.settings, name, path, method, HashAlgorithm::SHA256, {}, filter2);
|
||||
auto [storePath, hash] =
|
||||
store.computeStorePath(name, path, method, HashAlgorithm::SHA256, {}, filter2);
|
||||
debug(
|
||||
"hashed '%s' to '%s' (hash '%s')",
|
||||
path,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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");
|
||||
@@ -268,10 +273,10 @@ void Fetch::fetch(
|
||||
return;
|
||||
}
|
||||
|
||||
std::filesystem::path cacheDir = getCacheDir() / "git-lfs";
|
||||
auto cacheDir = getCacheDir() / "git-lfs";
|
||||
std::string key = hashString(HashAlgorithm::SHA256, pointerFilePath.rel()).to_string(HashFormat::Base16, false)
|
||||
+ "/" + pointer->oid;
|
||||
std::filesystem::path cachePath = cacheDir / key;
|
||||
auto cachePath = cacheDir / key;
|
||||
if (pathExists(cachePath)) {
|
||||
debug("using cache entry %s -> %s", key, PathFmt(cachePath));
|
||||
sink(readFile(cachePath));
|
||||
|
||||
@@ -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"
|
||||
@@ -74,6 +75,29 @@ namespace nix {
|
||||
|
||||
struct GitSourceAccessor;
|
||||
|
||||
struct GitError final : public CloneableError<GitError, Error>
|
||||
{
|
||||
template<typename... Ts>
|
||||
GitError(const git_error & error, Ts &&... args)
|
||||
: CloneableError("")
|
||||
{
|
||||
auto hf = HintFmt(std::forward<Ts>(args)...);
|
||||
err.msg = HintFmt("%1%: %2% (libgit2 error code = %3%)", Uncolored(hf.str()), error.message, error.klass);
|
||||
}
|
||||
|
||||
template<typename... Ts>
|
||||
GitError(Ts &&... args)
|
||||
: GitError(
|
||||
[]() -> const git_error & {
|
||||
const git_error * p = git_error_last();
|
||||
assert(p && "git_error_last() is unexpectedly null");
|
||||
return *p;
|
||||
}(),
|
||||
std::forward<Ts>(args)...)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::unique_ptr<git_repository, Deleter<git_repository_free>> Repository;
|
||||
typedef std::unique_ptr<git_tree_entry, Deleter<git_tree_entry_free>> TreeEntry;
|
||||
typedef std::unique_ptr<git_tree, Deleter<git_tree_free>> Tree;
|
||||
@@ -106,7 +130,7 @@ static void initLibGit2()
|
||||
static std::once_flag initialized;
|
||||
std::call_once(initialized, []() {
|
||||
if (git_libgit2_init() < 0)
|
||||
throw Error("initialising libgit2: %s", git_error_last()->message);
|
||||
throw GitError("initialising libgit2");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -114,7 +138,7 @@ static git_oid hashToOID(const Hash & hash)
|
||||
{
|
||||
git_oid oid;
|
||||
if (git_oid_fromstr(&oid, hash.gitRev().c_str()))
|
||||
throw Error("cannot convert '%s' to a Git OID", hash.gitRev());
|
||||
throw GitError("cannot convert '%s' to a Git OID", hash.gitRev());
|
||||
return oid;
|
||||
}
|
||||
|
||||
@@ -122,8 +146,7 @@ static Object lookupObject(git_repository * repo, const git_oid & oid, git_objec
|
||||
{
|
||||
Object obj;
|
||||
if (git_object_lookup(Setter(obj), repo, &oid, type)) {
|
||||
auto err = git_error_last();
|
||||
throw Error("getting Git object '%s': %s", oid, err->message);
|
||||
throw GitError("getting Git object '%s'", oid);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
@@ -133,8 +156,7 @@ static T peelObject(git_object * obj, git_object_t type)
|
||||
{
|
||||
T obj2;
|
||||
if (git_object_peel((git_object **) (typename T::pointer *) Setter(obj2), obj, type)) {
|
||||
auto err = git_error_last();
|
||||
throw Error("peeling Git object '%s': %s", *git_object_id(obj), err->message);
|
||||
throw Error("peeling Git object '%s'", *git_object_id(obj));
|
||||
}
|
||||
return obj2;
|
||||
}
|
||||
@@ -144,7 +166,7 @@ static T dupObject(typename T::pointer obj)
|
||||
{
|
||||
T obj2;
|
||||
if (git_object_dup((git_object **) (typename T::pointer *) Setter(obj2), (git_object *) obj))
|
||||
throw Error("duplicating object '%s': %s", *git_object_id((git_object *) obj), git_error_last()->message);
|
||||
throw GitError("duplicating object '%s'", *git_object_id((git_object *) obj));
|
||||
return obj2;
|
||||
}
|
||||
|
||||
@@ -216,7 +238,7 @@ static void initRepoAtomically(std::filesystem::path & path, GitRepo::Options op
|
||||
Repository tmpRepo;
|
||||
|
||||
if (git_repository_init(Setter(tmpRepo), tmpDir.string().c_str(), options.bare))
|
||||
throw Error("creating Git repository %s: %s", PathFmt(path), git_error_last()->message);
|
||||
throw GitError("creating Git repository %s", PathFmt(path));
|
||||
try {
|
||||
std::filesystem::rename(tmpDir, path);
|
||||
} catch (std::filesystem::filesystem_error & e) {
|
||||
@@ -226,7 +248,8 @@ static void initRepoAtomically(std::filesystem::path & path, GitRepo::Options op
|
||||
|| e.code() == std::errc::directory_not_empty) {
|
||||
return;
|
||||
} else
|
||||
throw SysError("moving temporary git repository from %s to %s", PathFmt(tmpDir), PathFmt(path));
|
||||
throw SystemError(
|
||||
e.code(), "moving temporary git repository from %s to %s", PathFmt(tmpDir), PathFmt(path));
|
||||
}
|
||||
// we successfully moved the repository, so the temporary directory no longer exists.
|
||||
delTmpDir.cancel();
|
||||
@@ -266,7 +289,7 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
|
||||
|
||||
initRepoAtomically(path, options);
|
||||
if (git_repository_open(Setter(repo), path.string().c_str()))
|
||||
throw Error("opening Git repository %s: %s", PathFmt(path), git_error_last()->message);
|
||||
throw GitError("opening Git repository %s", PathFmt(path));
|
||||
|
||||
ObjectDb odb;
|
||||
if (options.packfilesOnly) {
|
||||
@@ -279,28 +302,28 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
|
||||
*/
|
||||
|
||||
if (git_odb_new(Setter(odb)))
|
||||
throw Error("creating Git object database: %s", git_error_last()->message);
|
||||
throw GitError("creating Git object database");
|
||||
|
||||
if (git_odb_backend_pack(&packBackend, (path / "objects").string().c_str()))
|
||||
throw Error("creating pack backend: %s", git_error_last()->message);
|
||||
throw GitError("creating pack backend");
|
||||
|
||||
if (git_odb_add_backend(odb.get(), packBackend, 1))
|
||||
throw Error("adding pack backend to Git object database: %s", git_error_last()->message);
|
||||
throw GitError("adding pack backend to Git object database");
|
||||
} else {
|
||||
if (git_repository_odb(Setter(odb), repo.get()))
|
||||
throw Error("getting Git object database: %s", git_error_last()->message);
|
||||
throw GitError("getting Git object database");
|
||||
}
|
||||
|
||||
// mempack_backend will be owned by the repository, so we are not expected to free it ourselves.
|
||||
if (git_mempack_new(&mempackBackend))
|
||||
throw Error("creating mempack backend: %s", git_error_last()->message);
|
||||
throw GitError("creating mempack backend");
|
||||
|
||||
if (git_odb_add_backend(odb.get(), mempackBackend, 999))
|
||||
throw Error("adding mempack backend to Git object database: %s", git_error_last()->message);
|
||||
throw GitError("adding mempack backend to Git object database");
|
||||
|
||||
if (options.packfilesOnly) {
|
||||
if (git_repository_set_odb(repo.get(), odb.get()))
|
||||
throw Error("setting Git object database: %s", git_error_last()->message);
|
||||
throw GitError("setting Git object database");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -340,7 +363,7 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
|
||||
Indexer indexer;
|
||||
git_indexer_progress stats;
|
||||
if (git_indexer_new(Setter(indexer), pack_dir_path.c_str(), 0, nullptr, nullptr))
|
||||
throw Error("creating git packfile indexer: %s", git_error_last()->message);
|
||||
throw GitError("creating git packfile indexer");
|
||||
|
||||
// TODO: provide index callback for checkInterrupt() termination
|
||||
// though this is about an order of magnitude faster than the packbuilder
|
||||
@@ -348,15 +371,15 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
|
||||
constexpr size_t chunkSize = 128 * 1024;
|
||||
for (size_t offset = 0; offset < buf.size; offset += chunkSize) {
|
||||
if (git_indexer_append(indexer.get(), buf.ptr + offset, std::min(chunkSize, buf.size - offset), &stats))
|
||||
throw Error("appending to git packfile index: %s", git_error_last()->message);
|
||||
throw GitError("appending to git packfile index");
|
||||
checkInterrupt();
|
||||
}
|
||||
|
||||
if (git_indexer_commit(indexer.get(), &stats))
|
||||
throw Error("committing git packfile index: %s", git_error_last()->message);
|
||||
throw GitError("committing git packfile index");
|
||||
|
||||
if (git_mempack_reset(mempackBackend))
|
||||
throw Error("resetting git mempack backend: %s", git_error_last()->message);
|
||||
throw GitError("resetting git mempack backend");
|
||||
|
||||
checkInterrupt();
|
||||
}
|
||||
@@ -449,7 +472,7 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
|
||||
void setRemote(const std::string & name, const std::string & url) override
|
||||
{
|
||||
if (git_remote_set_url(*this, name.c_str(), url.c_str()))
|
||||
throw Error("setting remote '%s' URL to '%s': %s", name, url, git_error_last()->message);
|
||||
throw GitError("setting remote '%s' URL to '%s'", name, url);
|
||||
}
|
||||
|
||||
Hash resolveRef(std::string ref) override
|
||||
@@ -462,7 +485,7 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
|
||||
// an object_id.
|
||||
std::string peeledRef = ref + "^{commit}";
|
||||
if (git_revparse_single(Setter(object), *this, peeledRef.c_str()))
|
||||
throw Error("resolving Git reference '%s': %s", ref, git_error_last()->message);
|
||||
throw GitError("resolving Git reference '%s'", ref);
|
||||
auto oid = git_object_id(object.get());
|
||||
return toHash(*oid);
|
||||
}
|
||||
@@ -471,11 +494,11 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
|
||||
{
|
||||
GitConfig config;
|
||||
if (git_config_open_ondisk(Setter(config), configFile.string().c_str()))
|
||||
throw Error("parsing .gitmodules file: %s", git_error_last()->message);
|
||||
throw GitError("parsing .gitmodules file");
|
||||
|
||||
ConfigIterator it;
|
||||
if (git_config_iterator_glob_new(Setter(it), config.get(), "^submodule\\..*\\.(path|url|branch)$"))
|
||||
throw Error("iterating over .gitmodules: %s", git_error_last()->message);
|
||||
throw GitError("iterating over .gitmodules");
|
||||
|
||||
StringMap entries;
|
||||
|
||||
@@ -484,7 +507,7 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
|
||||
if (auto err = git_config_next(&entry, it.get())) {
|
||||
if (err == GIT_ITEROVER)
|
||||
break;
|
||||
throw Error("iterating over .gitmodules: %s", git_error_last()->message);
|
||||
throw GitError("iterating over .gitmodules");
|
||||
}
|
||||
entries.emplace(entry->name + 10, entry->value);
|
||||
}
|
||||
@@ -521,7 +544,7 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
|
||||
git_oid headRev;
|
||||
if (auto err = git_reference_name_to_id(&headRev, *this, "HEAD")) {
|
||||
if (err != GIT_ENOTFOUND)
|
||||
throw Error("resolving HEAD: %s", git_error_last()->message);
|
||||
throw GitError("resolving HEAD");
|
||||
} else
|
||||
info.headRev = toHash(headRev);
|
||||
|
||||
@@ -544,7 +567,7 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
|
||||
options.flags |= GIT_STATUS_OPT_INCLUDE_UNMODIFIED;
|
||||
options.flags |= GIT_STATUS_OPT_EXCLUDE_SUBMODULES;
|
||||
if (git_status_foreach_ext(*this, &options, &statusCallbackTrampoline, &statusCallback))
|
||||
throw Error("getting working directory status: %s", git_error_last()->message);
|
||||
throw GitError("getting working directory status");
|
||||
|
||||
/* Get submodule info. */
|
||||
auto modulesFile = path / ".gitmodules";
|
||||
@@ -587,8 +610,7 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
|
||||
if (auto errCode = git_object_lookup(Setter(obj), *this, &oid, GIT_OBJECT_ANY)) {
|
||||
if (errCode == GIT_ENOTFOUND)
|
||||
return false;
|
||||
auto err = git_error_last();
|
||||
throw Error("getting Git object '%s': %s", oid, err->message);
|
||||
throw GitError("getting Git object '%s'", oid);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -616,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);
|
||||
@@ -661,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
|
||||
@@ -918,7 +952,7 @@ struct GitSourceAccessor : SourceAccessor
|
||||
|
||||
TreeEntry copy;
|
||||
if (git_tree_entry_dup(Setter(copy), entry))
|
||||
throw Error("dupping tree entry: %s", git_error_last()->message);
|
||||
throw GitError("dupping tree entry");
|
||||
|
||||
auto entryName = std::string_view(git_tree_entry_name(entry));
|
||||
|
||||
@@ -948,7 +982,7 @@ struct GitSourceAccessor : SourceAccessor
|
||||
|
||||
Tree tree;
|
||||
if (git_tree_entry_to_object((git_object **) (git_tree **) Setter(tree), *state.repo, entry))
|
||||
throw Error("looking up directory '%s': %s", showPath(path), git_error_last()->message);
|
||||
throw GitError("looking up directory '%s'", showPath(path));
|
||||
|
||||
return tree;
|
||||
}
|
||||
@@ -983,7 +1017,7 @@ struct GitSourceAccessor : SourceAccessor
|
||||
|
||||
Tree tree;
|
||||
if (git_tree_entry_to_object((git_object **) (git_tree **) Setter(tree), *state.repo, entry))
|
||||
throw Error("looking up directory '%s': %s", showPath(path), git_error_last()->message);
|
||||
throw GitError("looking up directory '%s'", showPath(path));
|
||||
|
||||
return tree;
|
||||
}
|
||||
@@ -1016,7 +1050,7 @@ struct GitSourceAccessor : SourceAccessor
|
||||
|
||||
Blob blob;
|
||||
if (git_tree_entry_to_object((git_object **) (git_blob **) Setter(blob), *state.repo, entry))
|
||||
throw Error("looking up file '%s': %s", showPath(path), git_error_last()->message);
|
||||
throw GitError("looking up file '%s'", showPath(path));
|
||||
|
||||
return blob;
|
||||
}
|
||||
@@ -1068,7 +1102,7 @@ struct GitExportIgnoreSourceAccessor : CachingFilteringSourceAccessor
|
||||
if (git_error_last()->klass == GIT_ENOTFOUND)
|
||||
return false;
|
||||
else
|
||||
throw Error("looking up '%s': %s", showPath(path), git_error_last()->message);
|
||||
throw GitError("looking up '%s'", showPath(path));
|
||||
} else {
|
||||
// Official git will silently reject export-ignore lines that have
|
||||
// values. We do the same.
|
||||
@@ -1224,17 +1258,17 @@ struct GitFileSystemObjectSinkImpl : GitFileSystemObjectSink
|
||||
repo.emplace(parent.repoPool.get());
|
||||
|
||||
if (git_blob_create_from_stream(Setter(stream), **repo, nullptr))
|
||||
throw Error("creating a blob stream object: %s", git_error_last()->message);
|
||||
throw GitError("creating a blob stream object");
|
||||
|
||||
if (stream->write(stream.get(), contents.data(), contents.size()))
|
||||
throw Error("writing a blob for tarball member '%s': %s", path, git_error_last()->message);
|
||||
throw GitError("writing a blob for tarball member '%s'", path);
|
||||
|
||||
parent.totalBufSize -= contents.size();
|
||||
contents.clear();
|
||||
}
|
||||
} else {
|
||||
if (stream->write(stream.get(), data.data(), data.size()))
|
||||
throw Error("writing a blob for tarball member '%s': %s", path, git_error_last()->message);
|
||||
throw GitError("writing a blob for tarball member '%s'", path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1256,7 +1290,7 @@ struct GitFileSystemObjectSinkImpl : GitFileSystemObjectSink
|
||||
acquires ownership and frees the stream. */
|
||||
git_oid oid;
|
||||
if (git_blob_create_from_stream_commit(&oid, crf->stream.release()))
|
||||
throw Error("creating a blob object for '%s': %s", path, git_error_last()->message);
|
||||
throw GitError("creating a blob object for '%s'", path);
|
||||
addNode(
|
||||
*_state.lock(),
|
||||
crf->path,
|
||||
@@ -1270,8 +1304,7 @@ struct GitFileSystemObjectSinkImpl : GitFileSystemObjectSink
|
||||
|
||||
git_oid oid;
|
||||
if (git_blob_create_from_buffer(&oid, *repo, crf->contents.data(), crf->contents.size()))
|
||||
throw Error(
|
||||
"creating a blob object for '%s' from in-memory buffer: %s", crf->path, git_error_last()->message);
|
||||
throw GitError("creating a blob object for '%s' from in-memory buffer", crf->path);
|
||||
|
||||
addNode(
|
||||
*_state.lock(),
|
||||
@@ -1295,8 +1328,7 @@ struct GitFileSystemObjectSinkImpl : GitFileSystemObjectSink
|
||||
|
||||
git_oid oid;
|
||||
if (git_blob_create_from_buffer(&oid, *repo, target.c_str(), target.size()))
|
||||
throw Error(
|
||||
"creating a blob object for tarball symlink member '%s': %s", path, git_error_last()->message);
|
||||
throw GitError("creating a blob object for tarball symlink member '%s'", path);
|
||||
|
||||
auto state(_state.lock());
|
||||
addNode(*state, path, Child{GIT_FILEMODE_LINK, oid});
|
||||
@@ -1357,19 +1389,19 @@ struct GitFileSystemObjectSinkImpl : GitFileSystemObjectSink
|
||||
// Write this directory.
|
||||
git_treebuilder * b;
|
||||
if (git_treebuilder_new(&b, *repo, nullptr))
|
||||
throw Error("creating a tree builder: %s", git_error_last()->message);
|
||||
throw GitError("creating a tree builder");
|
||||
TreeBuilder builder(b);
|
||||
|
||||
for (auto & [name, child] : node.children) {
|
||||
auto oid_p = std::get_if<git_oid>(&child.file);
|
||||
auto oid = oid_p ? *oid_p : std::get<Directory>(child.file).oid.value();
|
||||
if (git_treebuilder_insert(nullptr, builder.get(), name.c_str(), &oid, child.mode))
|
||||
throw Error("adding a file to a tree builder: %s", git_error_last()->message);
|
||||
throw GitError("adding a file to a tree builder");
|
||||
}
|
||||
|
||||
git_oid oid;
|
||||
if (git_treebuilder_write(&oid, builder.get()))
|
||||
throw Error("creating a tree object: %s", git_error_last()->message);
|
||||
throw GitError("creating a tree object");
|
||||
node.oid = oid;
|
||||
}(_state.lock()->root);
|
||||
|
||||
|
||||
+58
-37
@@ -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"
|
||||
@@ -44,8 +45,9 @@ static bool isCacheFileWithinTtl(const Settings & settings, time_t now, const Po
|
||||
|
||||
std::filesystem::path getCachePath(std::string_view key, bool shallow)
|
||||
{
|
||||
return getCacheDir() / "gitv3"
|
||||
/ (hashString(HashAlgorithm::SHA256, key).to_string(HashFormat::Nix32, false) + (shallow ? "-shallow" : ""));
|
||||
auto name =
|
||||
hashString(HashAlgorithm::SHA256, key).to_string(HashFormat::Nix32, false) + (shallow ? "-shallow" : "");
|
||||
return getCacheDir() / "gitv3" / std::move(name);
|
||||
}
|
||||
|
||||
// Returns the name of the HEAD branch.
|
||||
@@ -61,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)
|
||||
@@ -88,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
|
||||
@@ -438,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);
|
||||
}
|
||||
@@ -477,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
|
||||
@@ -499,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`
|
||||
@@ -514,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);
|
||||
}
|
||||
}
|
||||
@@ -626,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. "
|
||||
@@ -639,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. */
|
||||
|
||||
@@ -13,10 +13,9 @@
|
||||
|
||||
namespace nix {
|
||||
|
||||
class Settings;
|
||||
struct GitRepo;
|
||||
|
||||
} // namespace nix
|
||||
}
|
||||
|
||||
namespace nix::fetchers {
|
||||
|
||||
@@ -24,12 +23,7 @@ struct Cache;
|
||||
|
||||
struct Settings : public Config
|
||||
{
|
||||
/**
|
||||
* Reference to the "parent" store-layer settings.
|
||||
*/
|
||||
const nix::Settings & storeSettings;
|
||||
|
||||
Settings(const nix::Settings & storeSettings);
|
||||
Settings();
|
||||
|
||||
Setting<StringMap> accessTokens{
|
||||
this,
|
||||
|
||||
@@ -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
@@ -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");
|
||||
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "nix/store/globals.hh"
|
||||
#include "nix/fetchers/fetch-settings.hh"
|
||||
#include "nix/flake/flakeref.hh"
|
||||
#include "nix/fetchers/attrs.hh"
|
||||
@@ -20,8 +19,7 @@ TEST(parseFlakeRef, path)
|
||||
{
|
||||
experimentalFeatureSettings.experimentalFeatures.get().insert(Xp::Flakes);
|
||||
|
||||
Settings settings;
|
||||
fetchers::Settings fetchSettings{settings};
|
||||
fetchers::Settings fetchSettings;
|
||||
|
||||
{
|
||||
auto s = "/foo/bar";
|
||||
@@ -71,8 +69,7 @@ TEST(parseFlakeRef, GitArchiveInput)
|
||||
{
|
||||
experimentalFeatureSettings.experimentalFeatures.get().insert(Xp::Flakes);
|
||||
|
||||
Settings settings;
|
||||
fetchers::Settings fetchSettings{settings};
|
||||
fetchers::Settings fetchSettings;
|
||||
|
||||
{
|
||||
auto s = "github:foo/bar/branch%23"; // branch name with `#`
|
||||
@@ -115,8 +112,7 @@ class InputFromURLTest : public ::testing::WithParamInterface<InputFromURLTestCa
|
||||
TEST_P(InputFromURLTest, attrsAreCorrectAndRoundTrips)
|
||||
{
|
||||
experimentalFeatureSettings.experimentalFeatures.get().insert(Xp::Flakes);
|
||||
Settings settings;
|
||||
fetchers::Settings fetchSettings{settings};
|
||||
fetchers::Settings fetchSettings;
|
||||
|
||||
const auto & testCase = GetParam();
|
||||
|
||||
@@ -278,8 +274,7 @@ INSTANTIATE_TEST_SUITE_P(
|
||||
|
||||
TEST(to_string, doesntReencodeUrl)
|
||||
{
|
||||
Settings settings;
|
||||
fetchers::Settings fetchSettings{settings};
|
||||
fetchers::Settings fetchSettings;
|
||||
auto s = "http://localhost:8181/test/+3d.tar.gz";
|
||||
auto flakeref = parseFlakeRef(fetchSettings, s);
|
||||
auto unparsed = flakeref.to_string();
|
||||
@@ -288,4 +283,18 @@ TEST(to_string, doesntReencodeUrl)
|
||||
ASSERT_EQ(unparsed, expected);
|
||||
}
|
||||
|
||||
TEST(parseFlakeRef, malformedGithubUrlDoesNotCrash)
|
||||
{
|
||||
experimentalFeatureSettings.experimentalFeatures.get().insert(Xp::Flakes);
|
||||
|
||||
fetchers::Settings fetchSettings;
|
||||
|
||||
// Using ref= instead of rev= with a github: URL should produce an
|
||||
// error, not an assertion failure in renderAuthorityAndPath
|
||||
// (https://github.com/NixOS/nix/issues/15196).
|
||||
EXPECT_THROW(
|
||||
parseFlakeRef(fetchSettings, "github:nixos/nixpkgs/nixpkgs.git?ref=aead170c1a49253ebfa5027010dfd89a77b73ca4"),
|
||||
Error);
|
||||
}
|
||||
|
||||
} // namespace nix
|
||||
@@ -31,7 +31,7 @@ namespace nix::flake {
|
||||
// setting name -> setting value -> allow or ignore.
|
||||
typedef std::map<std::string, std::map<std::string, bool>> TrustedList;
|
||||
|
||||
std::filesystem::path trustedListPath()
|
||||
static std::filesystem::path trustedListPath()
|
||||
{
|
||||
return getDataDir() / "trusted-settings.json";
|
||||
}
|
||||
|
||||
@@ -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
@@ -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 = ParsedURL::Authority{},
|
||||
.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 &) {
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "nix/main/loggers.hh"
|
||||
#include "nix/util/util.hh"
|
||||
#include "nix/main/plugin.hh"
|
||||
#include "nix/main/shared.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
|
||||
@@ -13,13 +13,6 @@
|
||||
|
||||
namespace nix {
|
||||
|
||||
class Settings;
|
||||
|
||||
// FIXME: don't use a global variable.
|
||||
extern Settings settings;
|
||||
|
||||
int handleExceptions(const std::string & programName, std::function<void()> fun);
|
||||
|
||||
/**
|
||||
* Don't forget to call initPlugins() after settings are initialized!
|
||||
* @param loadConfig Whether to load configuration from `nix.conf`, `NIX_CONFIG`, etc. May be disabled for unit tests.
|
||||
|
||||
@@ -31,17 +31,12 @@
|
||||
|
||||
#include "nix/util/exit.hh"
|
||||
#include "nix/util/strings.hh"
|
||||
#include "nix/util/config-global.hh"
|
||||
|
||||
#include "main-config-private.hh"
|
||||
#include "nix/expr/config.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
Settings settings;
|
||||
|
||||
static GlobalConfig::Register rSettings(&settings);
|
||||
|
||||
char ** savedArgv;
|
||||
|
||||
static bool gcWarning = true;
|
||||
@@ -340,8 +335,8 @@ void printVersion(const std::string & programName)
|
||||
std::cout << "System configuration file: " << nixConfFile() << "\n";
|
||||
std::cout << "User configuration files: "
|
||||
<< os_string_to_string(ExecutablePath{.directories = nixUserConfFiles()}.render()) << "\n";
|
||||
std::cout << "Store directory: "
|
||||
<< resolveStoreConfig(settings, StoreReference{settings.storeUri.get()})->storeDir << "\n";
|
||||
std::cout << "Store directory: " << resolveStoreConfig(StoreReference{settings.storeUri.get()})->storeDir
|
||||
<< "\n";
|
||||
std::cout << "State directory: " << settings.nixStateDir << "\n";
|
||||
}
|
||||
throw Exit();
|
||||
|
||||
@@ -73,7 +73,7 @@ std::function<void(siginfo_t * info, void * ctx)> stackOverflowHandler(defaultSt
|
||||
void defaultStackOverflowHandler(siginfo_t * info, void * ctx)
|
||||
{
|
||||
char msg[] = "error: stack overflow (possible infinite recursion)\n";
|
||||
[[gnu::unused]] auto res = write(2, msg, strlen(msg));
|
||||
[[gnu::unused]] auto res = ::write(2, msg, strlen(msg));
|
||||
_exit(1); // maybe abort instead?
|
||||
}
|
||||
|
||||
|
||||
@@ -18,9 +18,6 @@
|
||||
|
||||
extern "C" {
|
||||
|
||||
// FIXME: This is going to conflict with the one in libmain.
|
||||
nix::Settings cStoreSettings;
|
||||
|
||||
nix_err nix_libstore_init(nix_c_context * context)
|
||||
{
|
||||
if (context)
|
||||
@@ -49,7 +46,7 @@ Store * nix_store_open(nix_c_context * context, const char * uri, const char ***
|
||||
std::string uri_str = uri ? uri : "";
|
||||
|
||||
if (uri_str.empty())
|
||||
return new Store{nix::openStore(cStoreSettings)};
|
||||
return new Store{nix::openStore()};
|
||||
|
||||
auto storeRef = nix::StoreReference::parse(uri_str);
|
||||
|
||||
@@ -58,7 +55,7 @@ Store * nix_store_open(nix_c_context * context, const char * uri, const char ***
|
||||
storeRef.params[params[i][0]] = params[i][1];
|
||||
}
|
||||
}
|
||||
return new Store{nix::openStore(cStoreSettings, std::move(storeRef))};
|
||||
return new Store{nix::openStore(std::move(storeRef))};
|
||||
}
|
||||
NIXC_CATCH_ERRS_NULL
|
||||
}
|
||||
@@ -119,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
|
||||
@@ -315,8 +312,8 @@ StorePath * nix_add_derivation(nix_c_context * context, Store * store, nix_deriv
|
||||
without actually writing the derivation if this setting is
|
||||
set, but it was that way already, so we are doing this for
|
||||
back-compat for now. */
|
||||
auto ret = cStoreSettings.readOnlyMode ? nix::computeStorePath(*store->ptr, derivation->drv)
|
||||
: store->ptr->writeDerivation(derivation->drv, nix::NoRepair);
|
||||
auto ret = nix::settings.readOnlyMode ? nix::computeStorePath(*store->ptr, derivation->drv)
|
||||
: store->ptr->writeDerivation(derivation->drv, nix::NoRepair);
|
||||
|
||||
return new StorePath{ret};
|
||||
}
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
|
||||
extern "C" {
|
||||
|
||||
extern nix::Settings cStoreSettings;
|
||||
|
||||
struct Store
|
||||
{
|
||||
nix::ref<nix::Store> ptr;
|
||||
|
||||
Loaded 100 of 376 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user