diff --git a/release-common.nix b/release-common.nix index 7e7de005d2f..16832618546 100644 --- a/release-common.nix +++ b/release-common.nix @@ -70,7 +70,8 @@ rec { sha256 = "1pij0v449p166f9l29x7ppzk8j7g9k9mp15ilh5qxp29c7fnvxy2"; }) ]; */ - })); + })) + ++ lib.optional (stdenv.isLinux || stdenv.isDarwin) ipfs; propagatedDeps = [ (boehmgc.override { enableLargeConfig = true; }) diff --git a/tests/init.sh b/tests/init.sh index c62c4856a93..8b9ded4a446 100644 --- a/tests/init.sh +++ b/tests/init.sh @@ -2,7 +2,7 @@ source common.sh test -n "$TEST_ROOT" if test -d "$TEST_ROOT"; then - chmod -R u+w "$TEST_ROOT" + chmod -R u+rw "$TEST_ROOT" rm -rf "$TEST_ROOT" fi mkdir "$TEST_ROOT" diff --git a/tests/ipfs.sh b/tests/ipfs.sh new file mode 100644 index 00000000000..9cad1c381f6 --- /dev/null +++ b/tests/ipfs.sh @@ -0,0 +1,117 @@ +source common.sh + +# This are for ./fixed.nix +export IMPURE_VAR1=foo +export IMPURE_VAR2=bar + +################################################################################ +## Check that the ipfs daemon is present and enabled in your environment +################################################################################ + +if [[ -z $(type -p ipfs) ]]; then + echo "Ipfs not installed; skipping ipfs tests" + exit 99 +fi + +# To see if ipfs is connected to the network, we check if we can see some peers +# other than ourselves. +if (! (ipfs log ls)); +then + echo "Ipfs daemon not detected; initializing.." + ipfs init + ipfs daemon --offline & + pidIpfsDaemon=$! + trap "kill -9 $pidIpfsDaemon" EXIT +fi + +clearStore + +################################################################################ +## Create the folders for the source and destination stores +################################################################################ + +IPFS_TESTS=$TEST_ROOT/ipfs_tests +mkdir $IPFS_TESTS + +# Here we define some store locations, one for the initial store we upload, and +# the other three for the destination stores to which we'll copy (one for each +# method) +IPFS_SRC_STORE=$IPFS_TESTS/ipfs_source_store + +IPFS_DST_HTTP_STORE=$IPFS_TESTS/ipfs_dest_http_store +IPFS_DST_HTTP_LOCAL_STORE=$IPFS_TESTS/ipfs_dest_http_local_store +IPFS_DST_IPFS_STORE=$IPFS_TESTS/ipfs_dest_ipfs_store +IPFS_DST_IPNS_STORE=$IPFS_TESTS/ipfs_dest_ipns_store + +################################################################################ +## Generate the keys to sign the store +################################################################################ + +SIGNING_KEY_NAME=nixcache.for.ipfs-1 +SIGNING_KEY_PRI_FILE=$IPFS_TESTS/nix-cache-key.sec +SIGNING_KEY_PUB_FILE=$IPFS_TESTS/nix-cache-key.pub + +nix-store --generate-binary-cache-key $SIGNING_KEY_NAME $SIGNING_KEY_PRI_FILE $SIGNING_KEY_PUB_FILE + +################################################################################ +## Create, sign and upload the source store +################################################################################ + +mkdir -p $IPFS_SRC_STORE +storePaths=$(nix-build ./fixed.nix -A good | sort | uniq) + +# Hack around https://github.com/NixOS/nix/issues/3695 +for path in $storePaths; do + nix copy --to file://$IPFS_SRC_STORE $path +done +unset path + +nix sign-paths --store file://$IPFS_SRC_STORE \ + -k $SIGNING_KEY_PRI_FILE $storePaths + +IPFS_HASH=$(ipfs add -r $IPFS_SRC_STORE 2>/dev/null | tail -n 1 | awk '{print $2}') + +################################################################################ +## Create the local http store and download the derivation there +################################################################################ + +mkdir $IPFS_DST_HTTP_LOCAL_STORE + +IPFS_HTTP_LOCAL_PREFIX='http://localhost:8080/ipfs' + +DOWNLOAD_LOCATION=$(nix-build ./fixed.nix -A good \ + --option substituters $IPFS_HTTP_LOCAL_PREFIX/$IPFS_HASH \ + --store $IPFS_DST_HTTP_LOCAL_STORE \ + --no-out-link \ + -j0 \ + --option trusted-public-keys $(cat $SIGNING_KEY_PUB_FILE)) + +################################################################################ +## Create the ipfs store and download the derivation there +################################################################################ + +mkdir $IPFS_DST_IPFS_STORE + +DOWNLOAD_LOCATION=$(nix-build ./fixed.nix -A good \ + --option substituters 'ipfs://'$IPFS_HASH \ + --store $IPFS_DST_IPFS_STORE \ + --no-out-link \ + -j0 \ + --option trusted-public-keys $(cat $SIGNING_KEY_PUB_FILE)) + + +################################################################################ +## Create the ipns store and download the derivation there +################################################################################ + +# First I have to publish: +IPNS_ID=$(ipfs name publish $IPFS_HASH --allow-offline | awk '{print substr($3,1,length($3)-1)}') + +mkdir $IPFS_DST_IPNS_STORE + +DOWNLOAD_LOCATION=$(nix-build ./fixed.nix -A good \ + --option substituters 'ipns://'$IPNS_ID \ + --store $IPFS_DST_IPNS_STORE \ + --no-out-link \ + -j0 \ + --option trusted-public-keys $(cat $SIGNING_KEY_PUB_FILE)) diff --git a/tests/local.mk b/tests/local.mk index 536661af88e..f8af448d5df 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -31,7 +31,8 @@ nix_tests = \ nix-copy-ssh.sh \ post-hook.sh \ function-trace.sh \ - recursive.sh + recursive.sh \ + ipfs.sh # parallel.sh install-tests += $(foreach x, $(nix_tests), tests/$(x))