nix icon indicating copy to clipboard operation
nix copied to clipboard

FOD intermediate build artifacts not cleaned up upon hash mismatch

Open winterqt opened this issue 3 years ago • 1 comments

Describe the bug

FOD intermediate build artifacts are not cleaned up upon hash mismatch, leading to... weird things.

Steps To Reproduce

with import <nixpkgs> { };

stdenvNoCC.mkDerivation {
  name = "what";

  outputHashMode = "flat";
  outputHashAlgo = "sha256";
  outputHash = lib.fakeHash;

  buildCommand = "echo abc > $out";
}
$ nix-build what.nix
this derivation will be built:
  /nix/store/pkc3l69dkd68h40pcxkggzl9270qr6z1-what.drv
building '/nix/store/pkc3l69dkd68h40pcxkggzl9270qr6z1-what.drv'...
error: hash mismatch in fixed-output derivation '/nix/store/pkc3l69dkd68h40pcxkggzl9270qr6z1-what.drv':
         specified: sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
            got:    sha256-7eqv8/F3StKIhnN3DG1kCX45G8Ni19b7NJgt3w79GMs=
$ ls /nix/store | rg what
k3h6aiq6z2qsqaifccy0g2mx0mqscs2g-what
pkc3l69dkd68h40pcxkggzl9270qr6z1-what.drv
wl3q8rncvfix0gyb7nm8qi2ivlvm9nqx-what.lock
$ cat /nix/store/k3h6aiq6z2qsqaifccy0g2mx0mqscs2g-what
abc
$ nix show-derivation /nix/store/k3h6aiq6z2qsqaifccy0g2mx0mqscs2g-what
error: '/nix/store/k3h6aiq6z2qsqaifccy0g2mx0mqscs2g-what' does not have a known deriver

For posterity, here's /nix/store/pkc3l69dkd68h40pcxkggzl9270qr6z1-what.drv:

{
  "/nix/store/pkc3l69dkd68h40pcxkggzl9270qr6z1-what.drv": {
    "outputs": {
      "out": {
        "path": "/nix/store/wl3q8rncvfix0gyb7nm8qi2ivlvm9nqx-what",
        "hashAlgo": "sha256",
        "hash": "0000000000000000000000000000000000000000000000000000000000000000"
      }
    },
    "inputSrcs": [
      "/nix/store/9krlzvny65gdc8s7kpb6lkx8cd02c25b-default-builder.sh"
    ],
    "inputDrvs": {
      "/nix/store/74k43h4adz4p4qkiwg21jmbj75xw6h8x-stdenv-darwin.drv": [
        "out"
      ],
      "/nix/store/bx7ms8yb9crlsp7k0r5xghr9ckqbm2n3-bash-5.1-p16.drv": [
        "out"
      ]
    },
    "system": "aarch64-darwin",
    "builder": "/nix/store/kdakh3hx6mxh45jqpcynz1lp2y3f82yp-bash-5.1-p16/bin/bash",
    "args": [
      "-e",
      "/nix/store/9krlzvny65gdc8s7kpb6lkx8cd02c25b-default-builder.sh"
    ],
    "env": {
      "__darwinAllowLocalNetworking": "",
      "__impureHostDeps": "/bin/sh /usr/lib/libSystem.B.dylib /usr/lib/system/libunc.dylib /dev/zero /dev/random /dev/urandom /bin/sh",
      "__propagatedImpureHostDeps": "",
      "__propagatedSandboxProfile": "",
      "__sandboxProfile": "",
      "buildCommand": "echo abc > $out",
      "buildInputs": "",
      "builder": "/nix/store/kdakh3hx6mxh45jqpcynz1lp2y3f82yp-bash-5.1-p16/bin/bash",
      "cmakeFlags": "",
      "configureFlags": "",
      "depsBuildBuild": "",
      "depsBuildBuildPropagated": "",
      "depsBuildTarget": "",
      "depsBuildTargetPropagated": "",
      "depsHostHost": "",
      "depsHostHostPropagated": "",
      "depsTargetTarget": "",
      "depsTargetTargetPropagated": "",
      "doCheck": "",
      "doInstallCheck": "",
      "mesonFlags": "",
      "name": "what",
      "nativeBuildInputs": "",
      "out": "/nix/store/wl3q8rncvfix0gyb7nm8qi2ivlvm9nqx-what",
      "outputHash": "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",
      "outputHashAlgo": "sha256",
      "outputHashMode": "flat",
      "outputs": "out",
      "patches": "",
      "propagatedBuildInputs": "",
      "propagatedNativeBuildInputs": "",
      "stdenv": "/nix/store/5f05vzdazzj64dcmw9ylxv6d34jswi9q-stdenv-darwin",
      "strictDeps": "",
      "system": "aarch64-darwin"
    }
  }
}

Expected behavior

For these artifacts to be cleaned up.

nix-env --version output

nix-env (Nix) 2.10.3

Additional context

n/a

winterqt avatar Aug 04 '22 19:08 winterqt

Which part in here is problematic?

The outputs are indeed not cleared (not until the GC kicks at least), but that's on purpose: it would be silly to have to re-fetch them once you put the correct hash in the derivation.

The fact that they have no deriver should also not be a problem. There's a lot of paths in the store which don't (everything that gets imported during the evaluation or that gets nix-store --add-ed or equivalent), and that's totally part of the model.

thufschmitt avatar Aug 05 '22 14:08 thufschmitt