test/nixos-search: fix running flake-info in an offline environment

This commit is contained in:
Erik Arvstedt 2024-07-18 20:45:50 +02:00
parent 3cc6010658
commit 5d0907b064
No known key found for this signature in database
GPG Key ID: 33312B944DD97846
3 changed files with 30 additions and 4 deletions

View File

@ -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)";

View File

@ -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

View File

@ -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;