summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludovic.courtes@inria.fr>2019-07-02 10:30:23 +0200
committerLudovic Courtès <ludo@gnu.org>2019-07-04 18:05:02 +0200
commitdea62932bc929243dae5e8b08f4fbe0b6f70be95 (patch)
treed9821aba6a2ac4c4e1577d005850d6f3c7496bce
parentb9fcf0c82a14df48c7c6f36a08dbdcd3184fcbf8 (diff)
pack: 'squashfs' backend records the profile's search paths.
* guix/scripts/pack.scm (singularity-environment-file): New procedure. (squashfs-image): Use it, and create /.singularity/env/90-environment.sh. * gnu/tests/singularity.scm (run-singularity-test)["singularity run, with environment"]: New test, currently skipped. * gnu/tests/singularity.scm (build-tarball&run-singularity-test): Add GUILE-JSON to the profile.
-rw-r--r--gnu/tests/singularity.scm18
-rw-r--r--guix/scripts/pack.scm41
2 files changed, 57 insertions, 2 deletions
diff --git a/gnu/tests/singularity.scm b/gnu/tests/singularity.scm
index 668043a0bc0..2f3a6f289db 100644
--- a/gnu/tests/singularity.scm
+++ b/gnu/tests/singularity.scm
@@ -111,6 +111,21 @@
111 "run" #$image "-c" "(exit 42)")) 111 "run" #$image "-c" "(exit 42)"))
112 marionette)) 112 marionette))
113 113
114 ;; FIXME: Singularity 2.x doesn't directly honor
115 ;; /.singularity.d/env/*.sh. Instead, you have to load those files
116 ;; manually, which we don't do. Remove 'test-skip' call once we've
117 ;; switch to Singularity 3.x.
118 (test-skip 1)
119 (test-equal "singularity run, with environment"
120 0
121 (marionette-eval
122 ;; Check whether GUILE_LOAD_PATH is properly set, allowing us to
123 ;; find the (json) module.
124 `(status:exit-val
125 (system* #$(file-append singularity "/bin/singularity")
126 "--debug" "run" #$image "-c" "(use-modules (json))"))
127 marionette))
128
114 (test-end) 129 (test-end)
115 (exit (= (test-runner-fail-count (test-runner-current)) 0))))) 130 (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
116 131
@@ -122,7 +137,8 @@
122 (guile (set-guile-for-build (default-guile))) 137 (guile (set-guile-for-build (default-guile)))
123 ;; 'singularity exec' insists on having /bin/sh in the image. 138 ;; 'singularity exec' insists on having /bin/sh in the image.
124 (profile (profile-derivation (packages->manifest 139 (profile (profile-derivation (packages->manifest
125 (list bash-minimal guile-2.2)) 140 (list bash-minimal
141 guile-2.2 guile-json))
126 #:hooks '() 142 #:hooks '()
127 #:locales? #f)) 143 #:locales? #f))
128 (tarball (squashfs-image "singularity-pack" profile 144 (tarball (squashfs-image "singularity-pack" profile
diff --git a/guix/scripts/pack.scm b/guix/scripts/pack.scm
index bb6a8cda1af..4ac5dfc896a 100644
--- a/guix/scripts/pack.scm
+++ b/guix/scripts/pack.scm
@@ -286,6 +286,32 @@ added to the pack."
286 build 286 build
287 #:references-graphs `(("profile" ,profile)))) 287 #:references-graphs `(("profile" ,profile))))
288 288
289(define (singularity-environment-file profile)
290 "Return a shell script that defines the environment variables corresponding
291to the search paths of PROFILE."
292 (define build
293 (with-extensions (list guile-gcrypt)
294 (with-imported-modules `(((guix config) => ,(make-config.scm))
295 ,@(source-module-closure
296 `((guix profiles)
297 (guix search-paths))
298 #:select? not-config?))
299 #~(begin
300 (use-modules (guix profiles) (guix search-paths)
301 (ice-9 match))
302
303 (call-with-output-file #$output
304 (lambda (port)
305 (for-each (match-lambda
306 ((spec . value)
307 (format port "~a=~a~%export ~a~%"
308 (search-path-specification-variable spec)
309 value
310 (search-path-specification-variable spec))))
311 (profile-search-paths #$profile))))))))
312
313 (computed-file "singularity-environment.sh" build))
314
289(define* (squashfs-image name profile 315(define* (squashfs-image name profile
290 #:key target 316 #:key target
291 (profile-name "guix-profile") 317 (profile-name "guix-profile")
@@ -305,6 +331,9 @@ added to the pack."
305 (file-append (store-database (list profile)) 331 (file-append (store-database (list profile))
306 "/db/db.sqlite"))) 332 "/db/db.sqlite")))
307 333
334 (define environment
335 (singularity-environment-file profile))
336
308 (define build 337 (define build
309 (with-imported-modules (source-module-closure 338 (with-imported-modules (source-module-closure
310 '((guix build utils) 339 '((guix build utils)
@@ -339,6 +368,7 @@ added to the pack."
339 `(,@(map store-info-item 368 `(,@(map store-info-item
340 (call-with-input-file "profile" 369 (call-with-input-file "profile"
341 read-reference-graph)) 370 read-reference-graph))
371 #$environment
342 ,#$output 372 ,#$output
343 373
344 ;; Do not perform duplicate checking because we 374 ;; Do not perform duplicate checking because we
@@ -379,10 +409,19 @@ added to the pack."
379 target))))))) 409 target)))))))
380 '#$symlinks) 410 '#$symlinks)
381 411
412 "-p" "/.singularity.d d 555 0 0"
413
414 ;; Create the environment file.
415 "-p" "/.singularity.d/env d 555 0 0"
416 "-p" ,(string-append
417 "/.singularity.d/env/90-environment.sh s 777 0 0 "
418 (relative-file-name "/.singularity.d/env"
419 #$environment))
420
382 ;; Create /.singularity.d/actions, and optionally the 'run' 421 ;; Create /.singularity.d/actions, and optionally the 'run'
383 ;; script, used by 'singularity run'. 422 ;; script, used by 'singularity run'.
384 "-p" "/.singularity.d d 555 0 0"
385 "-p" "/.singularity.d/actions d 555 0 0" 423 "-p" "/.singularity.d/actions d 555 0 0"
424
386 ,@(if entry-point 425 ,@(if entry-point
387 `(;; This one if for Singularity 2.x. 426 `(;; This one if for Singularity 2.x.
388 "-p" 427 "-p"