env:rust: Add launch-rust-analyzer, refactor guix hacks functions
This commit is contained in:
parent
b00e6e8bf5
commit
92ec57e351
2 changed files with 56 additions and 44 deletions
7
env.scm
7
env.scm
|
@ -343,7 +343,7 @@ by other environments made."
|
|||
(delete "l" (directory-files "."))
|
||||
(layers-in-use)))))
|
||||
|
||||
(define* (mount-environment env #:optional (tag 'current))
|
||||
(define* (mount-environment env #:key (tag 'current) target)
|
||||
(let* ((name (environment-name env))
|
||||
(metadata-dir (metadata-file name))
|
||||
(tree (environment-tree env))
|
||||
|
@ -361,8 +361,9 @@ by other environments made."
|
|||
(mkdtemp (string-append
|
||||
"/tmp/env/" (symbol->string name)
|
||||
"." pfix ".XXXXXX"))))
|
||||
(merged (let ((f (string-append %env-directory
|
||||
"/" (symbol->string name))))
|
||||
(merged (let ((f (or target
|
||||
(string-append %env-directory
|
||||
"/" (symbol->string name)))))
|
||||
(if (directory-exists? f) f (mkdir-p f))))
|
||||
(upper (mkdtemp* "upper"))
|
||||
(work (mkdtemp* "work"))
|
||||
|
|
91
env/rust.scm
vendored
91
env/rust.scm
vendored
|
@ -1,4 +1,5 @@
|
|||
(define-module (env rust)
|
||||
#:use-module (env)
|
||||
#:use-module (gnu packages)
|
||||
#:use-module (gnu packages base)
|
||||
#:use-module (gnu packages bash)
|
||||
|
@ -10,6 +11,7 @@
|
|||
#:use-module (gnu packages commencement)
|
||||
#:use-module (gnu packages compression)
|
||||
#:use-module (gnu system file-systems)
|
||||
#:use-module (guix build utils)
|
||||
#:use-module (guix download)
|
||||
#:use-module (guix git-download)
|
||||
#:use-module ((guix licenses) #:prefix license:)
|
||||
|
@ -23,7 +25,8 @@
|
|||
#:use-module (ice-9 match)
|
||||
#:use-module (srfi srfi-1)
|
||||
#:export (launch-rustup-environment
|
||||
init-rustup-environment))
|
||||
init-rustup-environment
|
||||
launch-rust-analyzer))
|
||||
|
||||
(define rustup-origin
|
||||
(let ((name "rustup")
|
||||
|
@ -69,36 +72,6 @@
|
|||
0 7))
|
||||
(item rustup-init-script-derivation)))))
|
||||
|
||||
(define* (exec-in-rustup-environment launch cmd #:optional home)
|
||||
(let* ((mappings (if home
|
||||
(list
|
||||
(file-system-mapping
|
||||
(source home)
|
||||
(target "/home/rustup")
|
||||
(writable? #t)))
|
||||
'())))
|
||||
(with-store store
|
||||
(run-with-store store
|
||||
(mlet* %store-monad ((bash (package->derivation bash))
|
||||
(profile (profile-derivation
|
||||
rustup-environment-manifest)))
|
||||
(mbegin %store-monad
|
||||
(built-derivations (list bash profile))
|
||||
(let ((bash-binary (string-append (derivation->output-path bash)
|
||||
"/bin/sh"))
|
||||
(profile-dir (derivation->output-path profile)))
|
||||
(launch #:command cmd
|
||||
#:bash bash-binary
|
||||
#:user "rustup"
|
||||
#:user-mappings mappings
|
||||
#:profile profile-dir
|
||||
#:manifest rustup-environment-manifest
|
||||
#:link-profile? #f
|
||||
#:network? #t
|
||||
#:map-cwd? #f
|
||||
#:emulate-fhs? #t
|
||||
#:nesting? #f))))))))
|
||||
|
||||
(define (call-with-guix-shell-hacks proc)
|
||||
"Overcome several pitfails calling launch-environment/container procedure we
|
||||
aren't supposed to. PROC is passed curried launch-environment/container
|
||||
|
@ -136,16 +109,54 @@ function."
|
|||
;; Why not?
|
||||
(flush-all-ports)))))
|
||||
|
||||
(define* (init-rustup-environment #:optional home)
|
||||
(define* (exec-in-rustup-environment cmd #:key home mappings)
|
||||
(let* ((mappings (append (if home
|
||||
(list (file-system-mapping
|
||||
(source home)
|
||||
(target "/home/rustup")
|
||||
(writable? #t)))
|
||||
'())
|
||||
mappings)))
|
||||
(call-with-guix-shell-hacks
|
||||
(λ (launch)
|
||||
(exec-in-rustup-environment launch
|
||||
'("rustup-init.sh" "-q" "-y")
|
||||
home))))
|
||||
(with-store store
|
||||
(run-with-store store
|
||||
(mlet* %store-monad ((bash (package->derivation bash))
|
||||
(profile (profile-derivation
|
||||
rustup-environment-manifest)))
|
||||
(mbegin %store-monad
|
||||
(built-derivations (list bash profile))
|
||||
(let ((bash-binary (string-append (derivation->output-path bash)
|
||||
"/bin/sh"))
|
||||
(profile-dir (derivation->output-path profile)))
|
||||
(launch #:command cmd
|
||||
#:bash bash-binary
|
||||
#:user "rustup"
|
||||
#:user-mappings mappings
|
||||
#:profile profile-dir
|
||||
#:manifest rustup-environment-manifest
|
||||
#:link-profile? #f
|
||||
#:network? #t
|
||||
#:map-cwd? #f
|
||||
#:emulate-fhs? #t
|
||||
#:nesting? #f))))))))))
|
||||
|
||||
(define* (init-rustup-environment #:optional home)
|
||||
(exec-in-rustup-environment '("rustup-init.sh" "-q" "-y") #:home home))
|
||||
|
||||
(define* (launch-rustup-environment #:optional home)
|
||||
(call-with-guix-shell-hacks
|
||||
(λ (launch)
|
||||
(exec-in-rustup-environment launch
|
||||
'("/bin/sh")
|
||||
home))))
|
||||
(exec-in-rustup-environment '("/bin/sh") #:home home))
|
||||
|
||||
(define* (launch-rust-analyzer env target-name
|
||||
#:key (tag 'current) mappings)
|
||||
(let* ((target (string-append (@@ (env) %env-directory) "/" target-name))
|
||||
(mnt (mount-environment env #:tag tag #:target target)))
|
||||
(exec-in-rustup-environment '("./.cargo/bin/rust-analyzer")
|
||||
#:home (overlay-mount-merged mnt)
|
||||
#:mappings mappings)
|
||||
(sync)
|
||||
(system* "umount" target)
|
||||
(for-each delete-file-recursively
|
||||
(list target
|
||||
(overlay-mount-upper mnt)
|
||||
(overlay-mount-work mnt)))))
|
||||
|
|
Loading…
Reference in a new issue