Unverified Commit e3a74fda authored by John Ericson's avatar John Ericson Committed by GitHub
Browse files

fix inputDerivation in case of __structuredAttrs (#469652)

parents 17c265a6 97c36459
Loading
Loading
Loading
Loading
+14 −22
Original line number Diff line number Diff line
@@ -860,12 +860,23 @@ let
      # for a fixed-output derivation, the corresponding inputDerivation should
      # *not* be fixed-output. To achieve this we simply delete the attributes that
      # would make it fixed-output.
      deleteFixedOutputRelatedAttrs = lib.flip removeAttrs [
      fixedOutputRelatedAttrs = [
        "outputHashAlgo"
        "outputHash"
        "outputHashMode"
      ];

      # inputDerivation produces the inputs; not the outputs, so any
      # restrictions on what used to be the outputs don't serve a purpose
      # anymore.
      outputCheckAttrs = [
        "allowedReferences"
        "allowedRequisites"
        "disallowedReferences"
        "disallowedRequisites"
        "outputChecks"
      ];

    in

    extendDerivation validity.handled (
@@ -876,10 +887,10 @@ let
        # needed to enter a nix-shell with
        #   nix-build shell.nix -A inputDerivation
        inputDerivation = derivation (
          deleteFixedOutputRelatedAttrs derivationArg
          removeAttrs derivationArg (fixedOutputRelatedAttrs ++ outputCheckAttrs)
          // {
            # Add a name in case the original drv didn't have one
            name = derivationArg.name or "inputDerivation";
            name = "inputDerivation" + lib.optionalString (derivationArg ? name) "-${derivationArg.name}";
            # This always only has one output
            outputs = [ "out" ];

@@ -911,25 +922,6 @@ let
              ''
            ];
          }
          // (
            let
              sharedOutputChecks = {
                # inputDerivation produces the inputs; not the outputs, so any
                # restrictions on what used to be the outputs don't serve a purpose
                # anymore.
                allowedReferences = null;
                allowedRequisites = null;
                disallowedReferences = [ ];
                disallowedRequisites = [ ];
              };
            in
            if __structuredAttrs then
              {
                outputChecks.out = sharedOutputChecks;
              }
            else
              sharedOutputChecks
          )
        );

        inherit passthru overrideAttrs;
+65 −0
Original line number Diff line number Diff line
@@ -216,6 +216,22 @@ let
        touch $out
      '';
    };

  testInputDerivationDep = stdenv.mkDerivation {
    name = "test-input-derivation-dependency";
    buildCommand = "touch $out";
  };
  testInputDerivation =
    attrs:
    (stdenv.mkDerivation (
      attrs
      // {
        buildInputs = [ testInputDerivationDep ];
      }
    )).inputDerivation
    // {
      meta = { };
    };
in

{
@@ -356,6 +372,55 @@ in
        touch $out
      '';

  test-inputDerivation-structured = testInputDerivation {
    name = "test-inDrv-structured";
    __structuredAttrs = true;
  };

  test-inputDerivation-allowedReferences = testInputDerivation {
    name = "test-inDrv-allowedReferences";
    allowedReferences = [ ];
  };

  test-inputDerivation-disallowedReferences = testInputDerivation {
    name = "test-inDrv-disallowedReferences";
    disallowedReferences = [ "${testInputDerivationDep}" ];
  };

  test-inputDerivation-allowedRequisites = testInputDerivation {
    name = "test-inDrv-allowedRequisites";
    allowedRequisites = [ ];
  };

  test-inputDerivation-disallowedRequisites = testInputDerivation {
    name = "test-inDrv-disallowedRequisites";
    disallowedRequisites = [ "${testInputDerivationDep}" ];
  };

  test-inputDerivation-structured-allowedReferences = testInputDerivation {
    name = "test-inDrv-structured-allowedReferences";
    __structuredAttrs = true;
    outputChecks.out.allowedReferences = [ ];
  };

  test-inputDerivation-structured-disallowedReferences = testInputDerivation {
    name = "test-inDrv-structured-disallowedReferences";
    __structuredAttrs = true;
    outputChecks.out.disallowedReferences = [ "${testInputDerivationDep}" ];
  };

  test-inputDerivation-structured-allowedRequisites = testInputDerivation {
    name = "test-inDrv-structured-allowedRequisites";
    __structuredAttrs = true;
    outputChecks.out.allowedRequisites = [ ];
  };

  test-inputDerivation-structured-disallowedRequisites = testInputDerivation {
    name = "test-inDrv-structured-disallowedRequisites";
    __structuredAttrs = true;
    outputChecks.out.disallowedRequisites = [ "${testInputDerivationDep}" ];
  };

  test-prepend-append-to-var = testPrependAndAppendToVar {
    name = "test-prepend-append-to-var";
    stdenv' = bootStdenv;