diff --git a/test/nixos-search/ci-test.sh b/test/nixos-search/ci-test.sh index 8580a93..1f28361 100755 --- a/test/nixos-search/ci-test.sh +++ b/test/nixos-search/ci-test.sh @@ -3,13 +3,19 @@ set -euo pipefail cd "${BASH_SOURCE[0]%/*}" +nbFlake=$(realpath ../..) + # Use cachix to cache the `flake-info` build cachixCache=nix-bitcoin nix run .#cachix -- use "$cachixCache" # shellcheck disable=SC2016 -PATH=$(nix shell -L .#flake-info .#cachix -c sh -c 'echo $PATH') +PATH=$(nix shell -L .#{flake-info,cachix,jq} -c sh -c 'echo $PATH') + +# flake-info uses `nixpkgs` from NIX_PATH +NIX_PATH="nixpkgs=$(nix flake metadata --json --inputs-from "$nbFlake" nixpkgs | jq -r .path)" +export NIX_PATH if [[ ${CACHIX_SIGNING_KEY:-} ]]; then cachix push "$cachixCache" "$(type -P flake-info)"; diff --git a/test/nixos-search/flake-info-sandboxed.sh b/test/nixos-search/flake-info-sandboxed.sh index 2bf6bb8..aeb8199 100755 --- a/test/nixos-search/flake-info-sandboxed.sh +++ b/test/nixos-search/flake-info-sandboxed.sh @@ -13,7 +13,11 @@ cd "${BASH_SOURCE[0]%/*}" nbFlake=$(realpath ../..) # shellcheck disable=SC2016 -PATH=$(nix shell -L .#{flake-info,bubblewrap} -c sh -c 'echo $PATH') +PATH=$(nix shell -L .#{flake-info,bubblewrap,jq} -c sh -c 'echo $PATH') + +# flake-info uses `nixpkgs` from NIX_PATH +NIX_PATH="nixpkgs=$(nix flake metadata --json --inputs-from "$nbFlake" nixpkgs | jq -r .path)" +export NIX_PATH tmpDir=$(mktemp -d /tmp/nix-bitcoin-flake-info.XXX) trap 'rm -rf $tmpDir' EXIT diff --git a/test/nixos-search/flake.nix b/test/nixos-search/flake.nix index 8c462bc..a4e816f 100644 --- a/test/nixos-search/flake.nix +++ b/test/nixos-search/flake.nix @@ -4,8 +4,24 @@ { inputs.nixos-search.url = "github:nixos/nixos-search"; - outputs = { self, nixos-search }: { - inherit (nixos-search) packages; + outputs = { self, nixos-search }: let + systems = [ + "x86_64-linux" + "aarch64-linux" + ]; + inherit (nixos-search.inputs.nixpkgs) lib; + in { + packages = lib.genAttrs systems (system: { + # In flake-info, Rust calls into Nix code which uses `nixpkgs` from NIX_PATH. + # Don't set `nixpkgs` to a tarball URL, use the default value from the environment instead. + # This allows running flake-info in an offline environment (./flake-info-sandboxed.sh). + flake-info = nixos-search.packages.${system}.flake-info.overrideAttrs (old: { + postPatch = (old.postPatch or "") + '' + substituteInPlace src/commands/nix_flake_attrs.rs --replace-fail \ + 'command.add_arg_pair("-I", "nixpkgs=https://github.com/NixOS/nixpkgs/archive/refs/heads/nixpkgs-unstable.tar.gz");' "" + ''; + }); + }); # Used by ./ci-test.sh inherit (nixos-search.inputs.nixpkgs) legacyPackages;