| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 |
|
| 21 | |
| 22 | |
| 23 | |
| 24 |
|
| 25 | set -e
|
| 26 |
|
| 27 | guix environment --version
|
| 28 |
|
| 29 | if ! guile -c '((@ (guix scripts environment) assert-container-features))'
|
| 30 | then
|
| 31 | |
| 32 | exit 77
|
| 33 | fi
|
| 34 |
|
| 35 | tmpdir="t-guix-environment-$$"
|
| 36 | trap 'rm -r "$tmpdir"' EXIT
|
| 37 |
|
| 38 | mkdir "$tmpdir"
|
| 39 |
|
| 40 | |
| 41 | if guix environment --container --ad-hoc --bootstrap guile-bootstrap \
|
| 42 | -- guile -c '(exit 42)'
|
| 43 | then
|
| 44 | false
|
| 45 | else
|
| 46 | test $? = 42
|
| 47 | fi
|
| 48 |
|
| 49 | |
| 50 | root="$tmpdir/root"
|
| 51 | guix environment -C --ad-hoc --bootstrap guile-bootstrap -r "$root" -- guile --version
|
| 52 | guix environment -C -p "$root" --bootstrap -- guile --version
|
| 53 | path1=$(guix environment -C -p "$root" --bootstrap -- guile -c '(display (getenv "PATH"))')
|
| 54 | path2=$(guix environment -C --ad-hoc --bootstrap guile-bootstrap -- guile -c '(display (getenv "PATH"))')
|
| 55 | test "$path1" = "$path2"
|
| 56 |
|
| 57 | |
| 58 | guix environment --container --ad-hoc --bootstrap guile-bootstrap \
|
| 59 | -- guile -c '(exit (pair? (getaddrinfo "localhost" "80")))'
|
| 60 |
|
| 61 | |
| 62 | |
| 63 | guix environment --container --ad-hoc --bootstrap guile-bootstrap \
|
| 64 | -- guile -c "(exit (= ECONNREFUSED
|
| 65 | (catch 'system-error
|
| 66 | (lambda ()
|
| 67 | (let ((sock (socket AF_INET SOCK_STREAM 0)))
|
| 68 | (connect sock AF_INET INADDR_LOOPBACK 12345)))
|
| 69 | (lambda args
|
| 70 | (pk 'errno (system-error-errno args))))))"
|
| 71 |
|
| 72 | |
| 73 | result="`FOOBAR=42; export FOOBAR; guix environment -C --ad-hoc --bootstrap \
|
| 74 | guile-bootstrap -E ^FOO -- guile -c '(display (getenv \"FOOBAR\"))'`"
|
| 75 | test "$result" = "42"
|
| 76 |
|
| 77 | |
| 78 | uid="`id -u`"
|
| 79 | inner_uid="`guix environment -C --ad-hoc --bootstrap guile-bootstrap \
|
| 80 | -- guile -c '(display (getuid))'`"
|
| 81 | test $inner_uid = $uid
|
| 82 |
|
| 83 | |
| 84 | |
| 85 | export tmpdir
|
| 86 | inner_uid="`HOME=$tmpdir guix environment -C --ad-hoc --bootstrap guile-bootstrap \
|
| 87 | --user=gnu-guix -- guile -c '(display (getuid))'`"
|
| 88 | test $inner_uid = 1000
|
| 89 |
|
| 90 | if test "x$USER" = "x"; then USER="`id -un`"; fi
|
| 91 |
|
| 92 | |
| 93 | guix environment -C --ad-hoc --bootstrap guile-bootstrap \
|
| 94 | -- guile -c "(exit (string=? \"$USER\" (passwd:name (getpwuid (getuid)))))"
|
| 95 | guix environment -C --ad-hoc --bootstrap guile-bootstrap \
|
| 96 | -- guile -c '(exit (string? (group:name (getgrgid (getgid)))))'
|
| 97 | guix environment -C --ad-hoc --bootstrap guile-bootstrap \
|
| 98 | -- guile -c '(use-modules (srfi srfi-1))
|
| 99 | (exit (every group:name
|
| 100 | (map getgrgid (vector->list (getgroups)))))'
|
| 101 |
|
| 102 | |
| 103 | if guix environment --container --ad-hoc --bootstrap guile-bootstrap \
|
| 104 | --expose=/does-not-exist -- guile -c 1 2> "$tmpdir/error"
|
| 105 | then
|
| 106 | false
|
| 107 | else
|
| 108 | grep "/does-not-exist" "$tmpdir/error"
|
| 109 | grep "[Nn]o such file" "$tmpdir/error"
|
| 110 | fi
|
| 111 |
|
| 112 | |
| 113 | mount_test_code="
|
| 114 | (use-modules (ice-9 rdelim)
|
| 115 | (ice-9 match)
|
| 116 | (srfi srfi-1))
|
| 117 |
|
| 118 | (define mappings
|
| 119 | (filter-map (lambda (line)
|
| 120 | (match (string-split line #\space)
|
| 121 | ;; Empty line.
|
| 122 | ((\"\") #f)
|
| 123 | ;; Ignore the root file system.
|
| 124 | ((_ \"/\" _ _ _ _)
|
| 125 | #f)
|
| 126 | ;; Ignore these types of file systems, except if they
|
| 127 | ;; correspond to a parent file system.
|
| 128 | ((_ mount (or \"tmpfs\" \"proc\" \"sysfs\" \"devtmpfs\"
|
| 129 | \"devpts\" \"cgroup\" \"mqueue\") _ _ _)
|
| 130 | (and (string-prefix? (getcwd) mount)
|
| 131 | mount))
|
| 132 | ((_ mount _ _ _ _)
|
| 133 | mount)))
|
| 134 | (string-split (call-with-input-file \"/proc/mounts\" read-string)
|
| 135 | #\newline)))
|
| 136 |
|
| 137 | (for-each (lambda (mount)
|
| 138 | (display mount)
|
| 139 | (newline))
|
| 140 | mappings)"
|
| 141 |
|
| 142 | guix environment --container --ad-hoc --bootstrap guile-bootstrap \
|
| 143 | -- guile -c "$mount_test_code" > $tmpdir/mounts
|
| 144 |
|
| 145 | cat "$tmpdir/mounts"
|
| 146 | test `wc -l < $tmpdir/mounts` -eq 4
|
| 147 |
|
| 148 | current_dir="`cd $PWD; pwd -P`"
|
| 149 | grep -e "$current_dir$" $tmpdir/mounts |
| 150 | grep $(guix build guile-bootstrap) $tmpdir/mounts
|
| 151 | grep -e "$NIX_STORE_DIR/.*-bash" $tmpdir/mounts |
| 152 |
|
| 153 | rm $tmpdir/mounts
|
| 154 |
|
| 155 | |
| 156 | |
| 157 | (
|
| 158 | linktest='
|
| 159 | (exit (and (string=? (getenv "GUIX_ENVIRONMENT")
|
| 160 | (string-append (getenv "HOME") "/.guix-profile"))
|
| 161 | (string-prefix? "'"$NIX_STORE_DIR"'"
|
| 162 | (readlink (string-append (getenv "HOME")
|
| 163 | "/.guix-profile")))))'
|
| 164 |
|
| 165 | cd "$tmpdir" \
|
| 166 | && guix environment --bootstrap --container --link-profile \
|
| 167 | --ad-hoc guile-bootstrap --pure \
|
| 168 | -- guile -c "$linktest"
|
| 169 | )
|
| 170 |
|
| 171 | |
| 172 | usertest='(exit (and (string=? (getenv "HOME") "/home/foognu")
|
| 173 | (string=? (passwd:name (getpwuid 1000)) "foognu")
|
| 174 | (file-exists? "/home/foognu/umock")))'
|
| 175 | touch "$tmpdir/umock"
|
| 176 | HOME="$tmpdir" guix environment --bootstrap --container --user=foognu \
|
| 177 | --ad-hoc guile-bootstrap --pure \
|
| 178 | --share="$tmpdir/umock" \
|
| 179 | -- guile -c "$usertest"
|
| 180 |
|
| 181 | |
| 182 | (
|
| 183 | cd "$tmpdir" \
|
| 184 | && guix environment --bootstrap --container --no-cwd --user=foo \
|
| 185 | --ad-hoc guile-bootstrap --pure \
|
| 186 | -- /bin/sh -c 'test $(pwd) == "/home/foo" -a ! -d '"$tmpdir"
|
| 187 | )
|
| 188 |
|
| 189 | |
| 190 | (
|
| 191 | cd "$tmpdir" \
|
| 192 | && guix environment --bootstrap --container --no-cwd --cwd=/tmp \
|
| 193 | --ad-hoc guile-bootstrap --pure \
|
| 194 | -- /bin/sh -c 'test $(pwd) == "/tmp" -a ! -d '"$tmpdir"
|
| 195 | )
|
| 196 |
|
| 197 | |
| 198 | mkdir -p "$tmpdir/home/wd"
|
| 199 | home_dir="$(cd "$tmpdir/home"; pwd -P)"
|
| 200 | (
|
| 201 | cd "$tmpdir/home/wd" \
|
| 202 | && HOME="$home_dir" guix environment --bootstrap --container --user=foo \
|
| 203 | --cwd=. --ad-hoc guile-bootstrap --pure \
|
| 204 | -- /bin/sh -c 'test "$(pwd)" = "/home/foo/wd"'
|
| 205 | )
|
| 206 |
|
| 207 | |
| 208 | guix environment --bootstrap --container --ad-hoc guile-bootstrap \
|
| 209 | -- guile -c '(mkdir "/whatever")' && false
|
| 210 |
|
| 211 | |
| 212 | guix environment --bootstrap --container --ad-hoc guile-bootstrap \
|
| 213 | --writable-root \
|
| 214 | -- guile -c '(mkdir "/whatever")'
|
| 215 |
|
| 216 | |
| 217 | guix environment --bootstrap --container --ad-hoc guile-bootstrap \
|
| 218 | -- guile -c '(mkdir "/tmp/foo")'
|
| 219 |
|
| 220 | |
| 221 | guix environment --bootstrap --container --ad-hoc guile-bootstrap \
|
| 222 | -- guile -c '(mkdir (string-append (getenv "HOME") "/foo"))'
|
| 223 |
|
| 224 | |
| 225 | guix environment --bootstrap --container --ad-hoc guile-bootstrap \
|
| 226 | -- guile -c '(mkdir "/run/user/1000/shepherd")'
|
| 227 |
|
| 228 | |
| 229 |
|
| 230 | abnormal_exit_code="
|
| 231 | (use-modules (system foreign))
|
| 232 | ;; Purposely make Guile crash with a segfault. :)
|
| 233 | (pointer->string (make-pointer 123) 123)"
|
| 234 |
|
| 235 | if guix environment --bootstrap --container \
|
| 236 | --ad-hoc guile-bootstrap -- guile -c "$abnormal_exit_code"
|
| 237 | then false;
|
| 238 | else
|
| 239 | test $? -gt 127
|
| 240 | fi
|
| 241 |
|
| 242 | |
| 243 |
|
| 244 | |
| 245 | |
| 246 | |
| 247 | storedir="`guile -c '(use-modules (guix config))(display %storedir)'`"
|
| 248 | localstatedir="`guile -c '(use-modules (guix config))(display %localstatedir)'`"
|
| 249 | NIX_STORE_DIR="$storedir"
|
| 250 | GUIX_DAEMON_SOCKET="$localstatedir/guix/daemon-socket/socket"
|
| 251 | GUIX_BUILD_OPTIONS="--timeout=`guile -c '(use-modules (guix tests))(display %tests-build-timeout)'`"
|
| 252 | export NIX_STORE_DIR GUIX_DAEMON_SOCKET GUIX_BUILD_OPTIONS
|
| 253 |
|
| 254 | if ! guile -c '(use-modules (guix)) (exit (false-if-exception (open-connection)))'
|
| 255 | then
|
| 256 | exit 77
|
| 257 | fi
|
| 258 |
|
| 259 | |
| 260 | |
| 261 | |
| 262 | guix shell -C --emulate-fhs --bootstrap guile-bootstrap \
|
| 263 | -- guile -c '(exit (and (file-exists? "/etc/ld.so.cache")
|
| 264 | (file-exists? "/lib")
|
| 265 | (file-exists? "/sbin")
|
| 266 | (file-exists? "/usr/bin")
|
| 267 | (file-exists? "/usr/include")
|
| 268 | (file-exists? "/usr/lib")
|
| 269 | (file-exists? "/usr/libexec")
|
| 270 | (file-exists? "/usr/sbin")
|
| 271 | (file-exists? "/usr/share")))'
|
| 272 |
|
| 273 | |
| 274 | guix shell -CF --bootstrap guile-bootstrap \
|
| 275 | -- guile -c '(execlp "ldconfig" "ldconfig" "-p")'
|
| 276 |
|
| 277 | |
| 278 | |
| 279 | |
| 280 | guix shell -CF --bootstrap guile-bootstrap glibc \
|
| 281 | -- guile -c '(exit (if (string-contains (readlink "/lib/libc.so")
|
| 282 | "glibc-for-fhs")
|
| 283 | 0
|
| 284 | 1))'
|
| 285 |
|
| 286 | |
| 287 | guix shell -CF coreutils -- env | grep ^PATH=/bin:/usr/bin:/sbin:/usr/sbin.*
|
| 288 |
|
| 289 | |
| 290 | |
| 291 | |
| 292 | |
| 293 | PATH=/foo $(type -P guix) shell -CF -E ^PATH$ coreutils \
|
| 294 | -- env | grep ^PATH=.*:/foo
|
| 295 |
|
| 296 | |
| 297 | echo "TESTING SYMLINK IN CONTAINER"
|
| 298 | guix shell --bootstrap guile-bootstrap --container \
|
| 299 | --symlink=/usr/bin/guile=bin/guile -- \
|
| 300 | /usr/bin/guile --version
|
| 301 |
|
| 302 | |
| 303 | guix shell --bootstrap -CS /usr/bin/python=bin/python guile-bootstrap -- exit && false
|
| 304 |
|
| 305 | |
| 306 | guix shell --bootstrap -CS bin/guile=/usr/bin/guile guile-bootstrap -- exit && false
|
| 307 |
|
| 308 | |
| 309 | guix build hello -d
|
| 310 | env="$(type -P pre-inst-env)"
|
| 311 | guix shell -C -D guix -- "$env" guix build hello -d && false |
| 312 | hello_drv="$(guix build hello -d)"
|
| 313 | hello_drv_nested="$(cd "$(dirname env)" && guix shell --bootstrap -E GUIX_BUILD_OPTIONS -CW -D guix -- "$env" guix build hello -d)"
|
| 314 | test "$hello_drv" = "$hello_drv_nested"
|