mirror of
https://codeberg.org/hako/Rosenthal.git
synced 2026-11-29 22:58:06 +00:00
util: nix: Add <nix-wrapper>.
* modules/rosenthal/utils/nix.scm (<nix-wrapper>): New data type. (nix-expressions->profile-build-wrapper, nix-shell-wrapper): Return a value of it. (nix-shell-wrapper->package, with-nix-profile): Use it.
This commit is contained in:
1 file changed
+45
-42
@@ -5,6 +5,7 @@
|
|||||||
;; Guile builtins
|
;; Guile builtins
|
||||||
#:use-module (ice-9 match)
|
#:use-module (ice-9 match)
|
||||||
#:use-module (srfi srfi-1)
|
#:use-module (srfi srfi-1)
|
||||||
|
#:use-module (srfi srfi-9)
|
||||||
#:use-module (srfi srfi-26)
|
#:use-module (srfi srfi-26)
|
||||||
#:use-module (srfi srfi-71)
|
#:use-module (srfi srfi-71)
|
||||||
;; Utilities
|
;; Utilities
|
||||||
@@ -14,12 +15,8 @@
|
|||||||
#:use-module (guix build-system trivial)
|
#:use-module (guix build-system trivial)
|
||||||
;; Guix packages
|
;; Guix packages
|
||||||
#:autoload (gnu packages package-management) (nix)
|
#:autoload (gnu packages package-management) (nix)
|
||||||
#:export (installables->nix-expressions
|
#:export (nix-shell-wrapper
|
||||||
nix-expressions->profile-build-wrapper
|
|
||||||
|
|
||||||
nix-shell-wrapper
|
|
||||||
nix-shell-wrapper->package
|
nix-shell-wrapper->package
|
||||||
|
|
||||||
with-nix-profile))
|
with-nix-profile))
|
||||||
|
|
||||||
;; These search paths may contain incompatible libraries and crash programs
|
;; These search paths may contain incompatible libraries and crash programs
|
||||||
@@ -30,6 +27,7 @@
|
|||||||
;; ENV_VAR
|
;; ENV_VAR
|
||||||
;; '(ENV_VAR . PATH)
|
;; '(ENV_VAR . PATH)
|
||||||
;; '(ENV_VAR . (PATHS ...))
|
;; '(ENV_VAR . (PATHS ...))
|
||||||
|
|
||||||
(define %nix-wrapper-default-exclude-env-paths
|
(define %nix-wrapper-default-exclude-env-paths
|
||||||
'((#f . ("/bin" "/sbin"))
|
'((#f . ("/bin" "/sbin"))
|
||||||
"XDG_DATA_DIRS"
|
"XDG_DATA_DIRS"
|
||||||
@@ -61,8 +59,16 @@
|
|||||||
(_ (list #f)))
|
(_ (list #f)))
|
||||||
%nix-wrapper-default-exclude-env-paths)))
|
%nix-wrapper-default-exclude-env-paths)))
|
||||||
|
|
||||||
(define %nix-wrapper-for-profile?
|
(define-record-type <nix-wrapper>
|
||||||
(make-parameter #f))
|
(nix-wrapper name command file expressions)
|
||||||
|
nix-wrapper?
|
||||||
|
(name nix-wrapper-name) ;string
|
||||||
|
(command nix-wrapper-command) ;string
|
||||||
|
(file nix-wrapper-file) ;file-like object
|
||||||
|
(expressions nix-wrapper-expressions)) ;list of file-like objects
|
||||||
|
|
||||||
|
(define-gexp-compiler (nix-wrapper-compiler (wrapper <nix-wrapper>) system target)
|
||||||
|
(lower-object (nix-wrapper-file wrapper) system #:target target))
|
||||||
|
|
||||||
|
|
||||||
;;;
|
;;;
|
||||||
@@ -198,6 +204,7 @@ in
|
|||||||
'#$paths-to-exclude))))
|
'#$paths-to-exclude))))
|
||||||
#:options '(#:substitutable? #f)))
|
#:options '(#:substitutable? #f)))
|
||||||
|
|
||||||
|
(define wrapper
|
||||||
(program-file "build-nix-profile-nix-wrapper"
|
(program-file "build-nix-profile-nix-wrapper"
|
||||||
(with-imported-modules '((guix build utils))
|
(with-imported-modules '((guix build utils))
|
||||||
#~(begin
|
#~(begin
|
||||||
@@ -212,6 +219,11 @@ in
|
|||||||
(list "--out-link" (car args)))
|
(list "--out-link" (car args)))
|
||||||
"--file" #$profile.nix))))))))
|
"--file" #$profile.nix))))))))
|
||||||
|
|
||||||
|
(nix-wrapper "build-nix-profile-nix-wrapper"
|
||||||
|
"build-nix-profile"
|
||||||
|
wrapper
|
||||||
|
expressions))
|
||||||
|
|
||||||
;; See also https://nix.dev/manual/nix/2.34/command-ref/new-cli/nix3-env-shell.html
|
;; See also https://nix.dev/manual/nix/2.34/command-ref/new-cli/nix3-env-shell.html
|
||||||
(define* (nix-shell-wrapper name
|
(define* (nix-shell-wrapper name
|
||||||
#:optional (installables ".")
|
#:optional (installables ".")
|
||||||
@@ -291,8 +303,11 @@ Examples:
|
|||||||
environment-set)
|
environment-set)
|
||||||
options))
|
options))
|
||||||
|
|
||||||
|
(define wrapper-name
|
||||||
|
(string-append name "-nix-wrapper"))
|
||||||
|
|
||||||
(define wrapper
|
(define wrapper
|
||||||
(program-file (string-append name "-nix-wrapper")
|
(program-file wrapper-name
|
||||||
(with-imported-modules '((guix build utils))
|
(with-imported-modules '((guix build utils))
|
||||||
#~(begin
|
#~(begin
|
||||||
(use-modules (ice-9 match)
|
(use-modules (ice-9 match)
|
||||||
@@ -313,22 +328,23 @@ Examples:
|
|||||||
#$@(ensure-list installables)
|
#$@(ensure-list installables)
|
||||||
"--command" #$@run-command args)))))))
|
"--command" #$@run-command args)))))))
|
||||||
|
|
||||||
(if (%nix-wrapper-for-profile?)
|
(nix-wrapper wrapper-name
|
||||||
(list 'nix-shell-wrapper wrapper installables expression)
|
name
|
||||||
wrapper))
|
wrapper
|
||||||
|
(installables->nix-expressions
|
||||||
|
installables
|
||||||
|
#:expression expression)))
|
||||||
|
|
||||||
(define (nix-shell-wrapper->package wrapper)
|
(define (nix-shell-wrapper->package wrapper)
|
||||||
"Return a package for WRAPPER, file-like object created by 'nix-shell-wrapper'
|
"Return a package for WRAPPER, file-like object created by 'nix-shell-wrapper'
|
||||||
or 'nix-expressions->profile-build-wrapper'. The package will install a command
|
or 'nix-expressions->profile-build-wrapper'. The package will install a command
|
||||||
under its /bin directory, with the same name as WRAPPER.
|
under its /bin directory, with the command name of WRAPPER.
|
||||||
|
|
||||||
Note that packages created by this procedure are not supposed to be used in the
|
Note that packages created by this procedure are not supposed to be used in the
|
||||||
build environment and won't be able to interoperate with other packages in
|
build environment and won't be able to interoperate with other packages in
|
||||||
practice."
|
practice."
|
||||||
(let* ((wrapper-name (program-file-name wrapper))
|
|
||||||
(command (string-drop-right wrapper-name (string-length "-nix-wrapper"))))
|
|
||||||
(package
|
(package
|
||||||
(name wrapper-name)
|
(name (nix-wrapper-name wrapper))
|
||||||
(version "0.0.0")
|
(version "0.0.0")
|
||||||
(source #f)
|
(source #f)
|
||||||
(build-system trivial-build-system)
|
(build-system trivial-build-system)
|
||||||
@@ -337,25 +353,25 @@ practice."
|
|||||||
(with-imported-modules '((guix build utils))
|
(with-imported-modules '((guix build utils))
|
||||||
#~(begin
|
#~(begin
|
||||||
(use-modules (guix build utils))
|
(use-modules (guix build utils))
|
||||||
(let ((dest (string-append #$output "/bin/" #$command)))
|
(let ((dest (string-append #$output "/bin/"
|
||||||
|
#$(nix-wrapper-command wrapper))))
|
||||||
(mkdir-p (dirname dest))
|
(mkdir-p (dirname dest))
|
||||||
(symlink #$wrapper dest))))))
|
(symlink #$wrapper dest))))))
|
||||||
(home-page #f)
|
(home-page #f)
|
||||||
(synopsis #f)
|
(synopsis #f)
|
||||||
(description #f)
|
(description #f)
|
||||||
(license #f))))
|
(license #f)))
|
||||||
|
|
||||||
(define-syntax-rule (with-nix-profile packages)
|
(define (with-nix-profile packages)
|
||||||
"Transform PACKAGES, turning wrappers created by 'nix-shell-wrapper' into
|
"Transform PACKAGES, turning wrappers created by 'nix-shell-wrapper' into
|
||||||
packages, additionally adding a package containing the build-nix-profile script
|
packages, additionally adding a package containing a build-nix-profile script
|
||||||
created for them by 'nix-expressions->profile-build-wrapper'.
|
created for them by 'nix-expressions->profile-build-wrapper'.
|
||||||
|
|
||||||
The build-nix-profile accepts an optional path argument and will symlink the
|
The build-nix-profile script accepts an optional path argument and will symlink
|
||||||
resulted profile to the path.
|
the resulted profile to the path.
|
||||||
|
|
||||||
This macro is intended for use in Guix System and Guix Home package
|
This procedure is intended for use in Guix System and Guix Home package
|
||||||
declarations. Note that calls to 'nix-shell-wrapper' must be in the scope of
|
declarations.
|
||||||
this macro.
|
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
@@ -366,22 +382,9 @@ Example:
|
|||||||
#:environment-set '((\"LANG\" . \"C.UTF-8\"))))
|
#:environment-set '((\"LANG\" . \"C.UTF-8\"))))
|
||||||
%base-packages))
|
%base-packages))
|
||||||
"
|
"
|
||||||
(let ((wrappers
|
(let ((wrappers others (partition nix-wrapper? packages)))
|
||||||
others
|
(append (list (nix-shell-wrapper->package
|
||||||
(partition (match-lambda
|
|
||||||
(('nix-shell-wrapper _ _ _) #t)
|
|
||||||
(_ #f))
|
|
||||||
(parameterize ((%nix-wrapper-for-profile? #t))
|
|
||||||
packages))))
|
|
||||||
`(,(nix-shell-wrapper->package
|
|
||||||
(nix-expressions->profile-build-wrapper
|
(nix-expressions->profile-build-wrapper
|
||||||
(append-map (match-lambda
|
(append-map nix-wrapper-expressions wrappers))))
|
||||||
((_ _ installables expression)
|
(map nix-shell-wrapper->package wrappers)
|
||||||
(installables->nix-expressions
|
others)))
|
||||||
installables #:expression expression)))
|
|
||||||
wrappers)))
|
|
||||||
,@(map (match-lambda
|
|
||||||
((_ wrapper _ _)
|
|
||||||
(nix-shell-wrapper->package wrapper)))
|
|
||||||
wrappers)
|
|
||||||
,@others)))
|
|
||||||
Reference in new issue
Block a user