Skip to content

[CA-drvs] Existing derivation is rebuilt and conflicts #14107

@timschumi

Description

@timschumi

Describe the bug

Under certain (yet to be determined) conditions, Nix will attempt to rebuild a derivation that already exists in the Nix store, resulting in a conflict and subsequent build error. Whether the derivation (in the case of the following examples file) is listed as a direct member of systemPackages or just as a transitive dependency appears to make a difference.

This issue manifests with certain derivations if the ca-derivations feature is enabled and involved builds are content-addressed.

This issue is not yet fully reduced, mostly looking for pointers on how to box this in.

Steps To Reproduce

  1. Build system derivation with file "excluded" using nixos-rebuild build --flake github:timschumi/nix-config/87dac4b886f2b3c76bb35a075a1b7a2ef18b829d#ctfbox --keep-going. The build succeeds.

  2. Build system derivation with file included using nixos-rebuild build --flake github:timschumi/nix-config/80b85c5a49d5568e5c7bbbf66641930adcd25331#ctfbox --keep-going. file fails to build due to write conflicts into the Nix store and all derivations that depend on file are marked as failed (if they were planned to be built).

Build failure log with `file` as explicit dependency
error: builder for '/nix/store/c3f6wkkf9sglwp0djwhnlana5vd1w31k-file-5.45.drv' failed with exit code 2;
       last 25 log lines:
       > make[1]: Leaving directory '/build/file-5.45/doc'
       > Making check in python
       > make[1]: Entering directory '/build/file-5.45/python'
       > make[1]: Nothing to be done for 'check'.
       > make[1]: Leaving directory '/build/file-5.45/python'
       > make[1]: Entering directory '/build/file-5.45'
       > make[1]: Leaving directory '/build/file-5.45'
       > Running phase: installPhase
       > install flags: -j1 SHELL=/nix/store/xaia5nwnq0gcpjrwfcxlhk24sv37w0sx-bash-5.3p3/bin/bash pkgconfigdir=/nix/store/v16bscvldqz0lnsh17kzw6bjz8k7183f-file-5.45-dev/lib/pkgconfig m4datadir=/nix/store/v16bscvldqz0lnsh17kzw6bjz8k7183f-file-5.45-dev/share/aclocal aclocaldir=/nix/store/v16bscvldqz0lnsh17kzw6bjz8k7183f-file-5.45-dev/share/aclocal install
       > Making install in src
       > make[1]: Entering directory '/build/file-5.45/src'
       > make  install-am
       > make[2]: Entering directory '/build/file-5.45/src'
       > make[3]: Entering directory '/build/file-5.45/src'
       >  /nix/store/4i4x7khmvgcblpr0q344ws9cdzyksrpf-coreutils-9.7/bin/mkdir -p '/nix/store/9b7zzgvl341vsi9pg8yxa32jdrhfqhd9-file-5.45/lib'
       >  /nix/store/xaia5nwnq0gcpjrwfcxlhk24sv37w0sx-bash-5.3p3/bin/bash ../libtool   --mode=install /nix/store/4i4x7khmvgcblpr0q344ws9cdzyksrpf-coreutils-9.7/bin/install -c   libmagic.la '/nix/store/9b7zzgvl341vsi9pg8yxa32jdrhfqhd9-file-5.45/lib'
       > libtool: install: /nix/store/4i4x7khmvgcblpr0q344ws9cdzyksrpf-coreutils-9.7/bin/install -c .libs/libmagic.so.1.0.0 /nix/store/9b7zzgvl341vsi9pg8yxa32jdrhfqhd9-file-5.45/lib/libmagic.so.1.0.0
       > install: cannot remove '/nix/store/9b7zzgvl341vsi9pg8yxa32jdrhfqhd9-file-5.45/lib/libmagic.so.1.0.0': Permission denied
       > make[3]: *** [Makefile:467: install-libLTLIBRARIES] Error 1
       > make[3]: Leaving directory '/build/file-5.45/src'
       > make[2]: *** [Makefile:709: install-am] Error 2
       > make[2]: Leaving directory '/build/file-5.45/src'
       > make[1]: *** [Makefile:702: install] Error 2
       > make[1]: Leaving directory '/build/file-5.45/src'
       > make: *** [Makefile:464: install-recursive] Error 1
       For full logs, run:
         nix log /nix/store/c3f6wkkf9sglwp0djwhnlana5vd1w31k-file-5.45.drv
error: 1 dependencies of derivation '/nix/store/y7f4fvamfb28miq2zrqz21qc787zaq80-home-manager-path.drv' failed to build
error: 1 dependencies of derivation '/nix/store/ng1ya0gnnhxk5fdrdknxkac0fqf2dv6s-activation-script.drv' failed to build
error: 2 dependencies of derivation '/nix/store/i81msncxwsmc127yb158fvq21m4xp6iz-home-manager-generation.drv' failed to build
error: 1 dependencies of derivation '/nix/store/a9sbc1ic2vdp51ppfq5bnavd1487w3jz-unit-home-manager-tim.service.drv' failed to build
error: 1 dependencies of derivation '/nix/store/sjdrbbnix3vy4sj4i2flvv7sh9xb0kx8-system-units.drv' failed to build
error: 1 dependencies of derivation '/nix/store/kx1bkir4r72kfs12ga1vscqw3n9czy1y-etc.drv' failed to build
error: 1 dependencies of derivation '/nix/store/5b1r6h2l3fn4b53ifp6irzwb5vlzvhm2-nixos-system-ctfbox-25.11.20250905.8eb28ad.drv' failed to build

Expected behavior

file should not attempt to be rebuilt, given that it exists on-disk.

Metadata

nix-env (Nix) 2.28.5

Additional context

Checklist


Add 👍 to issues you find important.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions