mirror of
https://github.com/fort-nix/nix-bitcoin.git
synced 2024-11-22 22:33:46 +03:00
internal scripts: use pinned, cached pkgs
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
This commit is contained in:
parent
4cd9d0c6de
commit
af115d746b
@ -39,4 +39,4 @@ task:
|
|||||||
|
|
||||||
- name: shellcheck
|
- name: shellcheck
|
||||||
build_script:
|
build_script:
|
||||||
- nix shell --inputs-from . nixpkgs#{shellcheck,findutils,gnugrep} -c ./test/shellcheck.sh
|
- ./test/shellcheck.sh
|
||||||
|
20
helper/run-in-nix-env
Normal file
20
helper/run-in-nix-env
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#!/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
|
@ -1,6 +1,6 @@
|
|||||||
#! /usr/bin/env nix-shell
|
#!/usr/bin/env bash
|
||||||
#! nix-shell -i bash -p git
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
. "${BASH_SOURCE[0]%/*}/../../helper/run-in-nix-env" "git" "$@"
|
||||||
|
|
||||||
archive_hash () {
|
archive_hash () {
|
||||||
repo=$1
|
repo=$1
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env nix-shell
|
#!/usr/bin/env bash
|
||||||
#! nix-shell -i bash -p gnupg wget gnused
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
. "${BASH_SOURCE[0]%/*}/../../helper/run-in-nix-env" "gnupg wget gnused" "$@"
|
||||||
|
|
||||||
version="0.9.0"
|
version="0.9.0"
|
||||||
repo=https://github.com/Ride-The-Lightning/c-lightning-REST
|
repo=https://github.com/Ride-The-Lightning/c-lightning-REST
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#! /usr/bin/env nix-shell
|
#!/usr/bin/env bash
|
||||||
#! nix-shell -i bash -p git gnupg
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
. "${BASH_SOURCE[0]%/*}/../../helper/run-in-nix-env" "git gnupg" "$@"
|
||||||
|
|
||||||
TMPDIR="$(mktemp -d -p /tmp)"
|
TMPDIR="$(mktemp -d -p /tmp)"
|
||||||
trap 'rm -rf $TMPDIR' EXIT
|
trap 'rm -rf $TMPDIR' EXIT
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#! /usr/bin/env nix-shell
|
#!/usr/bin/env bash
|
||||||
#! nix-shell -i bash -p git
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
. "${BASH_SOURCE[0]%/*}/../../helper/run-in-nix-env" "git" "$@"
|
||||||
|
|
||||||
archive_hash () {
|
archive_hash () {
|
||||||
repo=$1
|
repo=$1
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#! /usr/bin/env nix-shell
|
#!/usr/bin/env bash
|
||||||
#! nix-shell -i bash -p git gnupg curl jq
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
. "${BASH_SOURCE[0]%/*}/../../helper/run-in-nix-env" "git gnupg curl jq" "$@"
|
||||||
|
|
||||||
TMPDIR=$(mktemp -d -p /tmp)
|
TMPDIR=$(mktemp -d -p /tmp)
|
||||||
trap 'rm -rf $TMPDIR' EXIT
|
trap 'rm -rf $TMPDIR' EXIT
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#! /usr/bin/env nix-shell
|
#!/usr/bin/env bash
|
||||||
#! nix-shell -i bash -p git gnupg
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
. "${BASH_SOURCE[0]%/*}/../../../helper/run-in-nix-env" "git gnupg" "$@"
|
||||||
|
|
||||||
TMPDIR=$(mktemp -d -p /tmp)
|
TMPDIR=$(mktemp -d -p /tmp)
|
||||||
trap 'rm -rf $TMPDIR' EXIT
|
trap 'rm -rf $TMPDIR' EXIT
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env nix-shell
|
#!/usr/bin/env bash
|
||||||
#! nix-shell -i bash -p gnupg wget gnused
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
. "${BASH_SOURCE[0]%/*}/../../helper/run-in-nix-env" "gnupg wget gnused" "$@"
|
||||||
|
|
||||||
version="0.13.1"
|
version="0.13.1"
|
||||||
repo=https://github.com/Ride-The-Lightning/RTL
|
repo=https://github.com/Ride-The-Lightning/RTL
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env nix-shell
|
#!/usr/bin/env bash
|
||||||
#! nix-shell -i bash -p nodePackages.node2nix gnupg wget jq moreutils gnused
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
. "${BASH_SOURCE[0]%/*}/../../helper/run-in-nix-env" "nodePackages.node2nix gnupg wget jq moreutils gnused" "$@"
|
||||||
|
|
||||||
TMPDIR=$(mktemp -d -p /tmp)
|
TMPDIR=$(mktemp -d -p /tmp)
|
||||||
trap 'rm -rf $TMPDIR' EXIT
|
trap 'rm -rf $TMPDIR' EXIT
|
||||||
|
@ -322,7 +322,7 @@ examples() {
|
|||||||
|
|
||||||
shellcheck() {
|
shellcheck() {
|
||||||
if ! checkFlakeSupport "shellcheck"; then return; fi
|
if ! checkFlakeSupport "shellcheck"; then return; fi
|
||||||
nix shell --inputs-from "$scriptDir/.." nixpkgs#shellcheck -c "$scriptDir/shellcheck.sh"
|
"$scriptDir/shellcheck.sh"
|
||||||
}
|
}
|
||||||
|
|
||||||
all() {
|
all() {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
. "${BASH_SOURCE[0]%/*}/../helper/run-in-nix-env" "shellcheck findutils gnugrep" "$@"
|
||||||
|
|
||||||
cd "${BASH_SOURCE[0]%/*}/.."
|
cd "${BASH_SOURCE[0]%/*}/.."
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user