| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 |
|
| 20 | |
| 21 | |
| 22 | |
| 23 |
|
| 24 | guix pack --version
|
| 25 |
|
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 |
|
| 31 | storedir="`guile -c '(use-modules (guix config))(display %storedir)'`"
|
| 32 | localstatedir="`guile -c '(use-modules (guix config))(display %localstatedir)'`"
|
| 33 | NIX_STORE_DIR="$storedir"
|
| 34 | GUIX_DAEMON_SOCKET="$localstatedir/guix/daemon-socket/socket"
|
| 35 | GUIX_BUILD_OPTIONS="--timeout=`guile -c '(use-modules (guix tests))(display %tests-build-timeout)'`"
|
| 36 | export NIX_STORE_DIR GUIX_DAEMON_SOCKET GUIX_BUILD_OPTIONS
|
| 37 |
|
| 38 | if ! guile -c '(use-modules (guix)) (exit (false-if-exception (open-connection)))'
|
| 39 | then
|
| 40 | exit 77
|
| 41 | fi
|
| 42 |
|
| 43 | |
| 44 | |
| 45 | |
| 46 | run_without_store ()
|
| 47 | {
|
| 48 | if unshare -r true |
| 49 | then
|
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | unshare -mrf sh -c 'mount -t tmpfs -o ro none "$NIX_STORE_DIR"; '"$*"
|
| 55 | else
|
| 56 | |
| 57 | |
| 58 | |
| 59 | sh -c "$*"
|
| 60 | fi
|
| 61 | }
|
| 62 |
|
| 63 | |
| 64 | |
| 65 | wait_for_file ()
|
| 66 | {
|
| 67 | i=0
|
| 68 | while ! test -f "$1" && test $i -lt 20
|
| 69 | do
|
| 70 | sleep 0.3
|
| 71 | i=`expr $i + 1`
|
| 72 | done
|
| 73 | test -f "$1"
|
| 74 | }
|
| 75 |
|
| 76 | test_directory="`mktemp -d`"
|
| 77 | export test_directory
|
| 78 | trap 'chmod -Rf +w "$test_directory"; rm -rf "$test_directory"' EXIT
|
| 79 |
|
| 80 | if unshare -r true
|
| 81 | then
|
| 82 | |
| 83 | tarball="`guix pack -R -S /Bin=bin sed`"
|
| 84 | (cd "$test_directory"; tar xvf "$tarball")
|
| 85 |
|
| 86 | chmod +w "$test_directory"
|
| 87 | run_without_store "$test_directory/Bin/sed" --version > "$test_directory/output"
|
| 88 | grep 'GNU sed' "$test_directory/output"
|
| 89 |
|
| 90 | |
| 91 | run_without_store GUIX_EXECUTION_ENGINE="userns" \
|
| 92 | "$test_directory/Bin/sed" --version > "$test_directory/output"
|
| 93 | grep 'GNU sed' "$test_directory/output"
|
| 94 |
|
| 95 | |
| 96 | run_without_store "$test_directory/Bin/sed" --does-not-exist && false
|
| 97 |
|
| 98 | chmod -Rf +w "$test_directory"; rm -rf "$test_directory"/*
|
| 99 | else
|
| 100 | echo "'userns' execution tests skipped" >&2
|
| 101 | fi
|
| 102 |
|
| 103 | case "`uname -m`" in
|
| 104 | x86_64|i?86)
|
| 105 | |
| 106 | tarball="`guix pack -RR -S /Bin=bin sed`"
|
| 107 | tar tvf "$tarball" | grep /bin/proot
|
| 108 | (cd "$test_directory"; tar xf "$tarball")
|
| 109 | chmod +w "$test_directory"
|
| 110 | run_without_store GUIX_EXECUTION_ENGINE="proot" \
|
| 111 | "$test_directory/Bin/sed" --version > "$test_directory/output"
|
| 112 | grep 'GNU sed' "$test_directory/output"
|
| 113 |
|
| 114 | |
| 115 | run_without_store GUIX_EXECUTION_ENGINE="fakechroot" \
|
| 116 | "$test_directory/Bin/sed" --version > "$test_directory/output"
|
| 117 | grep 'GNU sed' "$test_directory/output"
|
| 118 | unset GUIX_EXECUTION_ENGINE
|
| 119 |
|
| 120 | chmod -Rf +w "$test_directory"; rm -rf "$test_directory"/*
|
| 121 |
|
| 122 | if unshare -r true
|
| 123 | then
|
| 124 | |
| 125 | |
| 126 | |
| 127 | tarball="`guix pack -RR -S /bin=bin bash-minimal`"
|
| 128 | (cd "$test_directory"; tar xf "$tarball")
|
| 129 |
|
| 130 | STORE_PARENT="`dirname $NIX_STORE_DIR`"
|
| 131 | export STORE_PARENT
|
| 132 |
|
| 133 | for engine in userns proot fakechroot
|
| 134 | do
|
| 135 | for i in $(guix gc -R $(guix build bash-minimal | grep -v -e '-doc$'))
|
| 136 | do
|
| 137 | unshare -mrf sh -c "mount -t tmpfs none \"$NIX_STORE_DIR\"; GUIX_EXECUTION_ENGINE=$engine $test_directory/bin/sh -c 'echo $NIX_STORE_DIR/*'" | grep $(basename $i)
|
| 138 | unshare -mrf sh -c "mount -t tmpfs none \"$STORE_PARENT\"; GUIX_EXECUTION_ENGINE=$engine $test_directory/bin/sh -c 'echo $NIX_STORE_DIR/*'" | grep $(basename $i)
|
| 139 | done
|
| 140 | done
|
| 141 |
|
| 142 | chmod -Rf +w "$test_directory"; rm -rf "$test_directory"/*
|
| 143 | fi
|
| 144 | ;;
|
| 145 | *)
|
| 146 | echo "skipping PRoot and Fakechroot tests" >&2
|
| 147 | ;;
|
| 148 | esac
|
| 149 |
|
| 150 | if unshare -r true
|
| 151 | then
|
| 152 | |
| 153 | |
| 154 | |
| 155 | cat > "$test_directory/manifest.scm" <<EOF
|
| 156 | (use-modules (guix))
|
| 157 |
|
| 158 | (define daemon
|
| 159 | (program-file "daemon"
|
| 160 | #~(begin
|
| 161 | (use-modules (ice-9 match)
|
| 162 | (ice-9 ftw))
|
| 163 |
|
| 164 | (call-with-output-file "parent-store"
|
| 165 | (lambda (port)
|
| 166 | (write (scandir (ungexp (%store-prefix)))
|
| 167 | port)))
|
| 168 |
|
| 169 | (match (primitive-fork)
|
| 170 | (0 (sigaction SIGHUP (const #t))
|
| 171 | (call-with-output-file "pid"
|
| 172 | (lambda (port)
|
| 173 | (display (getpid) port)))
|
| 174 | (pause)
|
| 175 | (call-with-output-file "child-store"
|
| 176 | (lambda (port)
|
| 177 | (write (scandir (ungexp (%store-prefix)))
|
| 178 | port))))
|
| 179 | (_ #t)))))
|
| 180 |
|
| 181 | (define package
|
| 182 | (computed-file "package"
|
| 183 | #~(let ((out (ungexp output)))
|
| 184 | (mkdir out)
|
| 185 | (mkdir (string-append out "/bin"))
|
| 186 | (symlink (ungexp daemon)
|
| 187 | (string-append out "/bin/daemon")))))
|
| 188 |
|
| 189 | (manifest (list (manifest-entry
|
| 190 | (name "daemon")
|
| 191 | (version "0")
|
| 192 | (item package))))
|
| 193 | EOF
|
| 194 |
|
| 195 | tarball="$(guix pack -S /bin=bin -R -m "$test_directory/manifest.scm")"
|
| 196 | (cd "$test_directory"; tar xf "$tarball")
|
| 197 |
|
| 198 | |
| 199 | |
| 200 | |
| 201 | chmod +w "$test_directory"
|
| 202 | (cd "$test_directory"; run_without_store ./bin/daemon)
|
| 203 | wait_for_file "$test_directory/pid"
|
| 204 | kill -HUP $(cat "$test_directory/pid")
|
| 205 | wait_for_file "$test_directory/child-store"
|
| 206 | diff -u "$test_directory/parent-store" "$test_directory/child-store"
|
| 207 |
|
| 208 | chmod -Rf +w "$test_directory"; rm -rf "$test_directory"/*
|
| 209 | fi
|
| 210 |
|
| 211 | |
| 212 | tarball="`guix pack -R -S /share=share groff:doc`"
|
| 213 | (cd "$test_directory"; tar xf "$tarball")
|
| 214 | test -d "$test_directory/share/doc/groff/html"
|
| 215 | chmod -Rf +w "$test_directory"; rm -rf "$test_directory"/*
|
| 216 |
|
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | guix pack -RR -e '(@ (gnu packages python-xyz) python-numpy)' python-scipy --no-grafts -n
|
| 226 |
|
| 227 | |
| 228 | |
| 229 | cat >"$test_directory/manifest.scm" <<'EOF'
|
| 230 | (use-modules (guix) (guix profiles) (guix search-paths)
|
| 231 | (gnu packages bootstrap))
|
| 232 | (manifest
|
| 233 | (list (manifest-entry
|
| 234 | (name "test") (version "0")
|
| 235 | (item (file-union "test"
|
| 236 | `(("bin/hello"
|
| 237 | ,(program-file
|
| 238 | "hello"
|
| 239 | #~(begin
|
| 240 | (add-to-load-path (getenv "HELLO_EXEC_PATH"))
|
| 241 | (display (load-from-path "msg"))(newline))
|
| 242 | #:guile %bootstrap-guile))
|
| 243 | ("libexec/hello/msg"
|
| 244 | ,(plain-file "msg" "42")))))
|
| 245 | (search-paths
|
| 246 | (list (search-path-specification
|
| 247 | (variable "HELLO_EXEC_PATH")
|
| 248 | (files '("libexec/hello"))
|
| 249 | (separator #f)))))))
|
| 250 | EOF
|
| 251 | tarball="`guix pack -RR -S /opt= -m $test_directory/manifest.scm`"
|
| 252 | (cd "$test_directory"; tar xvf "$tarball")
|
| 253 | chmod +w "$test_directory"
|
| 254 | ( export GUIX_PROFILE=$test_directory/opt
|
| 255 | . $GUIX_PROFILE/etc/profile
|
| 256 | run_without_store "$test_directory/opt/bin/hello" > "$test_directory/output" )
|
| 257 | cat "$test_directory/output"
|
| 258 | test "`cat $test_directory/output`" = "42"
|