2024-05-28 16:43:04 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2020-07-17 19:50:53 +00:00
|
|
|
source common.sh
|
|
|
|
|
2024-06-04 19:23:17 +00:00
|
|
|
echo example > "$TEST_ROOT"/example.txt
|
|
|
|
mkdir -p "$TEST_ROOT/x"
|
2020-07-17 19:50:53 +00:00
|
|
|
|
2024-03-29 12:19:36 +00:00
|
|
|
export NIX_STORE_DIR=/nix2/store
|
2020-07-17 19:50:53 +00:00
|
|
|
|
2024-06-04 19:23:17 +00:00
|
|
|
CORRECT_PATH=$(cd "$TEST_ROOT" && nix-store --store ./x --add example.txt)
|
2020-07-17 19:50:53 +00:00
|
|
|
|
2024-03-29 12:19:36 +00:00
|
|
|
[[ $CORRECT_PATH =~ ^/nix2/store/.*-example.txt$ ]]
|
2020-07-17 19:50:53 +00:00
|
|
|
|
2024-06-04 19:23:17 +00:00
|
|
|
PATH1=$(cd "$TEST_ROOT" && nix path-info --store ./x "$CORRECT_PATH")
|
|
|
|
[ "$CORRECT_PATH" == "$PATH1" ]
|
2020-07-17 19:50:53 +00:00
|
|
|
|
2024-06-04 19:23:17 +00:00
|
|
|
PATH2=$(nix path-info --store "$TEST_ROOT/x" "$CORRECT_PATH")
|
|
|
|
[ "$CORRECT_PATH" == "$PATH2" ]
|
2020-07-17 19:50:53 +00:00
|
|
|
|
2024-06-04 19:23:17 +00:00
|
|
|
PATH3=$(nix path-info --store "local?root=$TEST_ROOT/x" "$CORRECT_PATH")
|
|
|
|
[ "$CORRECT_PATH" == "$PATH3" ]
|
2022-12-26 20:21:08 +00:00
|
|
|
|
2023-10-17 18:44:11 +00:00
|
|
|
# Ensure store info trusted works with local store
|
2024-06-04 19:23:17 +00:00
|
|
|
nix --store "$TEST_ROOT/x" store info --json | jq -e '.trusted'
|
2024-03-29 12:19:36 +00:00
|
|
|
|
|
|
|
# Test building in a chroot store.
|
|
|
|
if canUseSandbox; then
|
|
|
|
|
|
|
|
flakeDir=$TEST_ROOT/flake
|
2024-06-04 19:23:17 +00:00
|
|
|
mkdir -p "$flakeDir"
|
2024-03-29 12:19:36 +00:00
|
|
|
|
2024-06-04 19:23:17 +00:00
|
|
|
cat > "$flakeDir"/flake.nix <<EOF
|
2024-03-29 12:19:36 +00:00
|
|
|
{
|
|
|
|
outputs = inputs: rec {
|
|
|
|
packages.$system.default = import ./simple.nix;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
|
2024-06-04 19:23:17 +00:00
|
|
|
cp simple.nix shell.nix simple.builder.sh config.nix "$flakeDir/"
|
2024-03-29 12:19:36 +00:00
|
|
|
|
2024-06-16 10:51:46 +00:00
|
|
|
TODO_NixOS
|
|
|
|
|
2024-06-04 19:23:17 +00:00
|
|
|
outPath=$(nix build --print-out-paths --no-link --sandbox-paths '/nix? /bin? /lib? /lib64? /usr?' --store "$TEST_ROOT/x" path:"$flakeDir")
|
2024-03-29 12:19:36 +00:00
|
|
|
|
|
|
|
[[ $outPath =~ ^/nix2/store/.*-simple$ ]]
|
|
|
|
|
2024-06-04 19:23:17 +00:00
|
|
|
base=$(basename "$outPath")
|
|
|
|
[[ $(cat "$TEST_ROOT"/x/nix/store/"$base"/hello) = 'Hello World!' ]]
|
2024-03-29 12:19:36 +00:00
|
|
|
fi
|