mirror of
https://github.com/fort-nix/nix-bitcoin.git
synced 2024-09-11 15:05:40 +03:00
Instead of setting up the script PATH via nix-shell, use `nix shell` with inputs from the nix-bitcoin flake. Advantages: - Uses the nixpkgs version from the nix-bitcoin flake instead of `<nixpkgs>` from the user env (NIX_PATH), so the script runtime env is reproducible. - The pkg derivations for the runtime env are cached, which greatly increases script startup speed. This commit was generated by running the following script inside the repo root dir: def transform(path, src) if src =~ /#! *nix-shell +-i +bash +-p +(.*)/ pkgs = $1 if src =~ /^.*?(set -e.*?pipefail)\n/ set_statement = $1 src.sub!($&, '') end src.sub!(/\A.*?#! *nix-shell.*?\n/m, '') parents = ([ '..' ] * (path.split('/').count - 1)).join('/') [ '#!/usr/bin/env bash', *set_statement, %(. "${BASH_SOURCE[0]%/*}/#{parents}/helper/run-in-nix-env" "#{pkgs}" "$@"), nil, src ].join("\n") end end Dir['**/*.sh'].each do |f| src = File.read(f) if new_src = transform(f, src) puts "Changed file #{f}" File.write(f, new_src) end end
21 lines
619 B
Bash
21 lines
619 B
Bash
#!/usr/bin/env bash
|
|
|
|
# Usage:
|
|
# source "path/to/run-in-nix-env" "pkg1 pkg2 ..." "$@"
|
|
#
|
|
# Runs the calling script with pkgs1, pkg2, ... in PATH.
|
|
# The packages are sourced from the nixpkgs input of the nix-bitcoin root flake.
|
|
|
|
if [[ ${_NIX_BITCOIN_ENV_PKGS:-} != "$1" ]]; then
|
|
export _NIX_BITCOIN_ENV_PKGS=$1
|
|
shift
|
|
|
|
_shell_pkgs=()
|
|
for _pkg in $_NIX_BITCOIN_ENV_PKGS; do
|
|
_shell_pkgs+=("nixpkgs#$_pkg")
|
|
done
|
|
# BASH_SOURCE[0] is this file
|
|
# BASH_SOURCE[-1] is the root src file
|
|
exec nix shell --inputs-from "${BASH_SOURCE[0]%/*}/.." "${_shell_pkgs[@]}" -c "${BASH_SOURCE[-1]}" "$@"
|
|
fi
|