~/ ~/documents ~/harmful.txt github
Software builds with impuries produce non-deterministic and inconsistent outputs, making it imposisble to ganrantee reproducibility. Hence the strict policy for pure inputs for all packages in the nixpkgs repository. Impure inputs should be avoided whenever possible.

The following flake outputs a package named impure that requires an impure value to be provided at build time:

{
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  inputs.IMPURE_VALUE.url = "file+file:///dev/null";
  inputs.IMPURE_VALUE.flake = false;

  outputs = { self, nixpkgs, IMPURE_VALUE }: {
    packages.impure = nixpkgs.legacyPackages.x86_64-linux.stdenNoCC.mkDerivation {
        name = "impure";
        version = "1.0";
        dontUnpack = true;
        buildPhase = ''
          echo ${builtins.readFile IMPURE_VALUE.outPath} > IMPURE_VALUE
        '';
        installPhase = ''
           mkdir -p $out
           cp IMPURE_VALUE $out
        '';
    };
  };
}

The impure package can be built with the following command:

nix build .#impure --override-input IMPURE_VALUE file+file://<(printf %s "foo bar baz")

We can now verify that the impure package has been built with the correct value by inspecting the contents of the IMPURE_VALUE file and ensuring that it contains the string foo bar baz:

cat result/IMPURE_VALUE