Skip to content

Commit

Permalink
Handle stdout from shell hooks
Browse files Browse the repository at this point in the history
Before this commit, any `shellHook` which emitted to stdout would cause
the action to fail with a message like `<valid name of a variable from
the shell being loaded>: Invalid variable name`, as the hook's output
would get interpreted as part of the output of `env -0` and `echo
$PATH`.

After this commit, those commands are prefixed by a random delimiter,
and all output before that delimiter is ignored.

Type: fix
Issue: 11
  • Loading branch information
nicknovitski committed Oct 27, 2024
1 parent 9f0f1b1 commit d7cbfcc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
packages = eachSystem ({pkgs, ...}: {
default = pkgs.writeShellApplication {
name = "nix-develop-gha";
runtimeInputs = [pkgs.gnugrep pkgs.openssl.bin pkgs.coreutils];
runtimeInputs = [pkgs.gnugrep pkgs.openssl.bin pkgs.coreutils pkgs.gnused];
text = builtins.readFile ./nix-develop-gha.sh;
};
});
Expand Down
7 changes: 4 additions & 3 deletions nix-develop-gha.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ set -euo pipefail
IFS=" " read -r -a arguments <<<"${@:-./#default}"

with_nix_develop() {
nix develop "${arguments[@]}" --command "$@"
delimiter=$(openssl rand -base64 18)
nix develop "${arguments[@]}" --command bash -c "echo $delimiter; $*" | sed -n "\|$delimiter|,\$p" | tail -n +2
}

with_nix_develop true # Exit immediately if build fails
Expand Down Expand Up @@ -35,10 +36,10 @@ while IFS='=' read -r -d '' n v; do
continue
fi
printf "%s=%s\n" "$n" "$v" >>"${GITHUB_ENV:-/dev/stderr}"
done < <(with_nix_develop env -0)
done < <(with_nix_develop "env -0")

# Read the nix environment's $PATH into an array
IFS=":" read -r -a nix_path_array <<<"$(with_nix_develop bash -c "echo \$PATH")"
IFS=":" read -r -a nix_path_array <<<"$(with_nix_develop "echo \$PATH")"

# Iterate over the PATH array in reverse
#
Expand Down

0 comments on commit d7cbfcc

Please sign in to comment.