Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: path is not valid using nix ==2.18.0 #9052

Open
avdv opened this issue Sep 27, 2023 · 48 comments · Fixed by #9081 · May be fixed by #12558
Open

error: path is not valid using nix ==2.18.0 #9052

avdv opened this issue Sep 27, 2023 · 48 comments · Fixed by #9081 · May be fixed by #12558
Assignees
Labels

Comments

@avdv
Copy link
Member

avdv commented Sep 27, 2023

Describe the bug

On CI, we were seeing this problem:

Return code: 1
Error output:
these 2 derivations will be built:
  /nix/store/313azxr6w777rrgz0lcgkp5f0dlm2nvr-posix-toolchain.drv
  /nix/store/qp53d6mv3gs81akp4gv89pk9k7rb76zc-bazel-nixpkgs-posix-toolchain.drv
this path will be fetched (0.09 MiB download, 0.09 MiB unpacked):
  /nix/store/cqam21jchkwyp7k0128g6spcx3mzv6p6-bash-5.1-p16-man
error: path '/nix/store/cqam21jchkwyp7k0128g6spcx3mzv6p6-bash-5.1-p16-man' is not valid

This started to happen around the time when nix 2.18.0 was released. Downgrading to 2.17.0 has resolved this problem.

Steps To Reproduce

  1. clone the daml project: git clone https://github.com/digital-asset/daml.git
  2. cd daml
  3. git checkout 662a4417912df90ba9d9a99817b8ad9703480d06 # not really needed, also fails for commits from 2021
  4. install nix in single-user mode: bash <( curl -sSfL https://nixos.org/nix/install ) --no-daemon
  5. create path_invalid.nix:
with import <nixpkgs> { config = {}; overlays = []; };

let
  # `packages` might include lists, e.g. `stdenv.initialPath` is a list itself,
  # so we need to flatten `packages`.
  flatten = builtins.concatMap (x: if builtins.isList x then x else [x]);
  env = buildEnv {
    name = "posix-toolchain";
    paths = flatten [ stdenv.initialPath ];
  };
  cmd_glob = "${env}/bin/*";
  os = if stdenv.isDarwin then "osx" else "linux";
in

runCommand "bazel-nixpkgs-posix-toolchain"
  { executable = false;
    # Pointless to do this on a remote machine.
    preferLocalBuild = true;
    allowSubstitutes = false;
  }
  ''
    n=$out/nixpkgs_sh_posix.bzl
    mkdir -p "$(dirname "$n")"

    cat >>$n <<EOF
    load("@rules_sh//sh:posix.bzl", "posix", "sh_posix_toolchain")
    discovered = {
    EOF
    for cmd in ${cmd_glob}; do
        if [[ -x $cmd ]]; then
            echo "    \'$(basename $cmd)\': \'$cmd\'," >>$n
        fi
    done
    cat >>$n <<EOF
    }
    def create_posix_toolchain():
        sh_posix_toolchain(
            name = "nixpkgs_sh_posix",
            cmds = {
                cmd: discovered[cmd]
                for cmd in posix.commands
                if cmd in discovered
            }
        )
    EOF
  ''
  1. run:
DADE_NIXPKGS=$(pwd)/nixpkgs-snapshot

if [[ ! -e "$DADE_NIXPKGS" ]]; then
  echo "Loading outdated or missing nixpkgs snapshot..."
  outpath="$(
    nix-store -Q --realise --indirect --add-root "$DADE_NIXPKGS" \
      "$(nix-instantiate -Q --eval "nix/nixpkgs.nix" -A path \
        | sed 's/^\"//;s/\"$//')"
  )"
  echo "Done loading the nixpkgs snapshot to $outpath"
fi
  1. run: NIX_PATH=nixpkgs=$DADE_NIXPKGS nix-build path_invalid.nix

Expected behavior

I would expect the nix-build command to succeed.

nix-env --version output

$ nix-env --version
nix-env (Nix) 2.18.0

Additional context

I have tracked down the error message to

throw InvalidPath("path '%s' is not valid", printStorePath(storePath));

Priorities

Add 👍 to issues you find important.

@avdv avdv added the bug label Sep 27, 2023
@Artturin Artturin added the regression Something doesn't work anymore label Sep 27, 2023
@Artturin
Copy link
Member

I'm on commit edolstra@3494c29 in lazy-trees

parent for that merge is edolstra@7f8c99c
from August 16
and I don't have this issue

Should help with bisecting because 2.17 was released on July 24

git log 7f8c99c70c96bf3685e5cad73b38ede801079177^..2.18.0

Also seen in the #nix-dev:nixos.org room

@trofi said

nix-2.18.0 generates very cryptic errors:

$ nix build --no-link -f nixos system --keep-going
error: path '/nix/store/0mx9wiw18gn44w97jczfg90s2diwz5zp-jq-1.6-dev' is not valid

and warnings:

$ nix build --no-link -f nixos system --keep-going
warning: output lib of input /nix/store/i7vndr6ilzsjdasjvbd9yjvhll365fbd-dconf-0.40.0.drv missing, aborting the resolving
warning: output lib of input /nix/store/i7vndr6ilzsjdasjvbd9yjvhll365fbd-dconf-0.40.0.drv missing, aborting the resolving
warning: output info of input /nix/store/0v0vz7p63cx57wzswsf7m79x1yzmmrd8-findutils-4.9.0.drv missing, aborting the resolving

$ nix build -f. jq.dev made it unstick from error: path '/nix/store/0mx9wiw18gn44w97jczfg90s2diwz5zp-jq-1.6-dev' is not valid.

#4628 was a big PR so could be that

@Ericson2314 @roberth

@garyverhaegen-da
Copy link

If anyone is trying to reproduce, I should add to @avdv's description of the bug that if you happen to already have /nix/store/cqam21jchkwyp7k0128g6spcx3mzv6p6-bash-5.1-p16-man in your Nix store this will succeed, which may make reproduction a bit harder.

I can reliably reproduce the error with Nix 2.18.0 on a new Nix installation, though.

@garyverhaegen-da
Copy link

@Artturin I'm one of the maintainers of the https://github.com/digital-asset/daml repo and I can reliably reproduce the bug on 2.18.0 and can confirm it does not appear in with 2.17.0. Are there reasonably-easy-to-follow instructions on how to install arbitrary Nix commits instead of released versions? If so I could help with bisecting.

@avdv
Copy link
Member Author

avdv commented Sep 27, 2023

@Artturin spot on! (oh, it's not from PR #4628, but seems related) It is from #8829

5e3986f59cb58f48186a49dcec7aa317b4787522 is the first bad commit
commit 5e3986f59cb58f48186a49dcec7aa317b4787522
Author: John Ericson <John.Ericson@Obsidian.Systems>
Date:   Mon Mar 8 16:24:49 2021 -0500

    Adapt scheduler to work with dynamic derivations
    
    To avoid dealing with an optional `drvPath` (because we might not know
    it yet) everywhere, make an `CreateDerivationAndRealiseGoal`. This goal
    just builds/substitutes the derivation file, and then kicks of a build
    for that obtained derivation; in other words it does the chaining of
    goals when the drv file is missing (as can already be the case) or
    computed (new case).
    
    This also means the `getDerivation` state can be removed from
    `DerivationGoal`, which makes the `BasicDerivation` / in memory case and
    `Derivation` / drv file file case closer together.
    
    The map type is factored out for clarity, and because we will soon hvae
    a second use for it (`Derivation` itself).
    
    Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>

 .../build/create-derivation-and-realise-goal.cc    | 157 +++++++++++++++++++++
 .../build/create-derivation-and-realise-goal.hh    |  96 +++++++++++++
 src/libstore/build/derivation-goal.cc              |  22 +--
 src/libstore/build/derivation-goal.hh              |  15 +-
 src/libstore/build/drv-output-substitution-goal.hh |   4 +-
 src/libstore/build/entry-points.cc                 |  11 +-
 src/libstore/build/goal.cc                         |   2 +-
 src/libstore/build/goal.hh                         |  22 ++-
 src/libstore/build/substitution-goal.hh            |   4 +-
 src/libstore/build/worker.cc                       | 114 ++++++++++++---
 src/libstore/build/worker.hh                       |  22 +++
 src/libstore/derived-path-map.cc                   |  33 +++++
 src/libstore/derived-path-map.hh                   |  73 ++++++++++
 tests/dyn-drv/build-built-drv.sh                   |   4 +-
 14 files changed, 523 insertions(+), 56 deletions(-)
 create mode 100644 src/libstore/build/create-derivation-and-realise-goal.cc
 create mode 100644 src/libstore/build/create-derivation-and-realise-goal.hh
 create mode 100644 src/libstore/derived-path-map.cc
 create mode 100644 src/libstore/derived-path-map.hh

@andrevmatos
Copy link
Member

This started affecting my nixos-unstable-small system flake after a nix-collect-garbage and nix flake update, without anything apparent causing it, with a slightly different derivation:

error: path '/nix/store/phscma235mfx30d1dncgizls1rlmh7iz-bash-5.2-p15-dev' is not valid

@qbit
Copy link

qbit commented Sep 28, 2023

I was able to get things back up and running nix-store --repair-path /nix/store/...... on the various broken paths and switching nix.package to be pkgs.nixVersions.nix_2_17.

@andrevmatos
Copy link
Member

I can confirm nix-store --repair-path on the path above did work around the issue for me (until next gc?); I didn't need to downgrade to nix_2_17, at least while the path is available.

@qbit
Copy link

qbit commented Sep 28, 2023

I can confirm nix-store --repair-path on the path above did work around the issue for me (until next gc?); I didn't need to downgrade to nix_2_17, at least while the path is available.

Re the path, are you sure the next one isn't a different bash output? At first I thought it didn't work because there was -info and -man variations.

@CobaltCause
Copy link

FWIW, I ran into this with the following store paths:

  • /nix/store/r0q1ch9gl2f9xkxclg68b7s3qq39lvk1-bash-5.2-p15-man (both systems)
  • /nix/store/af5cs1nfdr1rhghy3vvdmz9jsypgksh7-bash-5.2-p15-doc (both systems)
  • /nix/store/04skl91v03vl3030h3ak3hxafn2v9lzf-kmod-30-dev (.#nixosConfigurations.worky only)

while upgrading with this commit https://or.computer.surgery/charles/dotfiles/-/commit/7d406812e27e254486ec7a8a01d28bc20eee7694.

My workaround was to run nix copy --from https://cache.nixos.org $affected_store_path for each one until nixos-rebuild worked correctly.

@thufschmitt thufschmitt moved this to 🏁 Assigned in Nix team Sep 29, 2023
@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/getting-error-path-not-valid-for-gnugrep-3-11-on-nixos-rebuild-switch/33642/4

alapshin added a commit to alapshin/nixos-config that referenced this issue Sep 30, 2023

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/amd-rx-7700-xt-not-being-detected-properly/33683/5

K900 pushed a commit to NixOS/nixpkgs that referenced this issue Oct 1, 2023
This reverts commit 13ec865.

This has caused widespread pain because of NixOS/nix#9052
@Ericson2314
Copy link
Member

Ericson2314 commented Oct 1, 2023

It would be handy if someone had a way to reproduce that worked with --store so I didn't have to reinstall Nix, build all of NixOS, etc.

I will work on this as the issue is assigned to me, but posting this here in case someone already has one.

@Munksgaard
Copy link

I'm seeing the same problem in CI using 2.18.0 (and not locally, using 2.17.0).

Ericson2314 added a commit to obsidiansystems/nix that referenced this issue Oct 2, 2023
This reverts commit 5e3986f. This
un-implements RFC 92 but fixes the critical bug NixOS#9052 which many people
are hitting. This is a decent stop-gap until a minimal reproduction of
that bug is found and a proper fix can be made.

Mostly fixed NixOS#9052, but I would like to leave that issue open until we
have a regression test, so I can then properly fix the bug (unbreaking
RFC 92) later.
Ericson2314 added a commit to obsidiansystems/nix that referenced this issue Oct 2, 2023
This reverts commit 5e3986f. This
un-implements RFC 92 but fixes the critical bug NixOS#9052 which many people
are hitting. This is a decent stop-gap until a minimal reproduction of
that bug is found and a proper fix can be made.

Mostly fixed NixOS#9052, but I would like to leave that issue open until we
have a regression test, so I can then properly fix the bug (unbreaking
RFC 92) later.
Ericson2314 added a commit to obsidiansystems/nix that referenced this issue Oct 2, 2023
This reverts commit 5e3986f. This
un-implements RFC 92 but fixes the critical bug NixOS#9052 which many people
are hitting. This is a decent stop-gap until a minimal reproduction of
that bug is found and a proper fix can be made.

Mostly fixed NixOS#9052, but I would like to leave that issue open until we
have a regression test, so I can then properly fix the bug (unbreaking
RFC 92) later.
Ericson2314 added a commit to obsidiansystems/nix that referenced this issue Oct 2, 2023
This reverts commit 5e3986f. This
un-implements RFC 92 but fixes the critical bug NixOS#9052 which many people
are hitting. This is a decent stop-gap until a minimal reproduction of
that bug is found and a proper fix can be made.

Mostly fixed NixOS#9052, but I would like to leave that issue open until we
have a regression test, so I can then properly fix the bug (unbreaking
RFC 92) later.
Ericson2314 added a commit to obsidiansystems/nix that referenced this issue Oct 2, 2023
This reverts commit 5e3986f. This
un-implements RFC 92 but fixes the critical bug NixOS#9052 which many people
are hitting. This is a decent stop-gap until a minimal reproduction of
that bug is found and a proper fix can be made.

Mostly fixed NixOS#9052, but I would like to leave that issue open until we
have a regression test, so I can then properly fix the bug (unbreaking
RFC 92) later.
@a-h
Copy link
Contributor

a-h commented Jan 10, 2024

I have another reproduction of what I believe to be this issue, on Nix 2.18.1.

In https://github.com/a-h/nix-copy I've got scripts to set up two NixOS VMs - source and target based on the same configuration.nix. The configuration.nix enables SSH, and sets a password for the user adrian of password: https://github.com/a-h/nix-copy/blob/main/configuration.nix

The flake.nix in the repo has a devShell which includes libvirt for running the virtual machines, the xc tool I use to simplify running complex commands, and the virsh-json tool I wrote to parse tables that are output from virsh commands and turn them into JSON.

The first command is xc build-iso which builds an ISO from the configuration.nix.

virt-run-all then runs two copies of the ISO using virt-install. One is called source, and the other is called target.

Once the VMs are stared, the virt-ssh command returns the IP addresses of the source and target machine, then I could run the tests.

Export package to disk

First, I SSH onto the source machine, and copy the hello command to disk:

nix copy --to file://$PWD/hello nixpkgs#hello --extra-experimental-features nix-command --extra-experimental-features flakes

Copy from source to target using scp

Next, I copy the results via SCP to the target machine, which mimics the behaviour of using a USB drive etc.

[adrian@nixos:~]$ scp -r ./hello adrian@192.168.122.182:/home/adrian/hello                                 
The authenticity of host '192.168.122.182 (192.168.122.182)' can't be established.
ED25519 key fingerprint is SHA256:O8ltjoGolRWGEFxQV4dK+RktPvTt347gqV8s/QfKA+0.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.122.182' (ED25519) to the list of known hosts.
(adrian@192.168.122.182) Password: 
ji01n9vinnj22nbrb86nx8a1ssgpilx8.narinfo                                                                                                                                           100%  606   581.0KB/s   00:00    
i93s7xxblavsacpy82zdbn4kplsyq48l.narinfo                                                                                                                                           100%  567     5.6MB/s   00:00    
9y8pmvk8gdwwznmkzxa6pwyah52xy3nk.narinfo                                                                                                                                           100%  659     7.2MB/s   00:00    
ldrslljw4rg026nw06gyrdwl78k77vyq.narinfo                                                                                                                                           100%  513     5.6MB/s   00:00    
zhl06z4lrfrkw5rp0hnjjfrgsclzvxpm.narinfo                                                                                                                                           100%  600     6.7MB/s   00:00    
12116yvlqh0sszlf6ipagkivxgh4ybn15d7qynvl34k87bmwkyv6.nar.xz                                                                                                                        100%   49KB  95.4MB/s   00:00    
168qxfl2rswcwbpvajr43r7s2fxan4lk69kyf7wasffga1ava9g8.nar.xz                                                                                                                        100% 6357KB 100.9MB/s   00:00    
0crc324g4mk9qv2kawr3w0rklvix854m7iarg8z848pibm3sxjfv.nar.xz                                                                                                                        100%   87KB 197.6MB/s   00:00    
1qi9kgysh7rpfnj20zxiys6xg15265ws0sc5kybmw1zdj8asc37j.nar.xz                                                                                                                        100%   50KB 198.3MB/s   00:00    
1rm2gqcly43l1mnd7iwyhslcfxnlg91y5c7y49y8dww1qwl0lsyp.nar.xz                                                                                                                        100%  402KB 366.1MB/s   00:00    
nix-cache-info                                                                                                                                                                     100%   21   206.8KB/s   00:00    

Get the store path on the source machine

With the data copied to the target machine, I can print out the path. For some reason, there's no newline.

[adrian@nixos:~]$ nix path-info nixpkgs#hello --extra-experimental-features nix-command --extra-experimental-features flakes
evaluating derivation 'flake:nixpkgs#hello'/nix/store/zhl06z4lrfrkw5rp0hnjjfrgsclzvxpm-hello-2.12.1

SSH into target machine and import the results of nix copy

Next, I exit the connection with source and SSH into target.

[adrian@nixos:~]$ exit
logout
Connection to 192.168.122.175 closed.
(nix:nix-shell-env) bash-5.2$ ssh adrian@192.168.122.182
(adrian@192.168.122.182) Password: 

Then, I try to run the nix copy operation to add the SCP'd files to the store.

[adrian@nixos:~]$ nix copy --all --no-check-sigs --from file://$PWD/hello --extra-experimental-features nix-command --extra-experimental-features flakes
error: path '/nix/store/ji01n9vinnj22nbrb86nx8a1ssgpilx8-libidn2-2.3.4' is not valid

Got unexpected error

As seen, I got the "error: path '/nix/store/ji01n9vinnj22nbrb86nx8a1ssgpilx8-libidn2-2.3.4' is not valid".

Why does SSH work?

If I log on to source and use ssh as the target, then it works OK:

ssh adrian@192.168.122.175
[adrian@nixos:~]$ nix copy --to ssh-ng://192.168.122.182 nixpkgs#hello --extra-experimental-features nix-command --extra-experimental-features flakes
(adrian@192.168.122.182) Password: 

Then... on the target...

(nix:nix-shell-env) bash-5.2$ ssh adrian@192.168.122.182
(adrian@192.168.122.182) Password: 
Last login: Wed Jan 10 12:57:10 2024 from 192.168.122.1

[adrian@nixos:~]$ nix shell /nix/store/zhl06z4lrfrkw5rp0hnjjfrgsclzvxpm-hello-2.12.1 --extra-experimental-features nix-command --extra-experimental-features flakes

[adrian@nixos:~]$ hello
Hello, world!

So, it's interesting that the nix copy operation seems to work if the target is SSH, but doesn't work if the target is a file path.

Code

https://github.com/a-h/nix-copy

@a-h
Copy link
Contributor

a-h commented Jan 10, 2024

I gave @solidsnakedev's workaround a try to help debug the issue further.

I noticed that it is possible to download from the cache to disk, and restore from disk on the target machine. So, I reproduced the issue, having copied the package from source to target. Running on target, I can't add the files to the store:

[adrian@nixos:~]$ nix copy --all --no-check-sigs --from file://$PWD/hello --extra-experimental-features nix-command --extra-experimental-features flakes                                                             
error: path '/nix/store/ldrslljw4rg026nw06gyrdwl78k77vyq-xgcc-12.3.0-libgcc' is not valid                                                                                                                            

But if I download it from the Nix cache to disk...

[adrian@nixos:~]$ nix copy --from https://cache.nixos.org /nix/store/ldrslljw4rg026nw06gyrdwl78k77vyq-xgcc-12.3.0-libgcc --to file://$PWD/libgcc --extra-experimental-features nix-command                           

Then from disk into the cache...

[adrian@nixos:~]$ nix copy --all --no-check-sigs --from file://$PWD/libgcc --extra-experimental-features nix-command --extra-experimental-features flakes

The operation succeeds:

[adrian@nixos:~]$ nix copy --all --no-check-sigs --from file://$PWD/hello --extra-experimental-features nix-command --extra-experimental-features flakes 

Was the narinfo or NAR file corrupted during transfer?

My first thought was that perhaps the scp operation didn't work, so I compared the narinfo files, and the one received from the source machine was identical to the one downloaded from the Nix cache on the local machine.

adrian@nixos:~]$ cat hello/ldrslljw4rg026nw06gyrdwl78k77vyq.narinfo                                                                                                                                                 
StorePath: /nix/store/ldrslljw4rg026nw06gyrdwl78k77vyq-xgcc-12.3.0-libgcc                                                                                                                                            
URL: nar/1qi9kgysh7rpfnj20zxiys6xg15265ws0sc5kybmw1zdj8asc37j.nar.xz                                                                                                                                                 
Compression: xz                                                                                                                                                                                                      
FileHash: sha256:1qi9kgysh7rpfnj20zxiys6xg15265ws0sc5kybmw1zdj8asc37j                                                                                                                                                
FileSize: 50868                                                                                                                                                                                                      
NarHash: sha256:18agdkqz0vzfxznc4h8ss7ql483lyjzjng185xcrwmdx7x1vc9a8                                                                                                                                                 
NarSize: 142456                                                                                                                                                                                                      
References:                                                                                                                                                                                                          
Deriver: m8hpbqa0vsnl1nr6g1n8bg792qakap68-xgcc-12.3.0.drv                                                                                                                                                            
Sig: cache.nixos.org-1:v+YiK82YiH+LXgSu9bPFbhPH1KYc190XB7Jb1c8TOvOaN8EsvDsDNcmCOxdLgR6YaB9N0LTp3uIa6ctQrdf/DA==                                                                                                      
                                                                                                                                                                                                                     
[adrian@nixos:~]$ cat libgcc/ldrslljw4rg026nw06gyrdwl78k77vyq.narinfo                                                                                                                                                
StorePath: /nix/store/ldrslljw4rg026nw06gyrdwl78k77vyq-xgcc-12.3.0-libgcc                                                                                                                                            
URL: nar/1qi9kgysh7rpfnj20zxiys6xg15265ws0sc5kybmw1zdj8asc37j.nar.xz                                                                                                                                                 
Compression: xz                                                                                                                                                                                                      
FileHash: sha256:1qi9kgysh7rpfnj20zxiys6xg15265ws0sc5kybmw1zdj8asc37j                                                                                                                                                
FileSize: 50868                                                                                                                                                                                                      
NarHash: sha256:18agdkqz0vzfxznc4h8ss7ql483lyjzjng185xcrwmdx7x1vc9a8                                                                                                                                                 
NarSize: 142456                                                                                                                                                                                                      
References:                                                                                                                                                                                                          
Deriver: m8hpbqa0vsnl1nr6g1n8bg792qakap68-xgcc-12.3.0.drv                                                                                                                                                            
Sig: cache.nixos.org-1:v+YiK82YiH+LXgSu9bPFbhPH1KYc190XB7Jb1c8TOvOaN8EsvDsDNcmCOxdLgR6YaB9N0LTp3uIa6ctQrdf/DA==           

In addition, the NAR files themselves are identical.

[adrian@nixos:~]$ sha256sum libgcc/nar/1qi9kgysh7rpfnj20zxiys6xg15265ws0sc5kybmw1zdj8asc37j.nar.xz                                                                                                                   
f20ca61592ed075e979f8569a07931a284d78df6b17f20a475371fa8fd9b29e2  libgcc/nar/1qi9kgysh7rpfnj20zxiys6xg15265ws0sc5kybmw1zdj8asc37j.nar.xz                                                                             
                                                                                                                                                                                                                     
[adrian@nixos:~]$ sha256sum hello/nar/1qi9kgysh7rpfnj20zxiys6xg15265ws0sc5kybmw1zdj8asc37j.nar.xz                                                                                                                    
f20ca61592ed075e979f8569a07931a284d78df6b17f20a475371fa8fd9b29e2  hello/nar/1qi9kgysh7rpfnj20zxiys6xg15265ws0sc5kybmw1zdj8asc37j.nar.xz

I think this shows that the problem doesn't seem to be caused by the download or transfer of the archives.

So what else could be causing this?

@a-h
Copy link
Contributor

a-h commented Jan 11, 2024

Reproducible bisection

Now that I have a reproducible testing process, I noticed that the nixpkgs version was changing between each run, and that I was using a recent commit, so I tried with nixpkgs/23.11 and it worked perfectly well, whereas with the latest unstable nixpkgs it doesn't.

[adrian@nixos:~]$ nix copy --to file://$PWD/hello github:NixOS/nixpkgs/23.11#hello --extra-experimental-features nix-command --extra-experimental-features flakes

Since it was working in 23.11, and not in the latest master branch, I decided to hunt it down. I got all the commits since 23.11 on the main branch with git log --oneline | sed '/Release NixOS 23.11/q' and bisected them.

There had been 13,269 commits since the latest, so I had to do 13 checks to find the exact commit when it started to break.

# 76090aacf4b6 - broken
# 7b2399a63c27 - working
# 140f2db977a0 - working
# 468a6bab44bf - broken
# 44f2f5ce5aaf - broken
# f9480bd35d76 - broken
# b122013b2373 - broken
# 0c909de8e6ab - broken
# 5902643e53f2 - broken
# a1e9171ca3c1 - broken
# 73b3a1450f4a - broken
# 67fc0e51da63 - broken
# 5621fb9e2dc5 - working

So I tracked it down to here.

67fc0e51da63	R. Ryantm	Fri Dec 15 05:07:22 2023 +0000	biome: 1.4.0 -> 1.4.1
Broken ^
5621fb9e2dc5	Nikolay Korotkiy	Tue Dec 12 02:04:18 2023 +0400	mosquitto: fix pkg-config files
Working ^

Why on earth would NixOS/nixpkgs@67fc0e51da63 cause a nix copy operation of hello to print error: path '/nix/store/ji01n9vinnj22nbrb86nx8a1ssgpilx8-libidn2-2.3.4' is not valid?

@a-h
Copy link
Contributor

a-h commented Jan 12, 2024

Reproduction in Nix 2.19.2

Since the workaround was apparently to use Nix 2.18.1, and I was able to reproduce the issue in it, I decided to check if it had been fixed in a subsequent version of Nix accidentally.

I updated the reproduction repo to use 2.19.2 in a-h/nix-copy@e855ecb and then created two new virtual machines - 192.168.122.153 (source) and 192.168.122.152 (target).

0 0 /home/adrian-hesketh/github.com/a-h/nix-copy % ssh adrian@192.168.122.153
The authenticity of host '192.168.122.153 (192.168.122.153)' can't be established.
ED25519 key fingerprint is SHA256:5s8NaYrdeH3MZhUKKrExqw44JmKwS+q9/h8cKkoiFtI.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.122.153' (ED25519) to the list of known hosts.
(adrian@192.168.122.153) Password: 

[adrian@nixos:~]$ nix --version
nix (Nix) 2.19.2

[adrian@nixos:~]$ nix copy --to file://$PWD/hello github:NixOS/nixpkgs/67fc0e51da63#hello

[adrian@nixos:~]$ scp -r ./hello/ adrian@192.168.122.152:/home/adrian/hello
The authenticity of host '192.168.122.152 (192.168.122.152)' can't be established.
ED25519 key fingerprint is SHA256:92Q0nHQWTKDy/DdFcCjKgOo8rDSlRNwjAyaoG47a00g.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.122.152' (ED25519) to the list of known hosts.
(adrian@192.168.122.152) Password: 
1rm2gqcly43l1mnd7iwyhslcfxnlg91y5c7y49y8dww1qwl0lsyp.nar.xz                                                                                                                        100%  402KB 112.7MB/s   00:00    
12116yvlqh0sszlf6ipagkivxgh4ybn15d7qynvl34k87bmwkyv6.nar.xz                                                                                                                        100%   49KB 179.4MB/s   00:00    
0crc324g4mk9qv2kawr3w0rklvix854m7iarg8z848pibm3sxjfv.nar.xz                                                                                                                        100%   87KB 170.6MB/s   00:00    
168qxfl2rswcwbpvajr43r7s2fxan4lk69kyf7wasffga1ava9g8.nar.xz                                                                                                                        100% 6357KB  67.6MB/s   00:00    
1qi9kgysh7rpfnj20zxiys6xg15265ws0sc5kybmw1zdj8asc37j.nar.xz                                                                                                                        100%   50KB 136.2MB/s   00:00    
ldrslljw4rg026nw06gyrdwl78k77vyq.narinfo                                                                                                                                           100%  513     4.5MB/s   00:00    
zhl06z4lrfrkw5rp0hnjjfrgsclzvxpm.narinfo                                                                                                                                           100%  600     5.6MB/s   00:00    
i93s7xxblavsacpy82zdbn4kplsyq48l.narinfo                                                                                                                                           100%  567     5.6MB/s   00:00    
ji01n9vinnj22nbrb86nx8a1ssgpilx8.narinfo                                                                                                                                           100%  606     5.9MB/s   00:00    
nix-cache-info                                                                                                                                                                     100%   21   192.7KB/s   00:00    
9y8pmvk8gdwwznmkzxa6pwyah52xy3nk.narinfo                                                                                                                                           100%  659     7.1MB/s   00:00    

[adrian@nixos:~]$ exit
logout
Connection to 192.168.122.153 closed.
0 0 /home/adrian-hesketh/github.com/a-h/nix-copy % ssh adrian@192.168.122.152
The authenticity of host '192.168.122.152 (192.168.122.152)' can't be established.
ED25519 key fingerprint is SHA256:92Q0nHQWTKDy/DdFcCjKgOo8rDSlRNwjAyaoG47a00g.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.122.152' (ED25519) to the list of known hosts.
(adrian@192.168.122.152) Password: 

[adrian@nixos:~]$ nix copy --all --no-check-sigs --from file://$PWD/hello
error: path '/nix/store/ji01n9vinnj22nbrb86nx8a1ssgpilx8-libidn2-2.3.4' is not valid

[adrian@nixos:~]$ nix --version
nix (Nix) 2.19.2

[adrian@nixos:~]$ 

@a-h
Copy link
Contributor

a-h commented Jan 12, 2024

@roberth - I would appreciate your thoughts on how to proceed. @'ing you because it says to in your profile. 😁

  • I can reproduce the issue on brand new NixOS VMs (see https://github.com/a-h/nix-copy for full code)
  • I've tested it using the latest Nix CLI (2.19.2)
  • I've hunted it down to a specific nixpkgs commit.

But the commit doesn't seem to make sense as the cause - I can't see how a minor change to a Rust package would result in error: path '/nix/store/ji01n9vinnj22nbrb86nx8a1ssgpilx8-libidn2-2.3.4' is not valid

Any ideas?

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/tiny-nixos-virtualbox-appliance/38145/3

@a-h
Copy link
Contributor

a-h commented Jan 15, 2024

Reading through the comments above, I noticed that there was a suggestion that it worked in Nix 2.17, but it doesn't.

[adrian@nixos:~]$ nix --version                
nix (Nix) 2.17.1                               
                                                     
[adrian@nixos:~]$ nix copy --all --verbose --no-check-sigs --from file://$PWD/hello                        
copying 5 paths...                                                                                        
copying path '/nix/store/9y8pmvk8gdwwznmkzxa6pwyah52xy3nk-x' from 'file:///home/adrian/hello'...
copying path '/nix/store/i93s7xxblavsacpy82zdbn4kplsyq48l-x' from 'file:///home/adrian/hello'...
copying path '/nix/store/ji01n9vinnj22nbrb86nx8a1ssgpilx8-x' from 'file:///home/adrian/hello'...
copying path '/nix/store/ldrslljw4rg026nw06gyrdwl78k77vyq-x' from 'file:///home/adrian/hello'...
copying path '/nix/store/zhl06z4lrfrkw5rp0hnjjfrgsclzvxpm-x' from 'file:///home/adrian/hello'...
error: path '/nix/store/ji01n9vinnj22nbrb86nx8a1ssgpilx8-libidn2-2.3.4' is not valid

@a-h
Copy link
Contributor

a-h commented Jan 19, 2024

The Nix copy output does contain everything required to restore the store, but it probably isn't doing it in the right order.

The store that's being copied from the source passes verification.

[adrian@nixos:~]$ nix store verify -vvvvv --store "file://$PWD/hello" --all
querying info about '/nix/store/9y8pmvk8gdwwznmkzxa6pwyah52xy3nk-x' on 'file:///home/adrian/hello'...
querying info about '/nix/store/i93s7xxblavsacpy82zdbn4kplsyq48l-x' on 'file:///home/adrian/hello'...
querying info about '/nix/store/ji01n9vinnj22nbrb86nx8a1ssgpilx8-x' on 'file:///home/adrian/hello'...
querying info about '/nix/store/kg7q3p9zy4q6spr8a41nd8njni8h8ayg-x' on 'file:///home/adrian/hello'...
querying info about '/nix/store/ldrslljw4rg026nw06gyrdwl78k77vyq-x' on 'file:///home/adrian/hello'...
querying info about '/nix/store/zhl06z4lrfrkw5rp0hnjjfrgsclzvxpm-x' on 'file:///home/adrian/hello'...
starting pool of 0 threads
checking '/nix/store/9y8pmvk8gdwwznmkzxa6pwyah52xy3nk-glibc-2.38-27'...
querying info about '/nix/store/9y8pmvk8gdwwznmkzxa6pwyah52xy3nk-glibc-2.38-27' on 'file:///home/adrian/hello'...
checking '/nix/store/i93s7xxblavsacpy82zdbn4kplsyq48l-libunistring-1.1'...
querying info about '/nix/store/i93s7xxblavsacpy82zdbn4kplsyq48l-libunistring-1.1' on 'file:///home/adrian/hello'...
checking '/nix/store/ji01n9vinnj22nbrb86nx8a1ssgpilx8-libidn2-2.3.4'...
querying info about '/nix/store/ji01n9vinnj22nbrb86nx8a1ssgpilx8-libidn2-2.3.4' on 'file:///home/adrian/hello'...
checking '/nix/store/kg7q3p9zy4q6spr8a41nd8njni8h8ayg-source'...
querying info about '/nix/store/kg7q3p9zy4q6spr8a41nd8njni8h8ayg-source' on 'file:///home/adrian/hello'...
checking '/nix/store/ldrslljw4rg026nw06gyrdwl78k77vyq-xgcc-12.3.0-libgcc'...
querying info about '/nix/store/ldrslljw4rg026nw06gyrdwl78k77vyq-xgcc-12.3.0-libgcc' on 'file:///home/adrian/hello'...
checking '/nix/store/zhl06z4lrfrkw5rp0hnjjfrgsclzvxpm-hello-2.12.1'...
querying info about '/nix/store/zhl06z4lrfrkw5rp0hnjjfrgsclzvxpm-hello-2.12.1' on 'file:///home/adrian/hello'...

And, the hello check passes:

nix store verify --store "file://$PWD/hello" /nix/store/zhl06z4lrfrkw5rp0hnjjfrgsclzvxpm-hello-2.12.1

Including recursively.

[adrian@nixos:~]$ nix store verify -vvvvv --recursive --store "file://$PWD/hello" /nix/store/zhl06z4lrfrkw5rp0hnjjfrgsclzvxpm-hello-2.12.1
querying info about missing paths...
starting pool of 24 threads
querying info about '/nix/store/zhl06z4lrfrkw5rp0hnjjfrgsclzvxpm-hello-2.12.1' on 'file:///home/adrian/hello'...
querying info about '/nix/store/9y8pmvk8gdwwznmkzxa6pwyah52xy3nk-glibc-2.38-27' on 'file:///home/adrian/hello'...
querying info about '/nix/store/ji01n9vinnj22nbrb86nx8a1ssgpilx8-libidn2-2.3.4' on 'file:///home/adrian/hello'...
querying info about '/nix/store/i93s7xxblavsacpy82zdbn4kplsyq48l-libunistring-1.1' on 'file:///home/adrian/hello'...
querying info about '/nix/store/ldrslljw4rg026nw06gyrdwl78k77vyq-xgcc-12.3.0-libgcc' on 'file:///home/adrian/hello'...
starting pool of 0 threads
checking '/nix/store/i93s7xxblavsacpy82zdbn4kplsyq48l-libunistring-1.1'...
checking '/nix/store/ji01n9vinnj22nbrb86nx8a1ssgpilx8-libidn2-2.3.4'...
checking '/nix/store/ldrslljw4rg026nw06gyrdwl78k77vyq-xgcc-12.3.0-libgcc'...
checking '/nix/store/9y8pmvk8gdwwznmkzxa6pwyah52xy3nk-glibc-2.38-27'...
checking '/nix/store/zhl06z4lrfrkw5rp0hnjjfrgsclzvxpm-hello-2.12.1'...

Here's the graph of packages produced by nix-store -q --graph /nix/store/zhl06z4lrfrkw5rp0hnjjfrgsclzvxpm-hello-2.12.1/bin/hello:

image

From the graph, it's clear that the order of installation must be libunistring-1.1, then libidn2-2.3.4 and xgcc-12.3.0-libgcc can happen at the same time, followed by glibc-2.38-27, and then finally hello-2.12.1.

This is exactly the checking order I see in the logs above. However, nix copy doesn't do the same order.

[adrian@nixos:~]$ nix copy -vvvvv --all --no-check-sigs --from file://$PWD/hello                          
performing daemon worker op: 31                                                                                                                                                                                      
copying 5 paths...                                                                                        
querying info about '/nix/store/9y8pmvk8gdwwznmkzxa6pwyah52xy3nk-glibc-2.38-27' on 'file:///home/adrian/hello'...     
querying info about '/nix/store/i93s7xxblavsacpy82zdbn4kplsyq48l-libunistring-1.1' on 'file:///home/adrian/hello'...                                                                                                                
querying info about '/nix/store/ji01n9vinnj22nbrb86nx8a1ssgpilx8-libidn2-2.3.4' on 'file:///home/adrian/hello'...                                                                                                                
querying info about '/nix/store/ldrslljw4rg026nw06gyrdwl78k77vyq-xgcc-12.3.0-libgcc' on 'file:///home/adrian/hello'...                                                                                                                
querying info about '/nix/store/zhl06z4lrfrkw5rp0hnjjfrgsclzvxpm-hello-2.12.1' on 'file:///home/adrian/hello'...     
copying path '/nix/store/9y8pmvk8gdwwznmkzxa6pwyah52xy3nk-glibc-2.38-27' from 'file:///home/adrian/hello'...                                                                                                                     
performing daemon worker op: 44                                                                                                                                                                                      
acquiring write lock on '/nix/var/nix/temproots/3145'                                                                                                                                                                
locking path '/nix/store/9y8pmvk8gdwwznmkzxa6pwyah52xy3nk-glibc-2.38-27'                                  
lock acquired on '/nix/store/9y8pmvk8gdwwznmkzxa6pwyah52xy3nk-glibc-2.38-27.lock'                                                                                                                                    
copying path '/nix/store/i93s7xxblavsacpy82zdbn4kplsyq48l-libunistring-1.1' from 'file:///home/adrian/hello'...                                                                                                                     
lock released on '/nix/store/9y8pmvk8gdwwznmkzxa6pwyah52xy3nk-glibc-2.38-27.lock'                         
copying path '/nix/store/ji01n9vinnj22nbrb86nx8a1ssgpilx8-libidn2-2.3.4' from 'file:///home/adrian/hello'...                                                                                                                     
copying path '/nix/store/ldrslljw4rg026nw06gyrdwl78k77vyq-xgcc-12.3.0-libgcc' from 'file:///home/adrian/hello'...                                                                                                                     
copying path '/nix/store/zhl06z4lrfrkw5rp0hnjjfrgsclzvxpm-hello-2.12.1' from 'file:///home/adrian/hello'...          
error: path '/nix/store/ji01n9vinnj22nbrb86nx8a1ssgpilx8-libidn2-2.3.4' is not valid 

The original logs aren't very helpful, because instead of zhl06z4lrfrkw5rp0hnjjfrgsclzvxpm-hello-2.12.1 they have zhl06z4lrfrkw5rp0hnjjfrgsclzvxpm-x, so I did some text edits to the logs above to add the package name instead of -x.

I don't know what it's supposed to be doing, but it looks like it's releasing the glibc lock too early to me. Shouldn't it be holding the lock until all dependencies of glibc (are copied, i.e. libunistring-1.1, libidn2-2.3.4 and xgcc-12.3.0-libgcc)?

Reading through

nix/src/libstore/store-api.cc

Lines 1087 to 1169 in e6e160a

std::map<StorePath, StorePath> copyPaths(
Store & srcStore,
Store & dstStore,
const StorePathSet & storePaths,
RepairFlag repair,
CheckSigsFlag checkSigs,
SubstituteFlag substitute)
{
auto valid = dstStore.queryValidPaths(storePaths, substitute);
StorePathSet missing;
for (auto & path : storePaths)
if (!valid.count(path)) missing.insert(path);
Activity act(*logger, lvlInfo, actCopyPaths, fmt("copying %d paths", missing.size()));
// In the general case, `addMultipleToStore` requires a sorted list of
// store paths to add, so sort them right now
auto sortedMissing = srcStore.topoSortPaths(missing);
std::reverse(sortedMissing.begin(), sortedMissing.end());
std::map<StorePath, StorePath> pathsMap;
for (auto & path : storePaths)
pathsMap.insert_or_assign(path, path);
Store::PathsSource pathsToCopy;
auto computeStorePathForDst = [&](const ValidPathInfo & currentPathInfo) -> StorePath {
auto storePathForSrc = currentPathInfo.path;
auto storePathForDst = storePathForSrc;
if (currentPathInfo.ca && currentPathInfo.references.empty()) {
storePathForDst = dstStore.makeFixedOutputPathFromCA(
currentPathInfo.path.name(),
currentPathInfo.contentAddressWithReferences().value());
if (dstStore.storeDir == srcStore.storeDir)
assert(storePathForDst == storePathForSrc);
if (storePathForDst != storePathForSrc)
debug("replaced path '%s' to '%s' for substituter '%s'",
srcStore.printStorePath(storePathForSrc),
dstStore.printStorePath(storePathForDst),
dstStore.getUri());
}
return storePathForDst;
};
// total is accessed by each copy, which are each handled in separate threads
std::atomic<uint64_t> total = 0;
for (auto & missingPath : sortedMissing) {
auto info = srcStore.queryPathInfo(missingPath);
auto storePathForDst = computeStorePathForDst(*info);
pathsMap.insert_or_assign(missingPath, storePathForDst);
ValidPathInfo infoForDst = *info;
infoForDst.path = storePathForDst;
auto source = sinkToSource([&](Sink & sink) {
// We can reasonably assume that the copy will happen whenever we
// read the path, so log something about that at that point
auto srcUri = srcStore.getUri();
auto dstUri = dstStore.getUri();
auto storePathS = srcStore.printStorePath(missingPath);
Activity act(*logger, lvlInfo, actCopyPath,
makeCopyPathMessage(srcUri, dstUri, storePathS),
{storePathS, srcUri, dstUri});
PushActivity pact(act.id);
LambdaSink progressSink([&](std::string_view data) {
total += data.size();
act.progress(total, info->narSize);
});
TeeSink tee { sink, progressSink };
srcStore.narFromPath(missingPath, tee);
});
pathsToCopy.push_back(std::pair{infoForDst, std::move(source)});
}
dstStore.addMultipleToStore(pathsToCopy, act, repair, checkSigs);
return pathsMap;
}
, it says it is doing a toplogical sort, but the copy operation looks like it's working through the alphabetic ordering of the paths, instead of following the dependency graph order (as the recursive verification does).

Does that help at all?

@a-h
Copy link
Contributor

a-h commented Jan 22, 2024

Since all of the paths are actually available on disk, you can copy them one at a time with a shell script without having to go to the Internet to fetch them again with this (assumes nix-export is the folder containing the results of nix copy to a filesystem):

for x in `grep StorePath nix-export/*.narinfo | awk '{print $2}'`; do nix copy $x --from file://$PWD/nix-export/ --offline; done

@thufschmitt thufschmitt removed release-blocker regression Something doesn't work anymore labels Feb 16, 2024
Ericson2314 added a commit that referenced this issue Mar 22, 2024
This fixes dynamic derivations, reverting #9081. #9052 However will be
reintroduced unless this is modified somehow.

This reverts commit 8440afb.
Ericson2314 added a commit that referenced this issue Oct 11, 2024
This fixes dynamic derivations, reverting #9081. #9052 However will be
reintroduced unless this is modified somehow.

This reverts commit 8440afb.
@TheColorman
Copy link

Just had the same issue with nix 2.24.9, and I can confirm that the issue was the copy order. Manually recursively specifying the problematic path as the only store path to copy worked for me.

Ericson2314 added a commit that referenced this issue Feb 1, 2025
This fixes dynamic derivations, reverting #9081. #9052 However will be
reintroduced unless this is modified somehow.

This reverts commit 8440afb.
Ericson2314 added a commit that referenced this issue Feb 2, 2025
This fixes dynamic derivations, reverting #9081.

I believe that this time around, #9052 is fixed. When I first rebased
this, tests were failing (which wasn't the case before). The cause of
those test failures were due to the crude job in which the outer goal
tried to exit with the inner goal's status.

Now, that error handling has been reworked to be more faithful. The exit
exit status and exception of the inner goal is returned by the outer
goal. The exception was what was causing the test failures, but I
believe it was not having the right error code (there is more than one
for failure) that caused #9081.

The only cost of doing things the "right way" was that I had to
introduce a hacky `preserveException` boolean. I don't like this, but,
then again, none of us like anything about how the scheduler works.
Issue #11927 is still there to clean everything up, subsuming the need
for any `preserveException` because I doubt we will be fishing
information out of state machines like this at all.

This reverts commit 8440afb.
Ericson2314 added a commit that referenced this issue Feb 2, 2025
This fixes dynamic derivations, reverting #9081.

I believe that this time around, #9052 is fixed. When I first rebased
this, tests were failing (which wasn't the case before). The cause of
those test failures were due to the crude job in which the outer goal
tried to exit with the inner goal's status.

Now, that error handling has been reworked to be more faithful. The exit
exit status and exception of the inner goal is returned by the outer
goal. The exception was what was causing the test failures, but I
believe it was not having the right error code (there is more than one
for failure) that caused #9081.

The only cost of doing things the "right way" was that I had to
introduce a hacky `preserveException` boolean. I don't like this, but,
then again, none of us like anything about how the scheduler works.
Issue #11927 is still there to clean everything up, subsuming the need
for any `preserveException` because I doubt we will be fishing
information out of state machines like this at all.

This reverts commit 8440afb.
Ericson2314 added a commit that referenced this issue Feb 2, 2025
This fixes dynamic derivations, reverting #9081.

I believe that this time around, #9052 is fixed. When I first rebased
this, tests were failing (which wasn't the case before). The cause of
those test failures were due to the crude job in which the outer goal
tried to exit with the inner goal's status.

Now, that error handling has been reworked to be more faithful. The exit
exit status and exception of the inner goal is returned by the outer
goal. The exception was what was causing the test failures, but I
believe it was not having the right error code (there is more than one
for failure) that caused #9081.

The only cost of doing things the "right way" was that I had to
introduce a hacky `preserveException` boolean. I don't like this, but,
then again, none of us like anything about how the scheduler works.
Issue #11927 is still there to clean everything up, subsuming the need
for any `preserveException` because I doubt we will be fishing
information out of state machines like this at all.

This reverts commit 8440afb.
Ericson2314 added a commit that referenced this issue Feb 4, 2025
This fixes dynamic derivations, reverting #9081.

I believe that this time around, #9052 is fixed. When I first rebased
this, tests were failing (which wasn't the case before). The cause of
those test failures were due to the crude job in which the outer goal
tried to exit with the inner goal's status.

Now, that error handling has been reworked to be more faithful. The exit
exit status and exception of the inner goal is returned by the outer
goal. The exception was what was causing the test failures, but I
believe it was not having the right error code (there is more than one
for failure) that caused #9081.

The only cost of doing things the "right way" was that I had to
introduce a hacky `preserveException` boolean. I don't like this, but,
then again, none of us like anything about how the scheduler works.
Issue #11927 is still there to clean everything up, subsuming the need
for any `preserveException` because I doubt we will be fishing
information out of state machines like this at all.

This reverts commit 8440afb.
Ericson2314 added a commit that referenced this issue Feb 5, 2025
This fixes dynamic derivations, reverting #9081.

I believe that this time around, #9052 is fixed. When I first rebased
this, tests were failing (which wasn't the case before). The cause of
those test failures were due to the crude job in which the outer goal
tried to exit with the inner goal's status.

Now, that error handling has been reworked to be more faithful. The exit
exit status and exception of the inner goal is returned by the outer
goal. The exception was what was causing the test failures, but I
believe it was not having the right error code (there is more than one
for failure) that caused #9081.

The only cost of doing things the "right way" was that I had to
introduce a hacky `preserveException` boolean. I don't like this, but,
then again, none of us like anything about how the scheduler works.
Issue #11927 is still there to clean everything up, subsuming the need
for any `preserveException` because I doubt we will be fishing
information out of state machines like this at all.

This reverts commit 8440afb.

Co-Authored-By: Eelco Dolstra <edolstra@gmail.com>
Ericson2314 added a commit that referenced this issue Feb 5, 2025
This fixes dynamic derivations, reverting #9081.

I believe that this time around, #9052 is fixed. When I first rebased
this, tests were failing (which wasn't the case before). The cause of
those test failures were due to the crude job in which the outer goal
tried to exit with the inner goal's status.

Now, that error handling has been reworked to be more faithful. The exit
exit status and exception of the inner goal is returned by the outer
goal. The exception was what was causing the test failures, but I
believe it was not having the right error code (there is more than one
for failure) that caused #9081.

The only cost of doing things the "right way" was that I had to
introduce a hacky `preserveException` boolean. I don't like this, but,
then again, none of us like anything about how the scheduler works.
Issue #11927 is still there to clean everything up, subsuming the need
for any `preserveException` because I doubt we will be fishing
information out of state machines like this at all.

This reverts commit 8440afb.

Co-Authored-By: Eelco Dolstra <edolstra@gmail.com>
Ericson2314 added a commit to obsidiansystems/nix that referenced this issue Feb 24, 2025
It's hard to reproduce this race condition going forward (e.g. it
depends on the precise order that goals are scheduled, but
https://github.com/roberth/nix-9052 current reproduces it, and this
fixes that.
@Ericson2314 Ericson2314 linked a pull request Feb 24, 2025 that will close this issue
@Ericson2314
Copy link
Member

Ericson2314 commented Feb 24, 2025

We noticed it after we reverted the revert on master, and I think #12558 fixes it.

Ericson2314 added a commit to obsidiansystems/nix that referenced this issue Feb 24, 2025
It's hard to reproduce this race condition going forward (e.g. it
depends on the precise order that goals are scheduled, but
https://github.com/roberth/nix-9052 current reproduces it, and this
fixes that.
@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2025-02-24-nix-team-meeting-minutes-215-216/60920/1

meslubi2021 added a commit to Unity-Nix/nix- that referenced this issue Mar 13, 2025

Partially verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
We cannot verify signatures from co-authors, and some of the co-authors attributed to this commit require their commits to be signed.
* Add FIXME

* Update tests/functional/flakes/symlink-paths.sh

* Add `inputs.self.submodules` flake attribute

This allows a flake to specify that it needs Git submodules to be
enabled (or disabled, if we ever change the default) on the top-level
flake. This requires the input to be refetched, but since the first
fetch is lazy, this shouldn't be expensive.

Currently the only attribute allowed by `inputs.self` is `submodules`,
but more can be added in the future (e.g. a `lazy` attribute to opt in
to lazy tree behaviour).

Fixes NixOS#5312, NixOS#9842.

* Add a test for a flake referencing a flake that has inputs.self

* nix-profile.fish: set --local NIX_LINK

Using `set --local` is better than using `set`/`set --erase`.  `--local`
will preserve any existing `NIX_LINK` value.  And the local variable is
automatically removed for any execution path.

* nix-profile.fish: Look for ca-bundle.crt in $NIX_PROFILES

There seems to be no good reason for `nix-profile.fish` and
`nix-profile-daemon.fish` to differ in how they look for the location of
the `ca-bundle.crt` that might be installed by one of the packages.

As `$NIX_PROFILES` points to user local paths, not checking there is
strictly less useful, it seems?

* Revert "Revert "Adapt scheduler to work with dynamic derivations""

This fixes dynamic derivations, reverting NixOS#9081.

I believe that this time around, NixOS#9052 is fixed. When I first rebased
this, tests were failing (which wasn't the case before). The cause of
those test failures were due to the crude job in which the outer goal
tried to exit with the inner goal's status.

Now, that error handling has been reworked to be more faithful. The exit
exit status and exception of the inner goal is returned by the outer
goal. The exception was what was causing the test failures, but I
believe it was not having the right error code (there is more than one
for failure) that caused NixOS#9081.

The only cost of doing things the "right way" was that I had to
introduce a hacky `preserveException` boolean. I don't like this, but,
then again, none of us like anything about how the scheduler works.
Issue NixOS#11927 is still there to clean everything up, subsuming the need
for any `preserveException` because I doubt we will be fishing
information out of state machines like this at all.

This reverts commit 8440afb.

Co-Authored-By: Eelco Dolstra <edolstra@gmail.com>

* Add BLAKE3 hashing algorithm

This uses the single-threaded C-based routines from libblake3.

This is not optimal performance-wise but should be a good starting point
for nix compatibility with BLAKE3 hashing until a more performant
implementation based on the multi-threaded BLAKE3 routines
(written in Rust) can be developed.

* Add BLAKE3 to documentation

* Parser: Respect the accessor of the source file for relative paths

* Parser: Respect the accessor of the source file for relative paths

Previously we only returned paths in rootFS, which is wrong and only
worked because currently all our source trees are in rootFS.

* pre-commit/check-merge-conflicts-2: fix use outside dev shell

Note that this is just a script that is meant to run outside a
derivation (but also can be called by a derivation builder).
`touch $out` does not belong in it.

`touch $out` worked accidentally in the derivation-based check,
and also in the dev shell, but if pre-commit is invoked without
the dev shell it would fail.

* test: Fix shellcheck by giving git-hashing scripts shebangs

This seems to be the way to do it now, even though I can't run them
without setting at least one env var.
I'll only fix shellcheck for now. Don't shoot the messenger.

It isn't quite clear to me why the previous commit masked this problem,
but I'm glad shellcheck has an effect or more effect now.

* test: Use skipTest instead of exit 0

This way shellcheck is ok with it, and it conveys that a significant
chunk of the test is skipped.

* Set FD_CLOEXEC on sockets created by curl

Curl creates sockets without setting FD_CLOEXEC/SOCK_CLOEXEC, this can
cause connections to remain open forever when using commands like `nix
shell`

This change sets the FD_CLOEXEC flag using a CURLOPT_SOCKOPTFUNCTION
callback.

* Document Store Derivations and Deriving Paths (NixOS#12290)

This is a big step documenting the store layer on its own, separately from the evaluator (and `builtins.derivation`).

Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>

* Rename to "content-address*ing* derivation"

"content-address*ed*" derivation is misleading because all derivations
are *themselves* content-addressed. What may or may not be
content-addressed is not derivation itself, but the *output* of the
derivation.

The outputs are not *part* of the derivation (for then the derivation
wouldn't be complete before we built it) but rather separate entities
produced by the derivation.

"content-adddress*ed*" is not correctly because it can only describe
what the derivation *is*, and that is not what we are trying to do.

"content-address*ing*" is correct because it describes what the
derivation *does* --- it produces content-addressed data.

* Fix possible deref of null git_config

* libfetchers: Drop no longer needed curl dependency

* Misc code cleanups

* Move git-lfs-fetch into its own source file

* getLfsEndpointUrl(): Use our RAII helpers

* Add release note

* smudgeLfs: Use default value

Eventually this should probably become a struct of options.

* Add TODO

* Restore NAR hash assertion

* Remove stray line

* Add release note

* Update src/libstore/unix/build/local-derivation-goal.cc

Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>

* nix flake prefetch: Add --out-link option

This makes `nix flake prefetch` more useful for scripting and prevents
the result from being GC'ed prematurely.

* Only try to chmod /nix/var/nix/profiles/per-user when necessary

Co-authored-by: Eelco Dolstra <edolstra@gmail.com>

* copyPathToStore(): Preserve symlinks

E.g. in a derivation attribute `foo = ./bar`, if ./bar is a symlink,
we should copy the symlink to the store, not its target. This restores
the behaviour of Nix <= 2.19.

* Don't import a symlink

This is a workaround to avoid differing evaluation results between Nix
2.19 and >= 2.20 (NixOS#12449).

* Get rid of `impureOutputHash`

I do not believe there is any problem with computing
`hashDerivationModulo` the normal way with impure derivations.

Conversely, the way this used to work is very suspicious because two
almost-equal derivations that only differ in depending on different
impure derivations could have the same drv hash modulo. That is very
suspicious because there is no reason to think those two different
impure derivations will end up producing the same content-addressed
data!

Co-authored-by: Alain Zscheile <zseri.devel@ytrizja.de>

* lockFlake(): When refetching a locked flake, use the locked ref

Otherwise we may accidentally update a lock when we shouldn't.

Fixes NixOS#12445.

* Formatting

* Add test

* feat: access tokens per repo

* feat: test and document access-token prefix support

* Add `inputs.self.lfs`

* Add release note

* fix: ensure access-token matches are complete

* fix: add comment about longest-possible match

* fix: linting

* doc: recursive-nix: advertise requiredSystemFeatures

It's best we teach users that the "foo" derivation is less than pure in the sense that it cannot be built just on any system, in particular that builders cannot be selected arbitrarily but based on their system-features. The `"recursive-nix"` system-feature is automatically defined by `--extra-experimental-features recursive-nix`

* Merge release notes

* Expose a bunch of things in the Legacy SSH Store for Hydra

* More interesting dynamic derivations example

Co-authored-by: Samuel Ainsworth <skainsworth@gmail.com>

* Introduce `DerivationOptions`

This is a first step towards PR NixOS#10760, and the issues it addresses.
See the Doxygen for details.

Thanks to these changes, we are able to drastically restrict how the
rest of the code-base uses `ParseDerivation`.

Co-Authored-By: HaeNoe <git@haenoe.party>

* Add `SSHMaster::Connection::trySetBufferSize`

It is unused in Nix currently, but will be used in Hydra. This reflects
what Hydra does in NixOS/hydra#1387.

We may probably to use it more widely for better SSH store performance,
but this needs to be subject to more testing before we do that.

* Allow setting `ssh://` pipe size

Exposed for Hydra. We could make it fancier but with (a) new store
settings (b) switch to `ssh-ng://` both in the works, it doesn't seem
worth it.

* getDefaultNixPath(): Don't add symlinks if the target doesn't exist

* resolveLookupPathPath(): Fix caching of negative lookups

This avoids spamming in case the missing search path entry does not
exist (NixOS#12480).

* dep-built-drv-2.sh: Don't fail with "cannot create symlink"

* JSONLogger: Log to a file descriptor instead of another Logger

Logging to another Logger was kind of nonsensical - it was really just
an easy way to get it to write its output to stderr, but that only
works if the underlying logger writes to stderr.

This change is needed to make it easy to log JSON output somewhere
else (like a file or socket).

* Support libgit2 1.9.0

For when the overlay is used with nixos-unstable.
1.9.0 has our patches.

* Use getStandardError()

* Fix a few warnings

* Move code related to NIX_MAN_DIR from libstore to nix-cli

This is a prerequisite to properly fixing man-pages once and
for all [1]. Note that this patch leaves manpages for legacy
commands in a borked state, pending the movement of manpages from
nix-manual to nix-cli [2].

[1]: https://www.github.com/NixOS/nix/issues/12382
[2]: https://www.github.com/NixOS/nix/issues/12382#issuecomment-2663782043

* windows: fix compilation after recent changes

Specifically last few week's merges involving legacy SSH options and
dynamic derivations.

* Restore detailed Nix CLI version

... as intended.

Requirements:
- don't build fresh libraries for each git commit
- have git commit in the CLI

Bug:
- echo ${version} went into the wrong file => use the fact that it's
  a symlink, not just for reading but also for writing.

* Write just ./.version on all components

This way it's easier to get right. See previous commit.

* startDaemon(): Detect if the daemon crashes before creating the socket

This avoids timeouts like those seen in
https://github.com/NixOS/nix/actions/runs/13376958708/job/37358120348?pr=6962.

* Make 'logger' a std::unique_ptr

This prevents it from being leaked (see
bb411e4 for an example of this).

* Fix crash on macOS

* stopProgressBar() -> logger->stop()

* Remove startProgressBar()

* Remove createDefaultLogger()

* tests: Fix installTests

* Don't override default man search paths

By appending a colon to MANPATH NIX_MAN_DIR gets prepended to the
final MANPATH before default search paths.
This makes man still consider default search paths, but prefers
NIX_MAN_DIR (if it exists).

It still makes sense to point NIX_MAN_DIR to a correct location
by moving man pages build from nix-manual.man to nix-cli.man, but
this should fix most common use-cases where nix is installed globally.

* repl: suppress progress bar in printValue()

* packaging: Move layers from dependencies to components

This makes it easier to implement batch overriding for the components.

* packaging: Add overrideAllMesonComponents

* packaging: Add source overriding "methods"

* test: Ignore packaging-overriding check on darwin for now

* packaging: Add patch count to version

* packaging: Make patch count lazier

This makes `nix.version` quicker to evaluate, which should speed up
package listing operations.

If you want an accurate count, use `lib.optionals` in your override
instead of `null` values.

* libstore: fix expected bytes in progress bar

* doc: Fix ccacheStdenvPackages typo

* packaging: Remove dead code

... from nixpkgs, my bad.

* packaging: Restore libgit2 USE_SSH=exec

... when nixpkgs is nixos-unstable or the overlay is used.

* Remove nixfmt override

Closes NixOS#12418
IFD in nixfmt repo

* Move MountedSourceAccessor to libutil

* Remove mounted-source-accessor.hh

* Remove redundant call to canonPath()

The CanonPath constructor already does that.

* Add a storeFS accessor for paths resulting from IFD

Hopefully fixes NixOS#11503.

* Add test

* MountedSourceAccessor: Remove redundant pathExists() method

* Add a UnionSourceAccessor

* Use UnionSourceAccessor to mount the chroot store on top of the real store directory

* UnionSourceAccessor: Don't filter out underlying files of the wrong type

NixOS#12512 (comment)

* Remove sourcePathToStorePath()

It's no longer needed now that all store paths inside the evaluator
are logical rather than real paths.

* In pure eval mode, restrict rootFS to just the Nix store

Note that in pure mode, we don't need to use the union FS even when
using a chroot store, since the user shouldn't have access to the
physical /nix/store.

* Remove unused variable

* Introduce `EvalStore::storePath`

This abstracts over a common case. Good for brevity, and enabling
further experiments.

* Fix dev shell

There was one `inputs.nixFmt` left after 573ffac.

* libfetchers-tests: Add back git-utils.cc

Seems like this got dropped at some point during meson migration, so
put it back in the build system.

Drop all tests for `parseGitUrl`, since that function doesn't exist
and migrating doesn't look sensible because git-lfs stuff seems to use
`ParsedURL`.

* doc: ssl-cert-file leaks into OSX builds

* Fix perl store bindings

When NixOS#9863 converted the `Nix::Store` free functions into member functions, the
implicit `this` argument was not accounted for when iterating over the variable
number of arguments in some functions.

* libexpr: Fix use-after-free of StaticEnv::up

It's not very clear what the ownership model is here, but one thing
is certain: `.up` can't be destroyed before the StaticEnv that refers
to it is.

Changing a non-owning pointer to taking shared ownership of the parent
`StaticEnv` prevents the `.up` from being freed.

I'm not a huge fan of the inverted ownership, where child `StaticEnv`
takes a refcount of the parent, but this seems like the least intrusive
way to fix the use-after-free.

This shouldn't cause any shared_ptr cycles to appear (hopefully).

* tests/functional: Add flake-based regression for debugger use-after-free

This is the simplest reproducer I have. It would be great to find
a repro without flakes, but I guess this should be ok for now.

* Include the Nix version in the title of the manual

This makes it easy to see at a glance what the version of the manual
is, e.g. "Nix 2.27.0 Reference Manual".

* nix flake archive: Skip relative path inputs

Fixes NixOS#12438.

* packaging: Use correct stdenv for x86_64-darwin

* nix flake archive: Recurse into relative path inputs

We can't ignore them entirely, since we do want to archive their
transitive inputs.

Fixes NixOS#12438.

* refact: Rename url -> hostAndPath

https://github.com/NixOS/nix/pull/12465/files#r1955286197

> Perhaps that is a misnomer.

* libstore: fix curl callback function signature

* Fix mingw build

https://hydra.nixos.org/build/291153007

* fix: update work meeting calendar link

* release notes: 2.27.0

* Edit release notes

* Add contributors

* Fix date

* Add more release notes

* Expand manual on derivation outputs

Note, this includes some text adapted from from Eelco's dissertation

* Add host attribute of github/gitlab flakerefs to URL serialization

`GitArchiveInputScheme::toUrl` currently drops the `host` attribute,
creating invalid urls when locking `github:` or `gitlab:` urls pointing to alterative instances and serializing the input back to a url.

```
❯ cat flake.nix
{
  inputs.gnome-2048 = {
    url = "gitlab:GNOME/gnome-2048?host=gitlab.gnome.org";
    flake = false;
  };

  outputs = inputs: {};
}
f1xb57354q79t_jpw5_h79cw0000gq/T/tmp.MOBbzbpT35
❯ nix flake metadata
warning: creating lock file '/private/var/folders/fb/f1xb57354q79t_jpw5_h79cw0000gq/T/tmp.MOBbzbpT35/flake.lock':
• Added input 'gnome-2048':
    'gitlab:GNOME/gnome-2048/70e0e430ca4bf590990433a3abdce6b631d50e6e?narHash=sha256-bya45ug2mDSU4SMn0fSBlZCuPl9y15B12ubKeb2A58s%3D' (2025-02-21)
Resolved URL:  path:/private/var/folders/fb/f1xb57354q79t_jpw5_h79cw0000gq/T/tmp.MOBbzbpT35
Locked URL:    path:/private/var/folders/fb/f1xb57354q79t_jpw5_h79cw0000gq/T/tmp.MOBbzbpT35?lastModified=1740744684&narHash=sha256-nxUL/JiTYbZX2c1XiN/TC6aA1hf%2B1YXsUvhL7ASY2uE%3D
Path:          /nix/store/f4xczpwhdxs8gal1rika1c5bvhyd472l-source
Last modified: 2025-02-28 13:11:24
Inputs:
└───gnome-2048: gitlab:GNOME/gnome-2048/70e0e430ca4bf590990433a3abdce6b631d50e6e?narHash=sha256-bya45ug2mDSU4SMn0fSBlZCuPl9y15B12ubKeb2A58s%3D (2025-02-21 23:18:46)
```

Note the gnome-2048 input url missing the original host query.

The Url after this commit:

```
[...]
Inputs:
└───gnome-2048: gitlab:GNOME/gnome-2048/70e0e430ca4bf590990433a3abdce6b631d50e6e?host=gitlab.gnome.org&narHash=sha256-bya45ug2mDSU4SMn0fSBlZCuPl9y15B12ubKeb2A58s%3D (2025-02-21 23:18:46)
```

* packaging/everything.nix: Use a multi-output derivation

This should fix a few packaging regressions.

`dev` also includes a merged `includes/`, which may be helpful until
inter-component includes are fixed properly.

* .mergify.yml: Add backport 2.27-maintenance entry

* remove fricklerhandwerk from CODEOWNERS

stepping aside as a Nix maintainer:
https://discourse.nixos.org/t/time-to-step-aside/61050

* Revert "Revert "Revert "Adapt scheduler to work with dynamic derivations"""

The bug reappeared after all, and the fix introduced a different bug. I
just reverted on 2.27 first, in NixOS#12576, but upon further introspection
and discussion with @roberth, with preparing for and travelling to
Planet Nix I will not be able to fix it on `master` soon enough for a
revert to not be warranted here in the meantime also.

This reverts commit c985252.

* `SingleDerivedPath` should be const in recursive data structures

* Rework derivation input resolution

I refactored the way that input resolution works in `DerivationGoal`. To
be honest, it is probably unclear to the reader whether this new way is
better or worse. I suppose *intrinsic* motivation, I can say that

- the more structured use of `inputGoal` (a local variable) is better
  than the shotgrun approach with `inputDrvOutputs`

- A virtual `waiteeDone` was a hack, and now it's gone.

However, the *real* motivation of this is not the above things, but that
it is needed for my mammoth refactor fixing NixOS#11897 and NixOS#11928.

It is nice that this step could come first, rather than making that
refactor even bigger.

* manual: Edit

* doc: note that function bindings are accessible in default values

Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>

* packaging: Typo in setVersionLayer / preConfigure

Apparently dead code in our use case, but good to keep nonetheless.
Credit: ztzg in NixOS#12498 (review)

* libstore: curl retry: reset content-encoding and don't use string after move

* progress-bar: Make pause/resume nestable

* repl: Fix value printing corruption

The resume call would get some non-flushed(?) data.
Extending the pause to include the newline makes the complete flush
part of the pause.

* refactor: RAII logger suspension

* repl: Fix :print corruption

See preceding commits.

* libfetchers/git: fix double quoting in error message

* libflake: fix double quoting when updating flakes

* libstore/remote-store: avoid old-style casting for maxConnections

Type-checking works better this way as (type) style casting is too
permissive.

* Fix minor documentation typos

Was reading the store chapter and came across a few small typos
and edits.

* rapidcheck: change to working arbitrary instances

Here we're switching to combinators instead of dereference operator.
It turns out the dereference operator was being executed upon test
setup, meaning that we were only using a only single value for each of
the executions of the property tests! Really not good.

And on Windows, we instead get:

    operator* is not allowed in this context

https://github.com/emil-e/rapidcheck/blob/ff6af6fc683159deb51c543b065eba14dfcf329b/src/gen/detail/GenerationHandler.cpp#L16C31-L16C71

Now a few of the property tests fail, because we're generating cases
which haven't been exercised before.

* coerceToSingleDerivedPathUnchecked: pass through experimental features

This fixes a few of the property tests, now that the property tests
are actually generating arbitrary data - some of that data now
requiring experimental features to function properly.

* DerivedPathTest: disable prop_legacy_round_rip until fixed

* c-api: fix a few memory leaks

* flake: Enable UBSAN for checks

Doing this makes catching non-obvious bugs easier. GHA CI workload is
already a concern and there isn't much benefit in running the tests with
and without sanitizers at the same time, so UBSAN is enabled for default
checks.

This change doesn't affect production builds in any way, but is rather a
step in the direction of improving automated testing during development.

Relates to NixOS#10969.

* build(deps): bump cachix/install-nix-action from 30 to 31

Bumps [cachix/install-nix-action](https://github.com/cachix/install-nix-action) from 30 to 31.
- [Release notes](https://github.com/cachix/install-nix-action/releases)
- [Commits](cachix/install-nix-action@v30...v31)

---
updated-dependencies:
- dependency-name: cachix/install-nix-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* libutil/windows: Finally use the correct constructor for std::wstring

C++ is very intuitive /s [1]. Fixes NixOS#12631.

[1]: https://godbolt.org/z/jMa9GP5sq

* port crash-handler from lix to nix

It was first introduced in https://git.lix.systems/lix-project/lix/commit/19e0ce2c03d8e0baa16998b086665664c420c1df

In Nix we only register the crash handler in main instead of initNix,
because library user may want to use their own crash handler.

Sample output:

Mar 12 08:38:06 eve nix[2303762]: Nix crashed. This is a bug. Please report this at https://github.com/NixOS/nix/issues with the following information included:
Mar 12 08:38:06 eve nix[2303762]: Exception: nix::SysError: error: writing to file: Resource temporarily unavailable
Mar 12 08:38:06 eve nix[2303762]: Stack trace:
Mar 12 08:38:06 eve nix[2303762]:  0# 0x000000000076876A in nix
                                   1# 0x00007FDA40E9F20A in /nix/store/2lhklm5aizx30qbw49acnrrzkj9lbmij-gcc-14-20241116-lib/lib/libstdc++.so.6
                                   2# std::unexpected() in /nix/store/2lhklm5aizx30qbw49acnrrzkj9lbmij-gcc-14-20241116-lib/lib/libstdc++.so.6
                                   3# 0x00007FDA40E9F487 in /nix/store/2lhklm5aizx30qbw49acnrrzkj9lbmij-gcc-14-20241116-lib/lib/libstdc++.so.6
                                   4# nix::writeFull(int, std::basic_string_view<char, std::char_traits<char> >, bool) in /home/joerg/git/nix/inst/lib/libnixutil.so
                                   5# nix::writeLine(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) in /home/joerg/git/nix/inst/lib/libnixutil.so
                                   6# nix::JSONLogger::write(nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> >, void> const&) in /home/joerg/git/nix/inst/lib/libnixutil.so
                                   7# nix::JSONLogger::logEI(nix::ErrorInfo const&) in /home/joerg/git/nix/inst/lib/libnixutil.so
                                   8# nix::Logger::logEI(nix::Verbosity, nix::ErrorInfo) in nix
                                   9# nix::handleExceptions(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::function<void ()>) in /home/joerg/git/nix/inst/lib/libnixmain.so
                                  10# 0x000000000087A563 in nix
                                  11# 0x00007FDA40BD41FE in /nix/store/6q2mknq81cyscjmkv72fpcsvan56qhmg-glibc-2.40-66/lib/libc.so.6
                                  12# __libc_start_main in /nix/store/6q2mknq81cyscjmkv72fpcsvan56qhmg-glibc-2.40-66/lib/libc.so.6
                                  13# 0x00000000006F4DF5 in nix

Co-authored-by: eldritch horrors <pennae@lix.systems>

* Remove use of $NIX_HELD_LOCKS

This variable was once used to communicate already acquired store path
locks between Nix and the build hook, but this hasn't been the case
since 9bcb4d2. So let's get rid of
it.

* libfetchers/git: fix caching head when using shallow clones

the old code was using the wrong cache directory, which lead to a
warning on every nix flake update

Update src/libfetchers/git.cc

* Advanced attributes organize

This is supposed to firstly improve the docs as they are, and secondly
hint at how the core conceptual information ought to be moved to the
store derivation section of the manual.

Co-authored-by: Jörg Thalheim <Mic92@users.noreply.github.com>

* Factor out "last 10 log lines" error message code

This will help avoid duplication later. In particular, the next commit
will not need to duplicate as much.

* Inline `buildDone` from `DerivationGoal` into use sites

The basic idea is that while we have duplicated this function, we now
have one call-site in the local build case, and one call site in the
build hook case. This unlocks big opportunities to specialize each copy,
since they really shouldn't be doing the same things. By the time we are
are done, there should not be much duplication left.

See NixOS#12628 for further info.

* Start simplifying `{Local,}DerivationGoal` cleanup code

Thanks to the previous commit, we can inline all these small callbacks.
In the build-hook case, they were empty, and now they disappear
entirely.

While `LocalDerivationGoal` can be used in the hook case (we use it
based on whether we have a local store, not based on whether we are
using the build hook, a decision which comes later), the previous
commit's inline moved the code into a spot where we know we are cleaning
up after local building, *not* after running the build hook. This allows
for much more simplification.

* Remove dead hook code in `LocalDerivationGoal::tryLocalBuild`

The `assert` above proves that `hook` is not set.

* Avoid pointless mutation

The code that was in between is now gone. We can just set `st` correctly
the first time.

* Remove `privateNetwork` variable from local drv goal

Can just inline its definition, it was immutable.

* Simplify local drv goal a bit more

- `chrootParentDir` can be a local variable instead of a class variable.

- `getChildStatus` can be inlined. Again, we have the `assert(!hook);`
  in the local building case, which makes for a simpler thing inlined.

* Remove `registerOutputs` from drv goal

Easy to inline in one spot, and assert in the other.

* Remove `signRealisation` from drv goal

We can move this method from `LocalStore` to `Store` --- even if we only
want the actual builder to sign things in many cases, there is no reason
to try to enforce this policy by spurious moving the method to a
subclass.

Now, we might technically sign class, but CA derivations is
experimental, and @Ericson2314 is going to revisit all this stuff with
issue NixOS#11896 anyways.

* Do no store timestamps in the build result in the build hook case

The variables are only set by CGroup mechanisms in `killSandbox` in the
local build. In the build hook case, these variables will not be set, so
there is nothing to do.

* Inline the try-catch `BuildError` in the hook case

In the local building case, there is many things which can through
`BuildError`, but in the hook case there is just this one. We can
therefore simplify the code by "cinching" down the logic just to the
spot the error is thrown.

There is other code outside `libstore/build` which also uses
`BuildError`, but I believe those cases are mistakes. The point of
`BuildError` is the narrow technical use-cases of "errors which should
not be fatal with `--keep-going`". Using it outside the
building/scheduling code doesn't really make sense in that regard. It
seems likely that those usages were instead merely because "oh, this
error has something to do with building, so I guess `BuildError` is
better than `Error`".

It is quite likely that I myself used `BuildError` incorrectly as
described above :).

* Simplify hook error status logic

The simplification here is due to a long-standing bug, but it is not
worth fixing the bug at this time. Instead we've finally written up an
issue for the bug, and referenced the issue number in the code.

* Make debug message more precise

* Remove unused parameter to the goal constructor

It has been unused since 37fca66.

* JSONLogger: Acquire a lock to prevent log messages from clobbering each other

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Eelco Dolstra <edolstra@gmail.com>
Co-authored-by: John Ericson <git@JohnEricson.me>
Co-authored-by: Illia Bobyr <illia.bobyr@gmail.com>
Co-authored-by: John Ericson <John.Ericson@Obsidian.Systems>
Co-authored-by: silvanshade <silvanshade@users.noreply.github.com>
Co-authored-by: Robert Hensing <robert@roberthensing.nl>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: MaxHearnden <maxoscarhearnden@gmail.com>
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Aiden Fox Ivey <aiden@aidenfoxivey.com>
Co-authored-by: Sandro Jäckel <sandro.jaeckel@gmail.com>
Co-authored-by: Jörg Thalheim <Mic92@users.noreply.github.com>
Co-authored-by: Alain Zscheile <zseri.devel@ytrizja.de>
Co-authored-by: Thomas Bereknyei <tomberek@gmail.com>
Co-authored-by: Leandro Reina <leandro.reina@ororatech.com>
Co-authored-by: Someone <else@someonex.net>
Co-authored-by: Samuel Ainsworth <skainsworth@gmail.com>
Co-authored-by: HaeNoe <git@haenoe.party>
Co-authored-by: Sergei Zimmerman <145775305+xokdvium@users.noreply.github.com>
Co-authored-by: Brian McKenna <brian@brianmckenna.org>
Co-authored-by: Philipp Otterbein <potterbein@blockstream.com>
Co-authored-by: Ivan Trubach <mr.trubach@icloud.com>
Co-authored-by: Silvan Mosberger <silvan.mosberger@moduscreate.com>
Co-authored-by: Fabian Möller <fabianm88@gmail.com>
Co-authored-by: Yannik Sander <yannik@floxdev.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Co-authored-by: Jörg Thalheim <joerg@thalheim.io>
Co-authored-by: Farid Zakaria <farid.m.zakaria@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jade Lovelace <lix@jade.fyi>
Co-authored-by: eldritch horrors <pennae@lix.systems>
Co-authored-by: Las <me@las.rs>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project