Unverified Commit 47e85717 authored by Ramses's avatar Ramses Committed by GitHub
Browse files

writeShellApplication: fix inheritPath without runtimeInputs (#499462)

parents 50375b59 3c031f3f
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -356,10 +356,16 @@ rec {
          export ${name}
        '') runtimeEnv
      )
      + lib.optionalString (runtimeInputs != [ ]) ''
      + ''

        export PATH="${lib.makeBinPath runtimeInputs}${lib.optionalString inheritPath ":$PATH"}"
        export PATH="${
          lib.concatStringsSep ":" (
            (lib.optionals (runtimeInputs != [ ]) [ (lib.makeBinPath runtimeInputs) ])
            ++ (lib.optionals inheritPath [ "$PATH" ])
          )
        }"
      ''

      + ''

        ${text}
+44 −0
Original line number Diff line number Diff line
@@ -83,6 +83,50 @@ linkFarm "writeShellApplication-tests" {
    '';
  };

  test-no-inherit-path-no-runtimeInputs = checkShellApplication {
    name = "test-no-inherit-path-no-runtimeInputs";
    inheritPath = false;
    runtimeInputs = [ ];
    text = ''
      if [[ ''${#PATH} -eq 0 ]]; then
        echo -n "PATH is empty"
      fi
    '';
    expected = "PATH is empty";
  };

  test-no-inherit-path-runtimeInputs = checkShellApplication {
    name = "test-no-inherit-path-runtimeInputs";
    inheritPath = false;
    runtimeInputs = [ hello ];
    text = ''
      extra_colon_pattern='(^:|:$)'
      if [[ ''${PATH} =~ $extra_colon_pattern ]]; then
        echo "PATH should not start or end with a colon: $PATH"
      fi
      if [[ ''${#PATH} -gt 0 ]]; then
        echo -n "PATH is not empty"
      fi
    '';
    expected = "PATH is not empty";
  };

  test-inherit-path-no-runtimeInputs = checkShellApplication {
    name = "test-inherit-path-no-runtimeInputs";
    inheritPath = true;
    runtimeInputs = [ ];
    text = ''
      extra_colon_pattern='(^:|:$)'
      if [[ ''${PATH} =~ $extra_colon_pattern ]]; then
        echo "PATH should not start or end with a colon: $PATH"
      fi
      if [[ ''${#PATH} -gt 0 ]]; then
        echo -n "PATH is not empty"
      fi
    '';
    expected = "PATH is not empty";
  };

  test-check-phase = checkShellApplication {
    name = "test-check-phase";
    text = "";