Compare commits
339
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 | ||
|
|
7c915b371d | ||
|
|
36d0e9580f | ||
|
|
c9abefbc30 | ||
|
|
6cbf80a0b0 | ||
|
|
d3d63a4b5b | ||
|
|
6a5ee08737 | ||
|
|
ac2dd58b6f | ||
|
|
8fadcceb6d | ||
|
|
4f91e9599f | ||
|
|
2913722781 | ||
|
|
12f97382af | ||
|
|
fdfc772114 | ||
|
|
a4b1814d67 | ||
|
|
702ebdb11b | ||
|
|
7106de16e6 | ||
|
|
b818594ba2 | ||
|
|
9ae12ede4c | ||
|
|
20f7f33123 | ||
|
|
002cbefa9f | ||
|
|
dc636dde10 | ||
|
|
a06ab4871c | ||
|
|
ed22ef2b89 | ||
|
|
7926a629e2 | ||
|
|
a8f305add3 | ||
|
|
cecbe9f73a | ||
|
|
9ac91e36a9 | ||
|
|
759f6c856b | ||
|
|
736abd50ff | ||
|
|
a3d51172e9 | ||
|
|
eae7e0151c | ||
|
|
d3388d3d81 | ||
|
|
7352205ce9 | ||
|
|
f3f9eac8fc | ||
|
|
df21c81191 | ||
|
|
52b1906995 | ||
|
|
c756d02948 | ||
|
|
403e30f136 | ||
|
|
3a60a04bf8 | ||
|
|
c9526e289a | ||
|
|
d4a0024184 | ||
|
|
d9651b1f82 | ||
|
|
912c6c283d | ||
|
|
04fd722b1b | ||
|
|
1a57df3473 | ||
|
|
04d13a96e3 | ||
|
|
46eabe34c2 | ||
|
|
ecdcdd82e0 | ||
|
|
a4c421da22 | ||
|
|
ae4e4d9afd | ||
|
|
fbd837c911 | ||
|
|
857fd2a3a4 | ||
|
|
3c1ad7d978 | ||
|
|
8020a847ab | ||
|
|
db8499e62f | ||
|
|
1add77677f | ||
|
|
d5eda907ef | ||
|
|
f9300514cd | ||
|
|
036a47be83 | ||
|
|
c4e408459a | ||
|
|
f0498b94d8 | ||
|
|
34688ecf5f | ||
|
|
92d0fe000b | ||
|
|
75af0351ac | ||
|
|
c79ff97c07 | ||
|
|
ef659136ca | ||
|
|
582e4fa0f6 | ||
|
|
6674c23416 | ||
|
|
b06d0f764f | ||
|
|
845d951682 | ||
|
|
a900bf1548 | ||
|
|
36ad2962ca | ||
|
|
e4ce788f9d | ||
|
|
3cd840d7f1 | ||
|
|
6b90755cad | ||
|
|
30e213c948 | ||
|
|
3b473c4be5 | ||
|
|
23ddb0bfc7 | ||
|
|
e29bb23cf9 | ||
|
|
08da3311b3 | ||
|
|
ba3dc07bf1 | ||
|
|
e5278ac66b | ||
|
|
2f49b730cf | ||
|
|
ca8e6cae91 | ||
|
|
bcc63908ba | ||
|
|
7eb23c15f3 | ||
|
|
103f912c40 | ||
|
|
34cbfffa11 | ||
|
|
499ffaf940 | ||
|
|
72ab64b612 | ||
|
|
2989a23fca | ||
|
|
bbb4b009ec | ||
|
|
91c706852b | ||
|
|
80b944a3f6 | ||
|
|
cccc9440d7 | ||
|
|
c21820db07 | ||
|
|
4496a7eead | ||
|
|
d1ad4b183a | ||
|
|
766316223c | ||
|
|
de6b5f60cd | ||
|
|
afd40adc90 | ||
|
|
dcc71da7e8 | ||
|
|
ecda8c2329 | ||
|
|
0da728b1f5 | ||
|
|
ea53914e47 | ||
|
|
d77c131df3 | ||
|
|
72c2954625 | ||
|
|
27d5cc39c8 | ||
|
|
25ab7f5850 | ||
|
|
139d05af6f | ||
|
|
b489c8ea15 | ||
|
|
a4c0295822 | ||
|
|
8336e71c19 | ||
|
|
037a19441a | ||
|
|
124605dffc | ||
|
|
936f6c6c7d | ||
|
|
b038500b47 | ||
|
|
a357d77492 | ||
|
|
47f261cc19 | ||
|
|
27435e0036 | ||
|
|
0e2fc2a2f1 | ||
|
|
6d6cbf78cc | ||
|
|
39a9a004e2 | ||
|
|
5f9483519a | ||
|
|
b9c77ecafc | ||
|
|
d5ce1a79ec | ||
|
|
663d27c9df | ||
|
|
4da0b36f83 | ||
|
|
a2de09c9fa | ||
|
|
2ba65f1f26 | ||
|
|
77b6b01b72 | ||
|
|
5e7195e1a4 | ||
|
|
78e8896d22 | ||
|
|
d84624d23d | ||
|
|
9e8cf9055a | ||
|
|
22372d7889 | ||
|
|
d09f03d742 | ||
|
|
b026649c62 | ||
|
|
d69ca7bf35 | ||
|
|
ee6cb7890a | ||
|
|
351b8dd768 | ||
|
|
1713f4c976 | ||
|
|
de88141cdf | ||
|
|
da9426b8fc | ||
|
|
bcbc8ae4e3 | ||
|
|
538e82aa0b | ||
|
|
711e6b3476 | ||
|
|
0fc20e3e20 | ||
|
|
5ee5e6e8a0 | ||
|
|
0f2754a682 | ||
|
|
97f71909d7 | ||
|
|
d5e4b0b4b8 | ||
|
|
00d0e6dff3 | ||
|
|
f326f02813 | ||
|
|
9e9b6d44f8 | ||
|
|
11f6f07598 | ||
|
|
ac9682c52f | ||
|
|
c7f1036bcb | ||
|
|
d1348a2477 | ||
|
|
c0ab135860 | ||
|
|
e5536c8935 | ||
|
|
929022c8f8 | ||
|
|
bad1a005ed | ||
|
|
692102f0dc | ||
|
|
68cf0a7f8a | ||
|
|
5dfd81cbc0 | ||
|
|
395eef30f1 | ||
|
|
c7098ec8da | ||
|
|
e8d1cb0668 | ||
|
|
a7c043b95d | ||
|
|
ffe97db4f9 | ||
|
|
252e4ee5ca | ||
|
|
623360d07f | ||
|
|
7f95112fac | ||
|
|
a13de50df3 | ||
|
|
0e3a620374 | ||
|
|
00f67ee5d5 | ||
|
|
d69001600b | ||
|
|
c1ab73f921 | ||
|
|
3cb27988fb | ||
|
|
f43566f4d7 | ||
|
|
fb6274b312 | ||
|
|
e72a8bebb8 | ||
|
|
dad793fcfd | ||
|
|
7985873f73 | ||
|
|
db576d599c | ||
|
|
d5544919e4 | ||
|
|
8928cb4fb8 | ||
|
|
0dd38bc8b6 | ||
|
|
d45004f5ec | ||
|
|
50050b5ef1 | ||
|
|
d0c194efc1 | ||
|
|
bfdd124837 | ||
|
|
1100c9dc23 | ||
|
|
cd6eb7e473 |
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,13 +39,24 @@ 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@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
|
||||
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
- name: Login to GitHub Container Registry
|
||||
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
|
||||
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
# Default meson build dir
|
||||
/build
|
||||
# Meson creates this file too
|
||||
src/.wraplock
|
||||
|
||||
# /tests/functional/
|
||||
/tests/functional/common/subst-vars.sh
|
||||
|
||||
@@ -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,29 @@
|
||||
---
|
||||
synopsis: "Rust nix-installer in beta"
|
||||
prs: []
|
||||
---
|
||||
|
||||
The Rust-based rewrite of the Nix installer is now in beta.
|
||||
We'd love help testing it out!
|
||||
|
||||
To test out the new installer, run:
|
||||
```
|
||||
curl -sSfL https://artifacts.nixos.org/nix-installer | sh -s -- install
|
||||
```
|
||||
|
||||
This installer can be run even when you have an existing, script-based Nix installation without any adjustments.
|
||||
|
||||
This new installer also comes with the ability to uninstall your Nix installation; run:
|
||||
```
|
||||
/nix/nix-installer uninstall
|
||||
```
|
||||
|
||||
This will get rid of your entire Nix installation (even if you installed over an existing, script-based installation).
|
||||
|
||||
This installer is a modified version of the [Determinate Nix Installer](https://github.com/DeterminateSystems/nix-installer) by Determinate Systems.
|
||||
Thanks to Determinate Systems for all the investment they've put into the installer.
|
||||
|
||||
Source for the installer is in https://github.com/NixOS/nix-installer.
|
||||
Report any issues in that repo.
|
||||
|
||||
For CI usage, a GitHub Action to install Nix using this installer is available at https://github.com/NixOS/nix-installer-action.
|
||||
@@ -6,3 +6,4 @@ prs: [14766]
|
||||
The C API now includes additional methods:
|
||||
|
||||
- `nix_store_query_path_from_hash_part()` - Get the full store path given its hash part
|
||||
- `nix_store_copy_path()` - Copy a single store path between two stores, allows repairs and configuring signature checking
|
||||
@@ -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).
|
||||
@@ -0,0 +1,32 @@
|
||||
---
|
||||
synopsis: S3 binary caches now use virtual-hosted-style addressing by default
|
||||
issues: [15208]
|
||||
---
|
||||
|
||||
S3 binary caches now use virtual-hosted-style URLs
|
||||
(`https://bucket.s3.region.amazonaws.com/key`) instead of path-style URLs
|
||||
(`https://s3.region.amazonaws.com/bucket/key`) when connecting to standard AWS
|
||||
S3 endpoints. This enables HTTP/2 multiplexing and fixes TCP connection
|
||||
exhaustion (TIME_WAIT socket accumulation) under high-concurrency workloads.
|
||||
|
||||
A new `addressing-style` store option controls this behavior:
|
||||
|
||||
- `auto` (default): virtual-hosted-style for standard AWS endpoints, path-style
|
||||
for custom endpoints.
|
||||
- `path`: forces path-style addressing (deprecated by AWS).
|
||||
- `virtual`: forces virtual-hosted-style addressing (bucket names must not
|
||||
contain dots).
|
||||
|
||||
Bucket names containing dots (e.g., `my.bucket.name`) automatically fall back
|
||||
to path-style addressing in `auto` mode, because dotted names create
|
||||
multi-level subdomains that break TLS wildcard certificate validation.
|
||||
|
||||
Example using path-style for backwards compatibility:
|
||||
|
||||
```
|
||||
s3://my-bucket/key?region=us-east-1&addressing-style=path
|
||||
```
|
||||
|
||||
Additionally, TCP keep-alive is now enabled on all HTTP connections, preventing
|
||||
idle connections from being silently dropped by intermediate network devices
|
||||
(NATs, firewalls, load balancers).
|
||||
@@ -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
+5
-5
@@ -63,15 +63,15 @@
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1763948260,
|
||||
"narHash": "sha256-zZk7fn2ARAqmLwaYTpxBJmj81KIdz11NiWt7ydHHD/M=",
|
||||
"rev": "1c8ba8d3f7634acac4a2094eef7c32ad9106532c",
|
||||
"lastModified": 1771903837,
|
||||
"narHash": "sha256-jEA8WggGKtMFeNeCKq3NK8cLEjJmG6/RLUElYYbBZ0E=",
|
||||
"rev": "e764fc9a405871f1f6ca3d1394fb422e0a0c3951",
|
||||
"type": "tarball",
|
||||
"url": "https://releases.nixos.org/nixos/25.05/nixos-25.05.813095.1c8ba8d3f763/nixexprs.tar.xz"
|
||||
"url": "https://releases.nixos.org/nixos/25.11/nixos-25.11.6495.e764fc9a4058/nixexprs.tar.xz"
|
||||
},
|
||||
"original": {
|
||||
"type": "tarball",
|
||||
"url": "https://channels.nixos.org/nixos-25.05/nixexprs.tar.xz"
|
||||
"url": "https://channels.nixos.org/nixos-25.11/nixexprs.tar.xz"
|
||||
}
|
||||
},
|
||||
"nixpkgs-23-11": {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
description = "The purely functional package manager";
|
||||
|
||||
inputs.nixpkgs.url = "https://channels.nixos.org/nixos-25.05/nixexprs.tar.xz";
|
||||
inputs.nixpkgs.url = "https://channels.nixos.org/nixos-25.11/nixexprs.tar.xz";
|
||||
|
||||
inputs.nixpkgs-regression.url = "github:NixOS/nixpkgs/215d4d0fd80ca5163643b03a33fde804a29cc1e2";
|
||||
inputs.nixpkgs-23-11.url = "github:NixOS/nixpkgs/a62e6edd6d5e1fa0329b8653c801147986f8d446";
|
||||
@@ -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,6 +409,10 @@
|
||||
|
||||
"nix-cmd" = { };
|
||||
|
||||
"nix-nswrapper" = {
|
||||
linuxOnly = true;
|
||||
};
|
||||
|
||||
"nix-cli" = { };
|
||||
|
||||
"nix-everything" = { };
|
||||
@@ -426,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 =
|
||||
|
||||
@@ -88,16 +88,28 @@
|
||||
''^tests/functional/lang/eval-fail-path-slash\.nix$''
|
||||
''^tests/functional/lang/eval-fail-toJSON-non-utf-8\.nix$''
|
||||
''^tests/functional/lang/eval-fail-set\.nix$''
|
||||
|
||||
# Language tests, don't churn the formatting of strings
|
||||
''^tests/functional/lang/eval-fail-fromTOML-overflow\.nix$''
|
||||
''^tests/functional/lang/eval-fail-fromTOML-underflow\.nix$''
|
||||
''^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 = {
|
||||
enable = true;
|
||||
# https://github.com/cachix/git-hooks.nix/pull/532
|
||||
package = pkgs.llvmPackages_latest.clang-tools;
|
||||
package = pkgs.llvmPackages_21.clang-tools;
|
||||
excludes = [
|
||||
# We don't want to format test data
|
||||
# ''tests/(?!nixos/).*\.nix''
|
||||
''^src/[^/]*-tests/data/.*$''
|
||||
"^src/[^/]*-tests/data/.*$"
|
||||
|
||||
# Don't format vendored code
|
||||
''^doc/manual/redirects\.js$''
|
||||
|
||||
@@ -24,6 +24,10 @@ subproject('libcmd')
|
||||
# Executables
|
||||
subproject('nix')
|
||||
|
||||
if host_machine.system() == 'linux'
|
||||
subproject('nswrapper')
|
||||
endif
|
||||
|
||||
# Docs
|
||||
if get_option('doc-gen')
|
||||
subproject('internal-api-docs')
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Clang gets grumpy about missing libasan symbols if -shared-libasan is not
|
||||
# passed when building shared libs, at least on Linux
|
||||
if cxx.get_id() == 'clang' and ('address' in get_option('b_sanitize') or 'undefined' in get_option(
|
||||
'b_sanitize',
|
||||
'b_sanitize',
|
||||
))
|
||||
add_project_link_arguments('-shared-libasan', language : 'cpp')
|
||||
endif
|
||||
|
||||
@@ -22,6 +22,8 @@ add_project_arguments(
|
||||
'-Werror=undef',
|
||||
'-Werror=unused-result',
|
||||
'-Werror=sign-compare',
|
||||
'-Werror=return-type',
|
||||
'-Werror=non-virtual-dtor',
|
||||
'-Wignored-qualifiers',
|
||||
'-Wimplicit-fallthrough',
|
||||
'-Wno-deprecated-declarations',
|
||||
@@ -31,6 +33,13 @@ add_project_arguments(
|
||||
# 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.
|
||||
@@ -40,6 +49,11 @@ do_pch = cxx.get_id() == 'clang'
|
||||
# instantiations in libutil and libstore.
|
||||
if cxx.get_id() == 'clang'
|
||||
add_project_arguments('-fpch-instantiate-templates', language : 'cpp')
|
||||
# Catch brace elision bugs: when WorkerProto::Version changed from `unsigned int`
|
||||
# to `struct { unsigned int major; uint8_t minor; }`, `.version = 16` silently
|
||||
# became `.version = {16, 0}` instead of failing, breaking protocol compatibility
|
||||
# in a subtle way
|
||||
add_project_arguments('-Werror=c99-designator', language : 'cpp')
|
||||
endif
|
||||
|
||||
# Detect if we're using libstdc++ (GCC's standard library)
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
{
|
||||
runCommand,
|
||||
system,
|
||||
stdenv,
|
||||
buildPackages,
|
||||
cacert,
|
||||
nix,
|
||||
nixComponents2,
|
||||
}:
|
||||
|
||||
let
|
||||
|
||||
inherit (stdenv.hostPlatform) system;
|
||||
|
||||
installerClosureInfo = buildPackages.closureInfo {
|
||||
rootPaths = [
|
||||
nix
|
||||
nixComponents2.nix-manual.man
|
||||
cacert
|
||||
];
|
||||
};
|
||||
@@ -42,6 +46,7 @@ runCommand "nix-binary-tarball-${version}" env ''
|
||||
--subst-var-by cacert ${cacert}
|
||||
substitute ${../scripts/install-multi-user.sh} $TMPDIR/install-multi-user \
|
||||
--subst-var-by nix ${nix} \
|
||||
--subst-var-by nix-manual ${nixComponents2.nix-manual.man} \
|
||||
--subst-var-by cacert ${cacert}
|
||||
|
||||
if type -p shellcheck; then
|
||||
|
||||
@@ -155,12 +155,14 @@ let
|
||||
];
|
||||
};
|
||||
|
||||
mesonBuildLayer = finalAttrs: prevAttrs: {
|
||||
mesonBuildLayer = finalAttrs: prevAttrs: rec {
|
||||
nativeBuildInputs = prevAttrs.nativeBuildInputs or [ ] ++ [
|
||||
pkg-config
|
||||
];
|
||||
separateDebugInfo = !stdenv.hostPlatform.isStatic;
|
||||
hardeningDisable = lib.optional stdenv.hostPlatform.isStatic "pie";
|
||||
# needed by separateDebugInfo
|
||||
# SEE: https://github.com/NixOS/nixpkgs/pull/394674/commits/a4d355342976e9e9823fb94f133bc43ebec9da5b
|
||||
__structuredAttrs = separateDebugInfo;
|
||||
};
|
||||
|
||||
mesonLibraryLayer = finalAttrs: prevAttrs: {
|
||||
@@ -416,6 +418,8 @@ in
|
||||
|
||||
nix-cmd = callPackage ../src/libcmd/package.nix { };
|
||||
|
||||
nix-nswrapper = callPackage ../src/nswrapper/package.nix { };
|
||||
|
||||
/**
|
||||
The Nix command line interface. Note that this does not include its tests, whereas `nix-everything` does.
|
||||
*/
|
||||
|
||||
+16
-26
@@ -30,34 +30,24 @@ scope: {
|
||||
NIX_CFLAGS_COMPILE = "-DINITIAL_MARK_STACK_SIZE=1048576";
|
||||
});
|
||||
|
||||
lowdown = pkgs.lowdown.overrideAttrs (prevAttrs: rec {
|
||||
version = "2.0.2";
|
||||
src = pkgs.fetchurl {
|
||||
url = "https://kristaps.bsd.lv/lowdown/snapshots/lowdown-${version}.tar.gz";
|
||||
hash = "sha512-cfzhuF4EnGmLJf5EGSIbWqJItY3npbRSALm+GarZ7SMU7Hr1xw0gtBFMpOdi5PBar4TgtvbnG4oRPh+COINGlA==";
|
||||
};
|
||||
nativeBuildInputs = prevAttrs.nativeBuildInputs ++ [ pkgs.buildPackages.bmake ];
|
||||
postInstall =
|
||||
lib.replaceStrings [ "lowdown.so.1" "lowdown.1.dylib" ] [ "lowdown.so.2" "lowdown.2.dylib" ]
|
||||
(prevAttrs.postInstall or "");
|
||||
patches = [ ];
|
||||
});
|
||||
|
||||
# TODO: Remove this when https://github.com/NixOS/nixpkgs/pull/442682 is included in a stable release
|
||||
toml11 =
|
||||
if lib.versionAtLeast pkgs.toml11.version "4.4.0" then
|
||||
pkgs.toml11
|
||||
else
|
||||
pkgs.toml11.overrideAttrs rec {
|
||||
version = "4.4.0";
|
||||
src = pkgs.fetchFromGitHub {
|
||||
owner = "ToruNiina";
|
||||
repo = "toml11";
|
||||
tag = "v${version}";
|
||||
hash = "sha256-sgWKYxNT22nw376ttGsTdg0AMzOwp8QH3E8mx0BZJTQ=";
|
||||
};
|
||||
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);
|
||||
};
|
||||
|
||||
# TODO Hack until https://github.com/NixOS/nixpkgs/issues/45462 is fixed.
|
||||
boost =
|
||||
(pkgs.boost.override {
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
|
||||
nix-cmd,
|
||||
|
||||
nix-nswrapper,
|
||||
|
||||
nix-cli,
|
||||
|
||||
nix-functional-tests,
|
||||
@@ -171,6 +173,9 @@ stdenv.mkDerivation (finalAttrs: {
|
||||
# Forwarded outputs
|
||||
ln -sT ${nix-manual} $doc
|
||||
ln -sT ${nix-manual.man} $man
|
||||
''
|
||||
+ lib.optionalString stdenv.isLinux ''
|
||||
lndir ${nix-nswrapper} $out
|
||||
'';
|
||||
|
||||
passthru = {
|
||||
|
||||
+24
-3
@@ -57,6 +57,7 @@ let
|
||||
"nix-flake"
|
||||
"nix-flake-c"
|
||||
"nix-flake-tests"
|
||||
"nix-nswrapper"
|
||||
"nix-main"
|
||||
"nix-main-c"
|
||||
"nix-cmd"
|
||||
@@ -114,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 (
|
||||
@@ -134,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
|
||||
)
|
||||
@@ -170,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);
|
||||
|
||||
@@ -190,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);
|
||||
|
||||
@@ -52,6 +52,7 @@ readonly PROFILE_FISH_PREFIXES=(
|
||||
readonly PROFILE_NIX_FILE_FISH="$NIX_ROOT/var/nix/profiles/default/etc/profile.d/nix-daemon.fish"
|
||||
|
||||
readonly NIX_INSTALLED_NIX="@nix@"
|
||||
readonly NIX_INSTALLED_NIX_MAN="@nix-manual@"
|
||||
readonly NIX_INSTALLED_CACERT="@cacert@"
|
||||
#readonly NIX_INSTALLED_NIX="/nix/store/byi37zv50wnfrpp4d81z3spswd5zva37-nix-2.3.6"
|
||||
#readonly NIX_INSTALLED_CACERT="/nix/store/7pi45g541xa8ahwgpbpy7ggsl0xj1jj6-nss-cacert-3.49.2"
|
||||
@@ -969,6 +970,8 @@ setup_default_profile() {
|
||||
task "Setting up the default profile"
|
||||
_sudo "to install a bootstrapping Nix in to the default profile" \
|
||||
HOME="$ROOT_HOME" "$NIX_INSTALLED_NIX/bin/nix-env" -i "$NIX_INSTALLED_NIX"
|
||||
_sudo "to install Nix man pages in to the default profile" \
|
||||
HOME="$ROOT_HOME" "$NIX_INSTALLED_NIX/bin/nix-env" -i "$NIX_INSTALLED_NIX_MAN"
|
||||
|
||||
if [ -z "${NIX_SSL_CERT_FILE:-}" ] || ! [ -f "${NIX_SSL_CERT_FILE:-}" ] || cert_in_store; then
|
||||
_sudo "to install a bootstrapping SSL certificate just for Nix in to the default profile" \
|
||||
|
||||
@@ -38,6 +38,7 @@ escape_systemd_env() {
|
||||
create_systemd_proxy_env() {
|
||||
vars="http_proxy https_proxy ftp_proxy all_proxy no_proxy HTTP_PROXY HTTPS_PROXY FTP_PROXY ALL_PROXY NO_PROXY"
|
||||
for v in $vars; do
|
||||
# shellcheck disable=SC2268
|
||||
if [ "x${!v:-}" != "x" ]; then
|
||||
echo "Environment=${v}=$(escape_systemd_env "${!v}")"
|
||||
fi
|
||||
|
||||
+43
-15
@@ -4,6 +4,7 @@
|
||||
#include "nix/cmd/command.hh"
|
||||
#include "nix/cmd/legacy.hh"
|
||||
#include "nix/cmd/markdown.hh"
|
||||
#include "nix/store/globals.hh"
|
||||
#include "nix/store/store-open.hh"
|
||||
#include "nix/store/local-fs-store.hh"
|
||||
#include "nix/store/derivations.hh"
|
||||
@@ -63,6 +64,25 @@ void NixMultiCommand::run()
|
||||
command->second->run();
|
||||
}
|
||||
|
||||
StoreConfigCommand::StoreConfigCommand() {}
|
||||
|
||||
ref<StoreConfig> StoreConfigCommand::getStoreConfig()
|
||||
{
|
||||
if (!_storeConfig)
|
||||
_storeConfig = createStoreConfig();
|
||||
return ref<StoreConfig>(_storeConfig);
|
||||
}
|
||||
|
||||
ref<StoreConfig> StoreConfigCommand::createStoreConfig()
|
||||
{
|
||||
return resolveStoreConfig(StoreReference{settings.storeUri.get()});
|
||||
}
|
||||
|
||||
void StoreConfigCommand::run()
|
||||
{
|
||||
run(getStoreConfig());
|
||||
}
|
||||
|
||||
StoreCommand::StoreCommand() {}
|
||||
|
||||
ref<Store> StoreCommand::getStore()
|
||||
@@ -74,12 +94,20 @@ ref<Store> StoreCommand::getStore()
|
||||
|
||||
ref<Store> StoreCommand::createStore()
|
||||
{
|
||||
return openStore();
|
||||
auto store = getStoreConfig()->openStore();
|
||||
store->init();
|
||||
return store;
|
||||
}
|
||||
|
||||
void StoreCommand::run()
|
||||
void StoreCommand::run(ref<StoreConfig> storeConfig)
|
||||
{
|
||||
run(getStore());
|
||||
// We can either efficiently implement getStore/createStore with memoization,
|
||||
// or use the StoreConfig passed in run.
|
||||
// It's more efficient to memoize, especially since there are some direct users
|
||||
// of getStore. The StoreConfig in both cases should be the same, though.
|
||||
auto store = getStore();
|
||||
assert(&*storeConfig == &store->config);
|
||||
run(std::move(store));
|
||||
}
|
||||
|
||||
CopyCommand::CopyCommand()
|
||||
@@ -88,28 +116,28 @@ CopyCommand::CopyCommand()
|
||||
.longName = "from",
|
||||
.description = "URL of the source Nix store.",
|
||||
.labels = {"store-uri"},
|
||||
.handler = {&srcUri},
|
||||
.handler = {[this](std::string s) { srcUri = StoreReference::parse(s); }},
|
||||
});
|
||||
|
||||
addFlag({
|
||||
.longName = "to",
|
||||
.description = "URL of the destination Nix store.",
|
||||
.labels = {"store-uri"},
|
||||
.handler = {&dstUri},
|
||||
.handler = {[this](std::string s) { dstUri = StoreReference::parse(s); }},
|
||||
});
|
||||
}
|
||||
|
||||
ref<Store> CopyCommand::createStore()
|
||||
ref<StoreConfig> CopyCommand::createStoreConfig()
|
||||
{
|
||||
return srcUri.empty() ? StoreCommand::createStore() : openStore(srcUri);
|
||||
return !srcUri ? StoreCommand::createStoreConfig() : resolveStoreConfig(StoreReference{*srcUri});
|
||||
}
|
||||
|
||||
ref<Store> CopyCommand::getDstStore()
|
||||
{
|
||||
if (srcUri.empty() && dstUri.empty())
|
||||
if (!srcUri && !dstUri)
|
||||
throw UsageError("you must pass '--from' and/or '--to'");
|
||||
|
||||
return dstUri.empty() ? openStore() : openStore(dstUri);
|
||||
return !dstUri ? openStore() : openStore(StoreReference{*dstUri});
|
||||
}
|
||||
|
||||
EvalCommand::EvalCommand()
|
||||
@@ -131,7 +159,7 @@ EvalCommand::~EvalCommand()
|
||||
ref<Store> EvalCommand::getEvalStore()
|
||||
{
|
||||
if (!evalStore)
|
||||
evalStore = evalStoreUrl ? openStore(*evalStoreUrl) : getStore();
|
||||
evalStore = evalStoreUrl ? openStore(StoreReference{*evalStoreUrl}) : getStore();
|
||||
return ref<Store>(evalStore);
|
||||
}
|
||||
|
||||
@@ -257,18 +285,18 @@ MixProfile::MixProfile()
|
||||
});
|
||||
}
|
||||
|
||||
void MixProfile::updateProfile(const StorePath & storePath)
|
||||
void MixProfile::updateProfile(Store & store_, const StorePath & storePath)
|
||||
{
|
||||
if (!profile)
|
||||
return;
|
||||
auto store = getDstStore().dynamic_pointer_cast<LocalFSStore>();
|
||||
auto * store = dynamic_cast<LocalFSStore *>(&store_);
|
||||
if (!store)
|
||||
throw Error("'--profile' is not supported for this Nix store");
|
||||
auto profile2 = absPath(*profile);
|
||||
switchLink(profile2, createGeneration(*store, profile2, storePath));
|
||||
}
|
||||
|
||||
void MixProfile::updateProfile(const BuiltPaths & buildables)
|
||||
void MixProfile::updateProfile(Store & store, const BuiltPaths & buildables)
|
||||
{
|
||||
if (!profile)
|
||||
return;
|
||||
@@ -292,12 +320,12 @@ void MixProfile::updateProfile(const BuiltPaths & buildables)
|
||||
throw UsageError(
|
||||
"'--profile' requires that the arguments produce a single store path, but there are %d", result.size());
|
||||
|
||||
updateProfile(result[0]);
|
||||
updateProfile(store, result[0]);
|
||||
}
|
||||
|
||||
MixDefaultProfile::MixDefaultProfile()
|
||||
{
|
||||
profile = getDefaultProfile().string();
|
||||
profile = getDefaultProfile(settings.getProfileDirsOptions()).string();
|
||||
}
|
||||
|
||||
static constexpr auto environmentVariablesCategory = "Options that change environment variables";
|
||||
|
||||
@@ -148,7 +148,7 @@ MixEvalArgs::MixEvalArgs()
|
||||
)",
|
||||
.category = category,
|
||||
.labels = {"store-url"},
|
||||
.handler = {&evalStoreUrl},
|
||||
.handler = {[this](std::string s) { evalStoreUrl = StoreReference::parse(s); }},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
#include "nix/cmd/get-build-log.hh"
|
||||
#include "nix/store/log-store.hh"
|
||||
#include "nix/store/store-open.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
std::string fetchBuildLog(ref<Store> store, const StorePath & path, std::string_view what)
|
||||
{
|
||||
auto subs = getDefaultSubstituters();
|
||||
|
||||
subs.push_front(store);
|
||||
|
||||
for (auto & sub : subs) {
|
||||
auto * logSubP = dynamic_cast<LogStore *>(&*sub);
|
||||
if (!logSubP) {
|
||||
printInfo("Skipped '%s' which does not support retrieving build logs", sub->config.getHumanReadableURI());
|
||||
continue;
|
||||
}
|
||||
auto & logSub = *logSubP;
|
||||
|
||||
auto log = logSub.getBuildLog(path);
|
||||
if (!log)
|
||||
continue;
|
||||
printInfo("got build log for '%s' from '%s'", what, logSub.config.getHumanReadableURI());
|
||||
return *log;
|
||||
}
|
||||
|
||||
throw Error("build log of '%s' is not available", what);
|
||||
}
|
||||
|
||||
} // namespace nix
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "nix/util/args.hh"
|
||||
#include "nix/cmd/common-eval-args.hh"
|
||||
#include "nix/store/path.hh"
|
||||
#include "nix/store/store-reference.hh"
|
||||
#include "nix/flake/lockfile.hh"
|
||||
|
||||
#include <optional>
|
||||
@@ -40,28 +41,43 @@ struct NixMultiCommand : MultiCommand, virtual Command
|
||||
// For the overloaded run methods
|
||||
#pragma GCC diagnostic ignored "-Woverloaded-virtual"
|
||||
|
||||
/**
|
||||
* A command that requires a \ref StoreConfig store configuration.
|
||||
*/
|
||||
struct StoreConfigCommand : virtual Command
|
||||
{
|
||||
StoreConfigCommand();
|
||||
void run() override;
|
||||
|
||||
/**
|
||||
* Return the default Nix store configuration.
|
||||
*/
|
||||
ref<StoreConfig> getStoreConfig();
|
||||
|
||||
virtual ref<StoreConfig> createStoreConfig();
|
||||
/**
|
||||
* Main entry point, with a `StoreConfig` provided
|
||||
*/
|
||||
virtual void run(ref<StoreConfig>) = 0;
|
||||
|
||||
private:
|
||||
std::shared_ptr<StoreConfig> _storeConfig;
|
||||
};
|
||||
|
||||
/**
|
||||
* A command that requires a \ref Store "Nix store".
|
||||
*/
|
||||
struct StoreCommand : virtual Command
|
||||
struct StoreCommand : virtual StoreConfigCommand
|
||||
{
|
||||
StoreCommand();
|
||||
void run() override;
|
||||
void run(ref<StoreConfig>) override;
|
||||
|
||||
/**
|
||||
* Return the default Nix store.
|
||||
*/
|
||||
ref<Store> getStore();
|
||||
|
||||
/**
|
||||
* Return the destination Nix store.
|
||||
*/
|
||||
virtual ref<Store> getDstStore()
|
||||
{
|
||||
return getStore();
|
||||
}
|
||||
|
||||
virtual ref<Store> createStore();
|
||||
ref<Store> createStore();
|
||||
/**
|
||||
* Main entry point, with a `Store` provided
|
||||
*/
|
||||
@@ -77,13 +93,13 @@ private:
|
||||
*/
|
||||
struct CopyCommand : virtual StoreCommand
|
||||
{
|
||||
std::string srcUri, dstUri;
|
||||
std::optional<StoreReference> srcUri, dstUri;
|
||||
|
||||
CopyCommand();
|
||||
|
||||
ref<Store> createStore() override;
|
||||
ref<StoreConfig> createStoreConfig() override;
|
||||
|
||||
ref<Store> getDstStore() override;
|
||||
ref<Store> getDstStore();
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -315,11 +331,11 @@ struct MixProfile : virtual StoreCommand
|
||||
MixProfile();
|
||||
|
||||
/* If 'profile' is set, make it point at 'storePath'. */
|
||||
void updateProfile(const StorePath & storePath);
|
||||
void updateProfile(Store & store, const StorePath & storePath);
|
||||
|
||||
/* If 'profile' is set, make it point at the store path produced
|
||||
by 'buildables'. */
|
||||
void updateProfile(const BuiltPaths & buildables);
|
||||
void updateProfile(Store & store, const BuiltPaths & buildables);
|
||||
};
|
||||
|
||||
struct MixDefaultProfile : MixProfile
|
||||
@@ -391,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)
|
||||
@@ -419,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{}},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "nix/main/common-args.hh"
|
||||
#include "nix/expr/search-path.hh"
|
||||
#include "nix/expr/eval-settings.hh"
|
||||
#include "nix/store/store-reference.hh"
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
@@ -55,7 +56,7 @@ struct MixEvalArgs : virtual Args, virtual MixRepair
|
||||
|
||||
LookupPath lookupPath;
|
||||
|
||||
std::optional<std::string> evalStoreUrl;
|
||||
std::optional<StoreReference> evalStoreUrl;
|
||||
|
||||
private:
|
||||
struct AutoArgExpr
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
///@file
|
||||
|
||||
#include "nix/store/store-api.hh"
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace nix {
|
||||
|
||||
/**
|
||||
* Fetch the build log for a store path, searching the store and its
|
||||
* substituters.
|
||||
*
|
||||
* @param store The store to search (and its substituters).
|
||||
* @param path The store path to get the build log for.
|
||||
* @param what A description of what we're fetching the log for (used in messages).
|
||||
* @return The build log content.
|
||||
* @throws Error if the build log is not available.
|
||||
*/
|
||||
std::string fetchBuildLog(ref<Store> store, const StorePath & path, std::string_view what);
|
||||
|
||||
} // namespace nix
|
||||
@@ -9,6 +9,7 @@ headers = files(
|
||||
'common-eval-args.hh',
|
||||
'compatibility-settings.hh',
|
||||
'editor-for.hh',
|
||||
'get-build-log.hh',
|
||||
'installable-attr-path.hh',
|
||||
'installable-derived-path.hh',
|
||||
'installable-flake.hh',
|
||||
@@ -20,4 +21,5 @@ headers = files(
|
||||
'network-proxy.hh',
|
||||
'repl-interacter.hh',
|
||||
'repl.hh',
|
||||
'unix-socket-server.hh',
|
||||
)
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "nix/util/finally.hh"
|
||||
#include "nix/util/types.hh"
|
||||
#include <filesystem>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
@@ -14,6 +15,7 @@ namespace detail {
|
||||
struct ReplCompleterMixin
|
||||
{
|
||||
virtual StringSet completePrefix(const std::string & prefix) = 0;
|
||||
virtual ~ReplCompleterMixin() = default;
|
||||
};
|
||||
}; // namespace detail
|
||||
|
||||
@@ -35,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 {
|
||||
|
||||
@@ -25,10 +26,9 @@ struct AbstractNixRepl
|
||||
* @todo this is a layer violation
|
||||
*
|
||||
* @param programName Name of the command, e.g. `nix` or `nix-env`.
|
||||
* @param args aguments to the command.
|
||||
* @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
|
||||
@@ -37,7 +37,6 @@ struct AbstractNixRepl
|
||||
*/
|
||||
static std::unique_ptr<AbstractNixRepl> create(
|
||||
const LookupPath & lookupPath,
|
||||
nix::ref<Store> store,
|
||||
ref<EvalState> state,
|
||||
std::function<AnnotatedValues()> getValues,
|
||||
RunNix * runNix = nullptr);
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
#pragma once
|
||||
///@file
|
||||
|
||||
#include "nix/util/file-descriptor.hh"
|
||||
|
||||
#include <filesystem>
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include <sys/types.h>
|
||||
|
||||
namespace nix::unix {
|
||||
|
||||
/**
|
||||
* Information about the identity of the peer on a Unix domain socket connection.
|
||||
*/
|
||||
struct PeerInfo
|
||||
{
|
||||
std::optional<pid_t> pid;
|
||||
std::optional<uid_t> uid;
|
||||
std::optional<gid_t> gid;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the identity of the caller, if possible.
|
||||
*/
|
||||
PeerInfo getPeerInfo(Descriptor remote);
|
||||
|
||||
/**
|
||||
* Callback type for handling new connections.
|
||||
*
|
||||
* The callback receives ownership of the connection and is responsible
|
||||
* for handling it (e.g., forking a child process, spawning a thread, etc.).
|
||||
*
|
||||
* @param socket The accepted connection file descriptor.
|
||||
* @param closeListeners A callback to close the listening sockets.
|
||||
* Useful in forked child processes to release the bound sockets.
|
||||
*/
|
||||
using UnixSocketHandler = std::function<void(AutoCloseFD socket, std::function<void()> closeListeners)>;
|
||||
|
||||
/**
|
||||
* Options for the serve loop.
|
||||
*
|
||||
* Only used if no systemd socket activation is detected.
|
||||
*/
|
||||
struct ServeUnixSocketOptions
|
||||
{
|
||||
/**
|
||||
* The Unix domain socket path to create and listen on.
|
||||
*/
|
||||
std::filesystem::path socketPath;
|
||||
|
||||
/**
|
||||
* Mode for the created socket file.
|
||||
*/
|
||||
mode_t socketMode = 0666;
|
||||
};
|
||||
|
||||
/**
|
||||
* Run a server loop that accepts connections and calls the handler for each.
|
||||
*
|
||||
* This function handles:
|
||||
* - systemd socket activation (via LISTEN_FDS environment variable)
|
||||
* - Creating and binding a Unix domain socket if no activation is detected
|
||||
* - Polling for incoming connections
|
||||
* - Accepting connections
|
||||
*
|
||||
* For each accepted connection, the handler is called with the connection
|
||||
* file descriptor. The handler takes ownership of the file descriptor and
|
||||
* is responsible for closing it when done.
|
||||
*
|
||||
* This function never returns normally. It runs until interrupted
|
||||
* (e.g., via SIGINT), at which point it throws `Interrupted`.
|
||||
*
|
||||
* @param options Configuration for the server.
|
||||
* @param handler Callback invoked for each accepted connection.
|
||||
*/
|
||||
[[noreturn]] void serveUnixSocket(const ServeUnixSocketOptions & options, UnixSocketHandler handler);
|
||||
|
||||
} // namespace nix::unix
|
||||
@@ -203,8 +203,10 @@ FlakeRef InstallableFlake::nixpkgsFlakeRef() const
|
||||
|
||||
if (auto nixpkgsInput = lockedFlake->lockFile.findInput({"nixpkgs"})) {
|
||||
if (auto lockedNode = std::dynamic_pointer_cast<const flake::LockedNode>(nixpkgsInput)) {
|
||||
debug("using nixpkgs flake '%s'", lockedNode->lockedRef);
|
||||
return std::move(lockedNode->lockedRef);
|
||||
if (lockedNode->isFlake) {
|
||||
debug("using nixpkgs flake '%s'", lockedNode->lockedRef);
|
||||
return std::move(lockedNode->lockedRef);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
@@ -583,16 +583,12 @@ static void throwBuildErrors(std::vector<KeyedBuildResult> & buildResults, const
|
||||
auto failedResult = failed.begin();
|
||||
if (failedResult != failed.end()) {
|
||||
if (failed.size() == 1) {
|
||||
failedResult->second->rethrow();
|
||||
throw *failedResult->second;
|
||||
} else {
|
||||
StringSet failedPaths;
|
||||
for (; failedResult != failed.end(); failedResult++) {
|
||||
if (!failedResult->second->errorMsg.empty()) {
|
||||
logError(
|
||||
ErrorInfo{
|
||||
.level = lvlError,
|
||||
.msg = failedResult->second->errorMsg,
|
||||
});
|
||||
if (!failedResult->second->message().empty()) {
|
||||
logError(failedResult->second->info());
|
||||
}
|
||||
failedPaths.insert(failedResult->first->path.to_string(store));
|
||||
}
|
||||
|
||||
@@ -74,6 +74,7 @@ sources = files(
|
||||
'command.cc',
|
||||
'common-eval-args.cc',
|
||||
'editor-for.cc',
|
||||
'get-build-log.cc',
|
||||
'installable-attr-path.cc',
|
||||
'installable-derived-path.cc',
|
||||
'installable-flake.cc',
|
||||
@@ -86,6 +87,12 @@ sources = files(
|
||||
'repl.cc',
|
||||
)
|
||||
|
||||
if host_machine.system() != 'windows'
|
||||
sources += files(
|
||||
'unix/unix-socket-server.cc',
|
||||
)
|
||||
endif
|
||||
|
||||
subdir('include/nix/cmd')
|
||||
|
||||
subdir('nix-meson-build-support/export-all-symbols')
|
||||
|
||||
@@ -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
|
||||
+73
-72
@@ -1,6 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
||||
#include "nix/util/error.hh"
|
||||
#include "nix/cmd/repl-interacter.hh"
|
||||
@@ -12,9 +13,8 @@
|
||||
#include "nix/expr/eval-settings.hh"
|
||||
#include "nix/expr/attr-path.hh"
|
||||
#include "nix/util/signals.hh"
|
||||
#include "nix/store/store-open.hh"
|
||||
#include "nix/store/log-store.hh"
|
||||
#include "nix/cmd/common-eval-args.hh"
|
||||
#include "nix/cmd/get-build-log.hh"
|
||||
#include "nix/expr/get-drvs.hh"
|
||||
#include "nix/store/derivations.hh"
|
||||
#include "nix/store/globals.hh"
|
||||
@@ -29,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 {
|
||||
@@ -65,20 +67,19 @@ struct NixRepl : AbstractNixRepl, detail::ReplCompleterMixin, gc
|
||||
|
||||
const static int envSize = 32768;
|
||||
std::shared_ptr<StaticEnv> staticEnv;
|
||||
Value lastLoaded;
|
||||
std::optional<Value> lastLoaded;
|
||||
Env * env;
|
||||
int displ;
|
||||
StringSet varNames;
|
||||
|
||||
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;
|
||||
|
||||
NixRepl(
|
||||
const LookupPath & lookupPath,
|
||||
nix::ref<Store> store,
|
||||
ref<EvalState> state,
|
||||
std::function<AnnotatedValues()> getValues,
|
||||
RunNix * runNix);
|
||||
@@ -100,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);
|
||||
|
||||
@@ -133,7 +135,6 @@ std::string removeWhitespace(std::string s)
|
||||
|
||||
NixRepl::NixRepl(
|
||||
const LookupPath & lookupPath,
|
||||
nix::ref<Store> store,
|
||||
ref<EvalState> state,
|
||||
std::function<NixRepl::AnnotatedValues()> getValues,
|
||||
RunNix * runNix)
|
||||
@@ -142,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"))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -309,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);
|
||||
@@ -511,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();
|
||||
@@ -531,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") {
|
||||
@@ -562,37 +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; });
|
||||
auto subs = getDefaultSubstituters();
|
||||
|
||||
subs.push_front(state->store);
|
||||
|
||||
bool foundLog = false;
|
||||
RunPager pager;
|
||||
for (auto & sub : subs) {
|
||||
auto * logSubP = dynamic_cast<LogStore *>(&*sub);
|
||||
if (!logSubP) {
|
||||
printInfo(
|
||||
"Skipped '%s' which does not support retrieving build logs", sub->config.getHumanReadableURI());
|
||||
continue;
|
||||
}
|
||||
auto & logSub = *logSubP;
|
||||
|
||||
auto log = logSub.getBuildLog(drvPath);
|
||||
if (log) {
|
||||
printInfo("got build log for '%s' from '%s'", drvPathRaw, logSub.config.getHumanReadableURI());
|
||||
logger->writeToStdout(*log);
|
||||
foundLog = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!foundLog)
|
||||
throw Error("build log of '%s' is not available", drvPathRaw);
|
||||
auto log = fetchBuildLog(state->store, drvPath, drvPathRaw);
|
||||
logger->writeToStdout(log);
|
||||
} else {
|
||||
runNix("nix-shell", {drvPathRaw});
|
||||
runNix("nix-shell", toOsStrings({drvPathRaw}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -693,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();
|
||||
@@ -735,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);
|
||||
@@ -773,11 +749,19 @@ void NixRepl::initEnv()
|
||||
|
||||
void NixRepl::showLastLoaded()
|
||||
{
|
||||
RunPager pager;
|
||||
if (!lastLoaded)
|
||||
throw Error("nothing has been loaded yet");
|
||||
|
||||
for (auto & i : *lastLoaded.attrs()) {
|
||||
std::string_view name = state->symbols[i.name];
|
||||
logger->cout(name);
|
||||
RunPager pager;
|
||||
try {
|
||||
for (auto & i : *lastLoaded->attrs()) {
|
||||
std::string_view name = state->symbols[i.name];
|
||||
logger->cout(name);
|
||||
}
|
||||
} catch (SystemError & e) {
|
||||
/* Ignore broken pipes when the pager gets interrupted. */
|
||||
if (!e.is(std::errc::broken_pipe))
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -882,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);
|
||||
@@ -889,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",
|
||||
@@ -900,13 +906,9 @@ void NixRepl::runNix(const std::string & program, const Strings & args, const st
|
||||
}
|
||||
|
||||
std::unique_ptr<AbstractNixRepl> AbstractNixRepl::create(
|
||||
const LookupPath & lookupPath,
|
||||
nix::ref<Store> store,
|
||||
ref<EvalState> state,
|
||||
std::function<AnnotatedValues()> getValues,
|
||||
RunNix * runNix)
|
||||
const LookupPath & lookupPath, ref<EvalState> state, std::function<AnnotatedValues()> getValues, RunNix * runNix)
|
||||
{
|
||||
return std::make_unique<NixRepl>(lookupPath, std::move(store), state, getValues, runNix);
|
||||
return std::make_unique<NixRepl>(lookupPath, state, getValues, runNix);
|
||||
}
|
||||
|
||||
ReplExitStatus AbstractNixRepl::runSimple(ref<EvalState> evalState, const ValMap & extraEnv)
|
||||
@@ -919,7 +921,6 @@ ReplExitStatus AbstractNixRepl::runSimple(ref<EvalState> evalState, const ValMap
|
||||
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDelete)
|
||||
auto repl = std::make_unique<NixRepl>(
|
||||
lookupPath,
|
||||
openStore(),
|
||||
evalState,
|
||||
getValues,
|
||||
/*runNix=*/nullptr);
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
///@file
|
||||
|
||||
#include "nix/cmd/unix-socket-server.hh"
|
||||
#include "nix/util/environment-variables.hh"
|
||||
#include "nix/util/file-system.hh"
|
||||
#include "nix/util/logging.hh"
|
||||
#include "nix/util/signals.hh"
|
||||
#include "nix/util/strings.hh"
|
||||
#include "nix/util/unix-domain-socket.hh"
|
||||
#include "nix/util/util.hh"
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <poll.h>
|
||||
|
||||
#if defined(__APPLE__) || defined(__FreeBSD__)
|
||||
# include <sys/ucred.h>
|
||||
#endif
|
||||
|
||||
namespace nix::unix {
|
||||
|
||||
PeerInfo getPeerInfo(Descriptor remote)
|
||||
{
|
||||
PeerInfo peer;
|
||||
|
||||
#if defined(SO_PEERCRED)
|
||||
|
||||
# if defined(__OpenBSD__)
|
||||
struct sockpeercred cred;
|
||||
# else
|
||||
ucred cred;
|
||||
# endif
|
||||
socklen_t credLen = sizeof(cred);
|
||||
if (getsockopt(remote, SOL_SOCKET, SO_PEERCRED, &cred, &credLen) == 0) {
|
||||
peer.pid = cred.pid;
|
||||
peer.uid = cred.uid;
|
||||
peer.gid = cred.gid;
|
||||
}
|
||||
|
||||
#elif defined(LOCAL_PEERCRED)
|
||||
|
||||
# if !defined(SOL_LOCAL)
|
||||
# define SOL_LOCAL 0
|
||||
# endif
|
||||
|
||||
xucred cred;
|
||||
socklen_t credLen = sizeof(cred);
|
||||
if (getsockopt(remote, SOL_LOCAL, LOCAL_PEERCRED, &cred, &credLen) == 0)
|
||||
peer.uid = cred.cr_uid;
|
||||
|
||||
#endif
|
||||
|
||||
return peer;
|
||||
}
|
||||
|
||||
[[noreturn]] void serveUnixSocket(const ServeUnixSocketOptions & options, UnixSocketHandler handler)
|
||||
{
|
||||
std::vector<AutoCloseFD> listeningSockets;
|
||||
|
||||
static constexpr int SD_LISTEN_FDS_START = 3;
|
||||
|
||||
// Handle socket-based activation by systemd.
|
||||
auto listenFds = getEnv("LISTEN_FDS");
|
||||
if (listenFds) {
|
||||
if (getEnv("LISTEN_PID") != std::to_string(getpid()))
|
||||
throw Error("unexpected systemd environment variables");
|
||||
auto count = string2Int<unsigned int>(*listenFds);
|
||||
assert(count);
|
||||
for (unsigned int i = 0; i < count; ++i) {
|
||||
AutoCloseFD fdSocket(SD_LISTEN_FDS_START + i);
|
||||
closeOnExec(fdSocket.get());
|
||||
listeningSockets.push_back(std::move(fdSocket));
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, create and bind to a Unix domain socket.
|
||||
else {
|
||||
createDirs(options.socketPath.parent_path());
|
||||
listeningSockets.push_back(createUnixDomainSocket(options.socketPath.string(), options.socketMode));
|
||||
}
|
||||
|
||||
std::vector<struct pollfd> fds;
|
||||
for (auto & i : listeningSockets)
|
||||
fds.push_back({.fd = i.get(), .events = POLLIN});
|
||||
|
||||
// Loop accepting connections.
|
||||
while (1) {
|
||||
try {
|
||||
checkInterrupt();
|
||||
|
||||
auto count = poll(fds.data(), fds.size(), -1);
|
||||
if (count == -1) {
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
throw SysError("polling for incoming connections");
|
||||
}
|
||||
|
||||
for (auto & fd : fds) {
|
||||
if (!fd.revents)
|
||||
continue;
|
||||
|
||||
// Accept a connection.
|
||||
struct sockaddr_un remoteAddr;
|
||||
socklen_t remoteAddrLen = sizeof(remoteAddr);
|
||||
|
||||
AutoCloseFD remote = accept(fd.fd, (struct sockaddr *) &remoteAddr, &remoteAddrLen);
|
||||
checkInterrupt();
|
||||
if (!remote) {
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
throw SysError("accepting connection");
|
||||
}
|
||||
|
||||
handler(std::move(remote), [&]() { listeningSockets.clear(); });
|
||||
}
|
||||
|
||||
} catch (Error & error) {
|
||||
auto ei = error.info();
|
||||
// FIXME: add to trace?
|
||||
ei.msg = HintFmt("while processing connection: %1%", ei.msg.str());
|
||||
logError(ei);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace nix::unix
|
||||
@@ -185,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,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@@ -24,7 +24,8 @@ 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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
@@ -756,7 +756,7 @@ TEST_F(PrimOpTest, langVersion)
|
||||
TEST_F(PrimOpTest, storeDir)
|
||||
{
|
||||
auto v = eval("builtins.storeDir");
|
||||
ASSERT_THAT(v, IsStringEq(settings.nixStore));
|
||||
ASSERT_THAT(v, IsStringEq(state.store->storeDir));
|
||||
}
|
||||
|
||||
TEST_F(PrimOpTest, nixVersion)
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
@@ -70,7 +70,7 @@ struct AttrDb
|
||||
{
|
||||
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");
|
||||
|
||||
@@ -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
|
||||
@@ -133,11 +133,17 @@ class SampleStack : public EvalProfiler
|
||||
FrameInfo getPrimOpFrameInfo(const PrimOp & primOp, std::span<Value *> args, PosIdx pos);
|
||||
|
||||
public:
|
||||
SampleStack(EvalState & state, std::filesystem::path profileFile, std::chrono::nanoseconds period)
|
||||
SampleStack(EvalState & state, const std::filesystem::path & profileFile, std::chrono::nanoseconds period)
|
||||
: state(state)
|
||||
, sampleInterval(period)
|
||||
, profileFd([&]() {
|
||||
AutoCloseFD fd = toDescriptor(open(profileFile.string().c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0660));
|
||||
auto fd = openNewFileForWrite(
|
||||
profileFile,
|
||||
0660,
|
||||
{
|
||||
.truncateExisting = true,
|
||||
.followSymlinksOnTruncate = true, /* FIXME: Probably shouldn't follow symlinks. */
|
||||
});
|
||||
if (!fd)
|
||||
throw SysError("opening file %s", PathFmt(profileFile));
|
||||
return fd;
|
||||
|
||||
@@ -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)
|
||||
@@ -70,9 +91,10 @@ Strings EvalSettings::getDefaultNixPath()
|
||||
}
|
||||
};
|
||||
|
||||
add(std::filesystem::path{getNixDefExpr()} / "channels");
|
||||
add(rootChannelsDir() / "nixpkgs", "nixpkgs");
|
||||
add(rootChannelsDir());
|
||||
add(getNixDefExpr() / "channels");
|
||||
auto profilesDirOpts = settings.getProfileDirsOptions();
|
||||
add(rootChannelsDir(profilesDirOpts) / "nixpkgs", "nixpkgs");
|
||||
add(rootChannelsDir(profilesDirOpts));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
+185
-39
@@ -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"
|
||||
@@ -31,6 +32,7 @@
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
@@ -155,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();
|
||||
}
|
||||
@@ -318,7 +322,6 @@ EvalState::EvalState(
|
||||
countCalls = getEnv("NIX_COUNT_CALLS").value_or("0") != "0";
|
||||
|
||||
static_assert(sizeof(Env) <= 16, "environment must be <= 16 bytes");
|
||||
static_assert(sizeof(Counter) == 64, "counters must be 64 bytes");
|
||||
|
||||
/* Construct the Nix expression search path. */
|
||||
assert(lookupPath.elements.empty());
|
||||
@@ -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 (...) {
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace nix {
|
||||
* variable is set. This is to prevent contention on these counters
|
||||
* when multi-threaded evaluation is enabled.
|
||||
*/
|
||||
struct alignas(64) Counter
|
||||
struct alignas(std::hardware_destructive_interference_size) Counter
|
||||
{
|
||||
using value_type = uint64_t;
|
||||
|
||||
|
||||
@@ -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"
|
||||
@@ -10,6 +11,36 @@ namespace nix {
|
||||
class EvalState;
|
||||
struct PrimOp;
|
||||
|
||||
/**
|
||||
* A deprecated bool setting that migrates to a `Setting<Diagnose>`.
|
||||
* When set to true, it emits a deprecation warning and sets the target
|
||||
* `Setting<Diagnose>` setting to `warn`.
|
||||
*/
|
||||
class DeprecatedWarnSetting : public BaseSetting<bool>
|
||||
{
|
||||
Setting<Diagnose> & target;
|
||||
const char * targetName;
|
||||
|
||||
public:
|
||||
DeprecatedWarnSetting(
|
||||
Config * options,
|
||||
Setting<Diagnose> & target,
|
||||
const char * targetName,
|
||||
const std::string & name,
|
||||
const std::string & description,
|
||||
const StringSet & aliases = {})
|
||||
: BaseSetting<bool>(false, true, name, description, aliases, std::nullopt)
|
||||
, target(target)
|
||||
, targetName(targetName)
|
||||
{
|
||||
options->addSetting(this);
|
||||
}
|
||||
|
||||
void assign(const bool & v) override;
|
||||
void appendOrSet(bool newValue, bool append) override;
|
||||
void override(const bool & v) override;
|
||||
};
|
||||
|
||||
struct EvalSettings : Config
|
||||
{
|
||||
/**
|
||||
@@ -328,20 +359,70 @@ struct EvalSettings : Config
|
||||
This option can be enabled by setting `NIX_ABORT_ON_WARN=1` in the environment.
|
||||
)"};
|
||||
|
||||
Setting<bool> warnShortPathLiterals{
|
||||
Setting<Diagnose> lintShortPathLiterals{
|
||||
this,
|
||||
false,
|
||||
"warn-short-path-literals",
|
||||
Diagnose::Ignore,
|
||||
"lint-short-path-literals",
|
||||
R"(
|
||||
If set to true, the Nix evaluator will warn when encountering relative path literals
|
||||
that don't start with `./` or `../`.
|
||||
Controls handling of relative path literals that don't start with `./` or `../`.
|
||||
|
||||
For example, with this setting enabled, `foo/bar` would emit a warning
|
||||
suggesting to use `./foo/bar` instead.
|
||||
- `ignore`: Ignore without warning (default)
|
||||
- `warn`: Emit a warning suggesting to use `./` prefix
|
||||
- `fatal`: Treat as a parse error
|
||||
|
||||
For example, with this setting set to `warn` or `fatal`, `foo/bar` would
|
||||
suggest using `./foo/bar` instead.
|
||||
|
||||
This is useful for improving code readability and making path literals
|
||||
more explicit.
|
||||
)"};
|
||||
)",
|
||||
};
|
||||
|
||||
DeprecatedWarnSetting warnShortPathLiterals{
|
||||
this,
|
||||
lintShortPathLiterals,
|
||||
"lint-short-path-literals",
|
||||
"warn-short-path-literals",
|
||||
R"(
|
||||
Deprecated. Use [`lint-short-path-literals`](#conf-lint-short-path-literals)` = warn` instead.
|
||||
)",
|
||||
};
|
||||
|
||||
Setting<Diagnose> lintUrlLiterals{
|
||||
this,
|
||||
Diagnose::Ignore,
|
||||
"lint-url-literals",
|
||||
R"(
|
||||
Controls handling of unquoted URLs as part of the Nix language syntax.
|
||||
The Nix language allows for URL literals, like so:
|
||||
|
||||
```
|
||||
$ nix repl
|
||||
nix-repl> http://foo
|
||||
"http://foo"
|
||||
```
|
||||
|
||||
Setting this to `warn` or `fatal` will cause the Nix parser to
|
||||
warn or throw an error when encountering a URL literal:
|
||||
|
||||
```
|
||||
$ nix repl --lint-url-literals fatal
|
||||
nix-repl> http://foo
|
||||
error: URL literal 'http://foo' is deprecated
|
||||
at «string»:1:1:
|
||||
|
||||
1| http://foo
|
||||
| ^
|
||||
```
|
||||
|
||||
Unquoted URLs are being deprecated and their usage is discouraged.
|
||||
|
||||
The reason is that, as opposed to path literals, URLs have no
|
||||
special properties that distinguish them from regular strings, URLs
|
||||
containing query parameters have to be quoted anyway, and unquoted URLs
|
||||
may confuse external tooling.
|
||||
)",
|
||||
};
|
||||
|
||||
Setting<unsigned> bindingsUpdateLayerRhsSizeThreshold{
|
||||
this,
|
||||
|
||||
@@ -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,
|
||||
@@ -134,7 +141,7 @@ public:
|
||||
virtual bool operator==(const ExternalValueBase & b) const noexcept;
|
||||
|
||||
/**
|
||||
* Print the value as JSON. Defaults to unconvertable, i.e. throws an error
|
||||
* Print the value as JSON. Defaults to unconvertible, i.e. throws an error
|
||||
*/
|
||||
virtual nlohmann::json
|
||||
printValueAsJSON(EvalState & state, bool strict, NixStringContext & context, bool copyToStore = true) const;
|
||||
@@ -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) \
|
||||
@@ -533,8 +571,8 @@ inline constexpr bool useBitPackedValueStorage = (ptrSize == 8) && (__STDCPP_DEF
|
||||
* Packs discriminator bits into the pointer alignment niches.
|
||||
*/
|
||||
template<std::size_t ptrSize>
|
||||
class alignas(16) ValueStorage<ptrSize, std::enable_if_t<detail::useBitPackedValueStorage<ptrSize>>>
|
||||
: public detail::ValueBase
|
||||
class alignas(16)
|
||||
ValueStorage<ptrSize, std::enable_if_t<detail::useBitPackedValueStorage<ptrSize>>> : public detail::ValueBase
|
||||
{
|
||||
/* Needs a dependent type name in order for member functions (and
|
||||
* potentially ill-formed bit casts) to be SFINAE'd out.
|
||||
@@ -587,7 +625,7 @@ class alignas(16) ValueStorage<ptrSize, std::enable_if_t<detail::useBitPackedVal
|
||||
enum PrimaryDiscriminator : int {
|
||||
pdUninitialized = 0,
|
||||
pdSingleDWord, //< layout: Single/zero field payload
|
||||
/* The order of these enumations must be the same as in InternalType. */
|
||||
/* The order of these enumerations must be the same as in InternalType. */
|
||||
pdListN, //< layout: Single untaggable field.
|
||||
pdString,
|
||||
pdPath,
|
||||
@@ -633,7 +671,7 @@ class alignas(16) ValueStorage<ptrSize, std::enable_if_t<detail::useBitPackedVal
|
||||
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) ValueStorage<ptrSize, std::enable_if_t<detail::useBitPackedVal
|
||||
{
|
||||
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',
|
||||
|
||||
+130
-24
@@ -3,7 +3,7 @@
|
||||
%define api.namespace { ::nix::parser }
|
||||
%define api.parser.class { BisonParser }
|
||||
%locations
|
||||
%define parse.error verbose
|
||||
%define parse.error detailed
|
||||
%defines
|
||||
/* %no-lines */
|
||||
%parse-param { void * scanner }
|
||||
@@ -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
|
||||
@@ -140,18 +168,42 @@ static Expr * makeCall(Exprs & exprs, PosIdx pos, Expr * fn, Expr * arg) {
|
||||
%type <Expr *> path_start
|
||||
%type <ToBeStringyExpr> string_parts string_attr
|
||||
%type <StringToken> attr
|
||||
%token <StringToken> ID
|
||||
%token <StringToken> STR IND_STR
|
||||
%token <NixInt> INT_LIT
|
||||
%token <NixFloat> FLOAT_LIT
|
||||
%token <StringToken> PATH HPATH SPATH PATH_END
|
||||
%token <StringToken> URI
|
||||
%token IF THEN ELSE ASSERT WITH LET IN_KW REC INHERIT EQ NEQ AND OR IMPL OR_KW
|
||||
%token PIPE_FROM PIPE_INTO /* <| and |> */
|
||||
%token DOLLAR_CURLY /* == ${ */
|
||||
%token IND_STRING_OPEN IND_STRING_CLOSE
|
||||
%token ELLIPSIS
|
||||
|
||||
%token <StringToken> ID "identifier"
|
||||
%token <StringToken> STR "string"
|
||||
%token <StringToken> IND_STR "indented string"
|
||||
%token <NixInt> INT_LIT "integer"
|
||||
%token <NixFloat> FLOAT_LIT "floating-point literal"
|
||||
%token <StringToken> PATH "path"
|
||||
%token <StringToken> HPATH "'~/…' path"
|
||||
%token <StringToken> SPATH "'<…>' path"
|
||||
%token <StringToken> PATH_END "end of path"
|
||||
%token <StringToken> URI "URI"
|
||||
%token IF "'if'"
|
||||
%token THEN "'then'"
|
||||
%token ELSE "'else'"
|
||||
%token ASSERT "'assert'"
|
||||
%token WITH "'with'"
|
||||
%token LET "'let'"
|
||||
%token IN_KW "'in'"
|
||||
%token REC "'rec'"
|
||||
%token INHERIT "'inherit'"
|
||||
%token EQ "'=='"
|
||||
%token NEQ "'!='"
|
||||
%token LEQ "'<='"
|
||||
%token GEQ "'>='"
|
||||
%token UPDATE "'//'"
|
||||
%token CONCAT "'++'"
|
||||
%token AND "'&&'"
|
||||
%token OR "'||'"
|
||||
%token IMPL "'->'"
|
||||
%token OR_KW "'or'"
|
||||
%token PIPE_FROM "'<|'"
|
||||
%token PIPE_INTO "'|>'"
|
||||
%token DOLLAR_CURLY "'${'"
|
||||
%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
|
||||
@@ -173,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;
|
||||
@@ -314,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; }
|
||||
@@ -358,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 += '/';
|
||||
@@ -554,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)
|
||||
@@ -23,13 +23,12 @@ SourcePath EvalState::storePath(const StorePath & path)
|
||||
StorePath
|
||||
EvalState::mountInput(fetchers::Input & input, const fetchers::Input & originalInput, ref<SourceAccessor> accessor)
|
||||
{
|
||||
auto storePath = fetchToStore(fetchSettings, *store, accessor, FetchMode::Copy, input.getName());
|
||||
auto [storePath, narHash] = fetchToStore2(fetchSettings, *store, accessor, FetchMode::Copy, input.getName());
|
||||
|
||||
allowPath(storePath); // FIXME: should just whitelist the entire virtual store
|
||||
|
||||
storeFS->mount(CanonPath(store->printStorePath(storePath)), accessor);
|
||||
|
||||
auto narHash = store->queryPathInfo(storePath)->narHash;
|
||||
input.attrs.insert_or_assign("narHash", narHash.to_string(HashFormat::SRI, true));
|
||||
|
||||
if (originalInput.getNarHash() && narHash != *originalInput.getNarHash())
|
||||
|
||||
+20
-12
@@ -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);
|
||||
}
|
||||
|
||||
@@ -1814,8 +1817,13 @@ static void derivationStrictInternal(EvalState & state, std::string_view drvName
|
||||
drv.fillInOutputPaths(*state.store);
|
||||
}
|
||||
|
||||
/* Write the resulting term into the Nix store directory. */
|
||||
auto drvPath = writeDerivation(*state.store, drv, state.repair);
|
||||
/* Write the resulting term into the Nix store directory.
|
||||
|
||||
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 =
|
||||
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);
|
||||
@@ -1926,7 +1934,7 @@ static void prim_storePath(EvalState & state, const PosIdx pos, Value ** args, V
|
||||
directly in the store. The latter condition is necessary so
|
||||
e.g. nix-push does the right thing. */
|
||||
if (!state.store->isStorePath(path.abs()))
|
||||
path = CanonPath(canonPath(path.abs(), true));
|
||||
path = CanonPath(canonPath(path.abs(), true).string());
|
||||
if (!state.store->isInStore(path.abs()))
|
||||
state.error<EvalError>("path '%1%' is not in the Nix store", path).atPos(pos).debugThrow();
|
||||
auto path2 = state.store->toStorePath(path.abs()).first;
|
||||
@@ -2147,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();
|
||||
}
|
||||
|
||||
@@ -191,19 +191,25 @@ static void prim_fetchClosure(EvalState & state, const PosIdx pos, Value ** args
|
||||
{.msg = HintFmt("attribute '%s' is missing in call to 'fetchClosure'", "fromStore"),
|
||||
.pos = state.positions[pos]});
|
||||
|
||||
auto parsedURL = parseURL(*fromStoreUrl, /*lenient=*/true);
|
||||
auto storeRef = StoreReference::parse(*fromStoreUrl);
|
||||
|
||||
if (parsedURL.scheme != "http" && parsedURL.scheme != "https"
|
||||
&& !(getEnv("_NIX_IN_TEST").has_value() && parsedURL.scheme == "file"))
|
||||
throw Error(
|
||||
{.msg = HintFmt("'fetchClosure' only supports http:// and https:// stores"), .pos = state.positions[pos]});
|
||||
if ([&] {
|
||||
auto * specified = std::get_if<StoreReference::Specified>(&storeRef.variant);
|
||||
return !specified
|
||||
|| (specified->scheme != "http" && specified->scheme != "https"
|
||||
&& !(getEnv("_NIX_IN_TEST").has_value() && specified->scheme == "file"));
|
||||
}())
|
||||
throw Error({
|
||||
.msg = HintFmt("'fetchClosure' only supports http:// and https:// stores"),
|
||||
.pos = state.positions[pos],
|
||||
});
|
||||
|
||||
if (!parsedURL.query.empty())
|
||||
if (!storeRef.params.empty())
|
||||
throw Error(
|
||||
{.msg = HintFmt("'fetchClosure' does not support URL query parameters (in '%s')", *fromStoreUrl),
|
||||
.pos = state.positions[pos]});
|
||||
|
||||
auto fromStore = openStore(parsedURL.to_string());
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,14 +34,20 @@ struct CacheImpl : Cache
|
||||
|
||||
Sync<State> _state;
|
||||
|
||||
CacheImpl()
|
||||
/**
|
||||
* This is a back-reference to the `Settings` that owns us.
|
||||
*/
|
||||
const Settings & settings;
|
||||
|
||||
CacheImpl(const Settings & _settings)
|
||||
: settings(_settings)
|
||||
{
|
||||
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.useSQLiteWAL});
|
||||
state->db = SQLite(dbPath, {.useWAL = nix::settings.useSQLiteWAL});
|
||||
state->db.isCache();
|
||||
state->db.exec(schema);
|
||||
|
||||
@@ -154,7 +160,7 @@ ref<Cache> Settings::getCache() const
|
||||
{
|
||||
auto cache(_cache.lock());
|
||||
if (!*cache)
|
||||
*cache = std::make_shared<CacheImpl>();
|
||||
*cache = std::make_shared<CacheImpl>(*this);
|
||||
return ref<Cache>(*cache);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
|
||||
namespace nix {
|
||||
|
||||
fetchers::Cache::Key makeFetchToStoreCacheKey(
|
||||
const std::string & name, const std::string & fingerprint, ContentAddressMethod method, const std::string & path)
|
||||
fetchers::Cache::Key
|
||||
makeSourcePathToHashCacheKey(std::string_view fingerprint, ContentAddressMethod method, const CanonPath & path)
|
||||
{
|
||||
return fetchers::Cache::Key{
|
||||
"fetchToStore",
|
||||
{{"name", name}, {"fingerprint", fingerprint}, {"method", std::string{method.render()}}, {"path", path}}};
|
||||
"sourcePathToHash",
|
||||
{{"fingerprint", std::string(fingerprint)}, {"method", std::string{method.render()}}, {"path", path.abs()}}};
|
||||
}
|
||||
|
||||
StorePath fetchToStore(
|
||||
@@ -23,19 +23,45 @@ StorePath fetchToStore(
|
||||
PathFilter * filter,
|
||||
RepairFlag repair)
|
||||
{
|
||||
// FIXME: add an optimisation for the case where the accessor is
|
||||
// a `PosixSourceAccessor` pointing to a store path.
|
||||
return fetchToStore2(settings, store, path, mode, name, method, filter, repair).first;
|
||||
}
|
||||
|
||||
std::pair<StorePath, Hash> fetchToStore2(
|
||||
const fetchers::Settings & settings,
|
||||
Store & store,
|
||||
const SourcePath & path,
|
||||
FetchMode mode,
|
||||
std::string_view name,
|
||||
ContentAddressMethod method,
|
||||
PathFilter * filter,
|
||||
RepairFlag repair)
|
||||
{
|
||||
std::optional<fetchers::Cache::Key> cacheKey;
|
||||
|
||||
auto [subpath, fingerprint] = filter ? std::pair<CanonPath, std::optional<std::string>>{path.path, std::nullopt}
|
||||
: path.accessor->getFingerprint(path.path);
|
||||
|
||||
if (fingerprint) {
|
||||
cacheKey = makeFetchToStoreCacheKey(std::string{name}, *fingerprint, method, subpath.abs());
|
||||
if (auto res = settings.getCache()->lookupStorePath(*cacheKey, store)) {
|
||||
debug("store path cache hit for '%s'", path);
|
||||
return res->storePath;
|
||||
cacheKey = makeSourcePathToHashCacheKey(*fingerprint, method, subpath);
|
||||
if (auto res = settings.getCache()->lookup(*cacheKey)) {
|
||||
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')",
|
||||
path,
|
||||
store.printStorePath(storePath),
|
||||
hash.to_string(HashFormat::SRI, true));
|
||||
return {storePath, hash};
|
||||
}
|
||||
debug("source path '%s' not in store", path);
|
||||
}
|
||||
} else {
|
||||
static auto barf = getEnv("_NIX_TEST_BARF_ON_UNCACHEABLE").value_or("") == "1";
|
||||
@@ -53,16 +79,41 @@ StorePath fetchToStore(
|
||||
|
||||
auto filter2 = filter ? *filter : defaultPathFilter;
|
||||
|
||||
auto storePath = mode == FetchMode::DryRun
|
||||
? store.computeStorePath(name, path, method, HashAlgorithm::SHA256, {}, filter2).first
|
||||
: store.addToStore(name, path, method, HashAlgorithm::SHA256, {}, filter2, repair);
|
||||
auto [storePath, hash] =
|
||||
mode == FetchMode::DryRun
|
||||
? [&]() {
|
||||
auto [storePath, hash] =
|
||||
store.computeStorePath(name, path, method, HashAlgorithm::SHA256, {}, filter2);
|
||||
debug(
|
||||
"hashed '%s' to '%s' (hash '%s')",
|
||||
path,
|
||||
store.printStorePath(storePath),
|
||||
hash.to_string(HashFormat::SRI, true));
|
||||
return std::make_pair(storePath, hash);
|
||||
}()
|
||||
: [&]() {
|
||||
// FIXME: ideally addToStore() would return the hash
|
||||
// right away (like computeStorePath()).
|
||||
auto storePath = store.addToStore(name, path, method, HashAlgorithm::SHA256, {}, filter2, repair);
|
||||
auto info = store.queryPathInfo(storePath);
|
||||
assert(info->references.empty());
|
||||
auto hash = method == ContentAddressMethod::Raw::NixArchive ? info->narHash : ({
|
||||
if (!info->ca || info->ca->method != method)
|
||||
throw Error("path '%s' lacks a CA field", store.printStorePath(storePath));
|
||||
info->ca->hash;
|
||||
});
|
||||
debug(
|
||||
"copied '%s' to '%s' (hash '%s')",
|
||||
path,
|
||||
store.printStorePath(storePath),
|
||||
hash.to_string(HashFormat::SRI, true));
|
||||
return std::make_pair(storePath, hash);
|
||||
}();
|
||||
|
||||
debug(mode == FetchMode::DryRun ? "hashed '%s'" : "copied '%s' to '%s'", path, store.printStorePath(storePath));
|
||||
if (cacheKey)
|
||||
settings.getCache()->upsert(*cacheKey, {{"hash", hash.to_string(HashFormat::SRI, true)}});
|
||||
|
||||
if (cacheKey && mode == FetchMode::Copy)
|
||||
settings.getCache()->upsert(*cacheKey, store, {}, storePath);
|
||||
|
||||
return storePath;
|
||||
return {storePath, hash};
|
||||
}
|
||||
|
||||
} // namespace nix
|
||||
@@ -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)
|
||||
@@ -339,9 +342,10 @@ std::pair<ref<SourceAccessor>, Input> Input::getAccessorUnchecked(const Settings
|
||||
// can reuse the existing nar instead of copying the unpacked
|
||||
// input back into the store on every evaluation.
|
||||
if (accessor->fingerprint) {
|
||||
ContentAddressMethod method = ContentAddressMethod::Raw::NixArchive;
|
||||
auto cacheKey = makeFetchToStoreCacheKey(getName(), *accessor->fingerprint, method, "/");
|
||||
settings.getCache()->upsert(cacheKey, store, {}, storePath);
|
||||
settings.getCache()->upsert(
|
||||
makeSourcePathToHashCacheKey(
|
||||
*accessor->fingerprint, ContentAddressMethod::Raw::NixArchive, CanonPath::root),
|
||||
{{"hash", store.queryPathInfo(storePath)->narHash.to_string(HashFormat::SRI, true)}});
|
||||
}
|
||||
|
||||
accessor->setPathDisplay("«" + to_string() + "»");
|
||||
|
||||
@@ -61,6 +61,11 @@ std::pair<CanonPath, std::optional<std::string>> FilteringSourceAccessor::getFin
|
||||
return next->getFingerprint(prefix / path);
|
||||
}
|
||||
|
||||
void FilteringSourceAccessor::invalidateCache(const CanonPath & path)
|
||||
{
|
||||
next->invalidateCache(prefix / path);
|
||||
}
|
||||
|
||||
void FilteringSourceAccessor::checkAccess(const CanonPath & path)
|
||||
{
|
||||
if (!isAllowed(path))
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
+69
-48
@@ -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"
|
||||
@@ -37,15 +38,16 @@ namespace {
|
||||
// old version of git, which will ignore unrecognized `-c` options.
|
||||
const std::string gitInitialBranch = "__nix_dummy_branch";
|
||||
|
||||
bool isCacheFileWithinTtl(time_t now, const struct stat & st)
|
||||
static bool isCacheFileWithinTtl(const Settings & settings, time_t now, const PosixStat & st)
|
||||
{
|
||||
return st.st_mtime + static_cast<time_t>(settings.tarballTtl) > now;
|
||||
}
|
||||
|
||||
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
|
||||
@@ -105,7 +119,7 @@ bool storeCachedHead(const std::string & actualUrl, bool shallow, const std::str
|
||||
return true;
|
||||
}
|
||||
|
||||
std::optional<std::string> readHeadCached(const std::string & actualUrl, bool shallow)
|
||||
static std::optional<std::string> readHeadCached(const Settings & settings, const std::string & actualUrl, bool shallow)
|
||||
{
|
||||
// Create a cache path to store the branch of the HEAD ref. Append something
|
||||
// in front of the URL to prevent collision with the repository itself.
|
||||
@@ -113,11 +127,11 @@ std::optional<std::string> readHeadCached(const std::string & actualUrl, bool sh
|
||||
std::filesystem::path headRefFile = cacheDir / "HEAD";
|
||||
|
||||
time_t now = time(0);
|
||||
struct stat st;
|
||||
auto st = maybeStat(headRefFile);
|
||||
std::optional<std::string> cachedRef;
|
||||
if (stat(headRefFile.string().c_str(), &st) == 0) {
|
||||
if (st) {
|
||||
cachedRef = readHead(cacheDir);
|
||||
if (cachedRef != std::nullopt && *cachedRef != gitInitialBranch && isCacheFileWithinTtl(now, st)) {
|
||||
if (cachedRef != std::nullopt && *cachedRef != gitInitialBranch && isCacheFileWithinTtl(settings, now, *st)) {
|
||||
debug("using cached HEAD ref '%s' for repo '%s'", *cachedRef, actualUrl);
|
||||
return cachedRef;
|
||||
}
|
||||
@@ -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. */
|
||||
@@ -728,12 +749,12 @@ struct GitInputScheme : InputScheme
|
||||
return revCount;
|
||||
}
|
||||
|
||||
std::string getDefaultRef(const RepoInfo & repoInfo, bool shallow) const
|
||||
std::string getDefaultRef(const Settings & settings, const RepoInfo & repoInfo, bool shallow) const
|
||||
{
|
||||
auto head = std::visit(
|
||||
overloaded{
|
||||
[&](const std::filesystem::path & path) { return GitRepo::openRepo(path, {})->getWorkdirRef(); },
|
||||
[&](const ParsedURL & url) { return readHeadCached(url.to_string(), shallow); }},
|
||||
[&](const ParsedURL & url) { return readHeadCached(settings, url.to_string(), shallow); }},
|
||||
repoInfo.location);
|
||||
if (!head) {
|
||||
warn("could not read HEAD ref from repo at '%s', using 'master'", repoInfo.locationToArg());
|
||||
@@ -783,7 +804,7 @@ struct GitInputScheme : InputScheme
|
||||
|
||||
auto originalRef = input.getRef();
|
||||
bool shallow = getShallowAttr(input);
|
||||
auto ref = originalRef ? *originalRef : getDefaultRef(repoInfo, shallow);
|
||||
auto ref = originalRef ? *originalRef : getDefaultRef(settings, repoInfo, shallow);
|
||||
input.attrs.insert_or_assign("ref", ref);
|
||||
|
||||
std::filesystem::path repoDir;
|
||||
@@ -819,10 +840,10 @@ struct GitInputScheme : InputScheme
|
||||
if (getAllRefsAttr(input)) {
|
||||
doFetch = true;
|
||||
} else {
|
||||
/* If the local ref is older than ‘tarball-ttl’ seconds, do a
|
||||
/* If the local ref is older than 'tarball-ttl' seconds, do a
|
||||
git fetch to update the local ref to the remote ref. */
|
||||
struct stat st;
|
||||
doFetch = stat(localRefFile.string().c_str(), &st) != 0 || !isCacheFileWithinTtl(now, st);
|
||||
auto st = maybeStat(localRefFile);
|
||||
doFetch = !st || !isCacheFileWithinTtl(settings, now, *st);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -129,6 +129,25 @@ struct Settings : public Config
|
||||
true,
|
||||
Xp::Flakes};
|
||||
|
||||
Setting<unsigned int> tarballTtl{
|
||||
this,
|
||||
60 * 60,
|
||||
"tarball-ttl",
|
||||
R"(
|
||||
The number of seconds a downloaded tarball is considered fresh. If
|
||||
the cached tarball is stale, Nix checks whether it is still up
|
||||
to date using the ETag header. Nix downloads a new version if
|
||||
the ETag header is unsupported, or the cached ETag doesn't match.
|
||||
|
||||
Setting the TTL to `0` forces Nix to always check if the tarball is
|
||||
up to date.
|
||||
|
||||
Nix caches tarballs in `$XDG_CACHE_HOME/nix/tarballs`.
|
||||
|
||||
Files fetched via `NIX_PATH`, `fetchGit`, `fetchMercurial`,
|
||||
`fetchTarball`, and `fetchurl` respect this TTL.
|
||||
)"};
|
||||
|
||||
ref<Cache> getCache() const;
|
||||
|
||||
ref<GitRepo> getTarballCache() const;
|
||||
|
||||
@@ -24,7 +24,17 @@ StorePath fetchToStore(
|
||||
PathFilter * filter = nullptr,
|
||||
RepairFlag repair = NoRepair);
|
||||
|
||||
fetchers::Cache::Key makeFetchToStoreCacheKey(
|
||||
const std::string & name, const std::string & fingerprint, ContentAddressMethod method, const std::string & path);
|
||||
std::pair<StorePath, Hash> fetchToStore2(
|
||||
const fetchers::Settings & settings,
|
||||
Store & store,
|
||||
const SourcePath & path,
|
||||
FetchMode mode,
|
||||
std::string_view name = "source",
|
||||
ContentAddressMethod method = ContentAddressMethod::Raw::NixArchive,
|
||||
PathFilter * filter = nullptr,
|
||||
RepairFlag repair = NoRepair);
|
||||
|
||||
fetchers::Cache::Key
|
||||
makeSourcePathToHashCacheKey(std::string_view fingerprint, ContentAddressMethod method, const CanonPath & path);
|
||||
|
||||
} // namespace nix
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -52,6 +52,8 @@ struct FilteringSourceAccessor : SourceAccessor
|
||||
|
||||
std::pair<CanonPath, std::optional<std::string>> getFingerprint(const CanonPath & path) override;
|
||||
|
||||
void invalidateCache(const CanonPath & path) override;
|
||||
|
||||
/**
|
||||
* Call `makeNotAllowedError` to throw a `RestrictedPathError`
|
||||
* exception if `isAllowed()` returns `false` for `path`.
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "nix/fetchers/fetchers.hh"
|
||||
|
||||
namespace nix::fetchers {
|
||||
|
||||
@@ -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 = {});
|
||||
|
||||
|
||||
+105
-55
@@ -1,5 +1,10 @@
|
||||
#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"
|
||||
#include "nix/store/globals.hh"
|
||||
@@ -9,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 = getEnv();
|
||||
auto env = getEnvOs();
|
||||
// Set HGPLAIN: this means we get consistent output from hg and avoids leakage from a user or system .hgrc.
|
||||
env["HGPLAIN"] = "";
|
||||
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));
|
||||
@@ -144,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 {};
|
||||
}
|
||||
|
||||
@@ -154,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
|
||||
@@ -185,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()));
|
||||
@@ -230,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");
|
||||
|
||||
@@ -281,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);
|
||||
@@ -330,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");
|
||||
|
||||
|
||||
+11
-13
@@ -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());
|
||||
@@ -165,14 +165,12 @@ struct PathInputScheme : InputScheme
|
||||
|
||||
// To prevent `fetchToStore()` copying the path again to Nix
|
||||
// store, pre-create an entry in the fetcher cache.
|
||||
accessor->fingerprint =
|
||||
fmt("path:%s", store.queryPathInfo(*storePath)->narHash.to_string(HashFormat::SRI, true));
|
||||
auto narHash = store.queryPathInfo(*storePath)->narHash.to_string(HashFormat::SRI, true);
|
||||
accessor->fingerprint = fmt("path:%s", narHash);
|
||||
settings.getCache()->upsert(
|
||||
makeFetchToStoreCacheKey(
|
||||
input.getName(), *accessor->fingerprint, ContentAddressMethod::Raw::NixArchive, "/"),
|
||||
store,
|
||||
{},
|
||||
*storePath);
|
||||
makeSourcePathToHashCacheKey(
|
||||
*accessor->fingerprint, ContentAddressMethod::Raw::NixArchive, CanonPath::root),
|
||||
{{"hash", narHash}});
|
||||
|
||||
/* Trust the lastModified value supplied by the user, if
|
||||
any. It's not a "secure" attribute so we don't care. */
|
||||
|
||||
Loaded 100 of 525 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user