mirror of
https://codeberg.org/hako/Rosenthal.git
synced 2026-11-29 22:58:06 +00:00
utils: nix: Adjust variable names and docstrings.
This commit is contained in:
1 file changed
+63
-60
@@ -16,7 +16,8 @@
|
|||||||
;; Guix packages
|
;; Guix packages
|
||||||
#:autoload (gnu packages package-management) (nix)
|
#:autoload (gnu packages package-management) (nix)
|
||||||
#:export (nix-shell-wrapper
|
#:export (nix-shell-wrapper
|
||||||
nix-shell-wrapper->package
|
nix-wrapper->package
|
||||||
|
nix-shell-wrapper->package ;alias to nix-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
|
||||||
@@ -40,18 +41,11 @@
|
|||||||
("QML_IMPORT_PATH" . "/lib/qt6/qml")
|
("QML_IMPORT_PATH" . "/lib/qt6/qml")
|
||||||
("QT_PLUGIN_PATH" . ("/lib/qt5/plugins" "/lib/qt6/plugins"))))
|
("QT_PLUGIN_PATH" . ("/lib/qt5/plugins" "/lib/qt6/plugins"))))
|
||||||
|
|
||||||
;; Additional outputs added to the profile we build.
|
;; Additional outputs to add when building the profile.
|
||||||
(define %nix-profile-extra-outputs
|
(define %nix-profile-extra-outputs
|
||||||
'("man" "info"))
|
'("man" "info"))
|
||||||
|
|
||||||
(define %nix-wrapper-default-unset-env-vars
|
(define %nix-profile-default-exclude-paths
|
||||||
(filter-map (match-lambda
|
|
||||||
((? string? env) env)
|
|
||||||
(((? string? env) . _) env)
|
|
||||||
(_ #f))
|
|
||||||
%nix-wrapper-default-exclude-env-paths))
|
|
||||||
|
|
||||||
(define %nix-wrapper-default-exclude-paths
|
|
||||||
(filter identity
|
(filter identity
|
||||||
(append-map (match-lambda
|
(append-map (match-lambda
|
||||||
((_ . (? string? path)) (list path))
|
((_ . (? string? path)) (list path))
|
||||||
@@ -59,6 +53,23 @@
|
|||||||
(_ (list #f)))
|
(_ (list #f)))
|
||||||
%nix-wrapper-default-exclude-env-paths)))
|
%nix-wrapper-default-exclude-env-paths)))
|
||||||
|
|
||||||
|
(define %nix-shell-default-unset-env-vars
|
||||||
|
(filter-map (match-lambda
|
||||||
|
((? string? env) env)
|
||||||
|
(((? string? env) . _) env)
|
||||||
|
(_ #f))
|
||||||
|
%nix-wrapper-default-exclude-env-paths))
|
||||||
|
|
||||||
|
|
||||||
|
;;;
|
||||||
|
;;; Helper utilities to use packages from Nix.
|
||||||
|
;;;
|
||||||
|
|
||||||
|
(define (ensure-list x)
|
||||||
|
(if (list? x)
|
||||||
|
x
|
||||||
|
(list x)))
|
||||||
|
|
||||||
(define-record-type <nix-wrapper>
|
(define-record-type <nix-wrapper>
|
||||||
(nix-wrapper name command file expressions)
|
(nix-wrapper name command file expressions)
|
||||||
nix-wrapper?
|
nix-wrapper?
|
||||||
@@ -70,15 +81,33 @@
|
|||||||
(define-gexp-compiler (nix-wrapper-compiler (wrapper <nix-wrapper>) system target)
|
(define-gexp-compiler (nix-wrapper-compiler (wrapper <nix-wrapper>) system target)
|
||||||
(lower-object (nix-wrapper-file wrapper) system #:target target))
|
(lower-object (nix-wrapper-file wrapper) system #:target target))
|
||||||
|
|
||||||
|
(define (nix-wrapper->package wrapper)
|
||||||
;;;
|
"Return a package for nix-wrapper WRAPPER. The package will install a command
|
||||||
;;; Helper utilities to use packages from Nix.
|
under its /bin directory, with the command name of WRAPPER.
|
||||||
;;;
|
|
||||||
|
|
||||||
(define (ensure-list x)
|
Note that packages created by this procedure are not supposed to be used in the
|
||||||
(if (list? x)
|
build environment and won't be able to interoperate with other packages in
|
||||||
x
|
practice."
|
||||||
(list x)))
|
(package
|
||||||
|
(name (nix-wrapper-name wrapper))
|
||||||
|
(version "0.0.0")
|
||||||
|
(source #f)
|
||||||
|
(build-system trivial-build-system)
|
||||||
|
(arguments
|
||||||
|
(list #:builder
|
||||||
|
(with-imported-modules '((guix build utils))
|
||||||
|
#~(begin
|
||||||
|
(use-modules (guix build utils))
|
||||||
|
(let ((dest (string-append #$output "/bin/"
|
||||||
|
#$(nix-wrapper-command wrapper))))
|
||||||
|
(mkdir-p (dirname dest))
|
||||||
|
(symlink #$wrapper dest))))))
|
||||||
|
(home-page #f)
|
||||||
|
(synopsis #f)
|
||||||
|
(description #f)
|
||||||
|
(license #f)))
|
||||||
|
|
||||||
|
(define nix-shell-wrapper->package nix-wrapper->package)
|
||||||
|
|
||||||
;; Flake output attribute -> Nix expression
|
;; Flake output attribute -> Nix expression
|
||||||
;; https://nix.dev/manual/nix/2.34/command-ref/new-cli/nix.html#flake-output-attribute
|
;; https://nix.dev/manual/nix/2.34/command-ref/new-cli/nix.html#flake-output-attribute
|
||||||
@@ -142,12 +171,12 @@ optional and interpreted as attribute paths relative to the Nix expression."
|
|||||||
(define* (nix-expressions->profile-build-wrapper
|
(define* (nix-expressions->profile-build-wrapper
|
||||||
expressions
|
expressions
|
||||||
#:key
|
#:key
|
||||||
(paths-to-exclude %nix-wrapper-default-exclude-paths)
|
(paths-to-exclude %nix-profile-default-exclude-paths)
|
||||||
(extra-outputs-to-install %nix-profile-extra-outputs)
|
(extra-outputs-to-install %nix-profile-extra-outputs)
|
||||||
(nixpkgs-commit "714a5f8c4ead6b31148d829288440ed033ccc041")
|
(nixpkgs-commit "714a5f8c4ead6b31148d829288440ed033ccc041")
|
||||||
(nix (file-append nix "/bin/nix")))
|
(nix (file-append nix "/bin/nix")))
|
||||||
"Return a file-like object that wraps the \"nix build\" command-line utility
|
"Return a nix-wrapper that wraps the \"nix build\" command-line utility and
|
||||||
and builds a Nix profile if run. Nix daemon is required to use the wrapper.
|
builds a Nix profile if run. Nix daemon is required to use the wrapper.
|
||||||
|
|
||||||
The wrapper accepts an optional path argument and will symlink the resulted
|
The wrapper accepts an optional path argument and will symlink the resulted
|
||||||
profile to the path.
|
profile to the path.
|
||||||
@@ -156,7 +185,7 @@ EXPRESSIONS (list of strings / list of G-expressions) can be formatted from
|
|||||||
'installables->nix-expressions' and specifies packages to be added into the
|
'installables->nix-expressions' and specifies packages to be added into the
|
||||||
profile.
|
profile.
|
||||||
|
|
||||||
PATHS-TO-EXCLUDE (default: %nix-wrapper-default-exclude-paths, list of strings)
|
PATHS-TO-EXCLUDE (default: %nix-profile-default-exclude-paths, list of strings)
|
||||||
excludes subdirectories from being added into the profile.
|
excludes subdirectories from being added into the profile.
|
||||||
|
|
||||||
EXTRA-OUTPUTS-TO-INSTALL (default: %nix-build-profile-extra-outputs, list of
|
EXTRA-OUTPUTS-TO-INSTALL (default: %nix-build-profile-extra-outputs, list of
|
||||||
@@ -231,12 +260,12 @@ in
|
|||||||
(run-command '())
|
(run-command '())
|
||||||
(options '())
|
(options '())
|
||||||
(environment-keep #t)
|
(environment-keep #t)
|
||||||
(environment-unset %nix-wrapper-default-unset-env-vars)
|
(environment-unset %nix-shell-default-unset-env-vars)
|
||||||
(environment-set '())
|
(environment-set '())
|
||||||
(nix (file-append nix "/bin/nix")))
|
(nix (file-append nix "/bin/nix")))
|
||||||
"Return a file-like object that wraps the \"nix shell\" command-line utility
|
"Return a nix-wrapper that wraps the \"nix shell\" command-line utility and
|
||||||
and spawns an one-off software environment if run. Nix daemon is required to
|
spawns an one-off software environment if run. Nix daemon is required to use
|
||||||
use the wrapper.
|
the wrapper.
|
||||||
|
|
||||||
INSTALLABLES (string / list of strings) is specified as Flake output attribute
|
INSTALLABLES (string / list of strings) is specified as Flake output attribute
|
||||||
and will be added into the environment. When EXPRESSION (string / file-like
|
and will be added into the environment. When EXPRESSION (string / file-like
|
||||||
@@ -254,7 +283,7 @@ When ENVIRONMENT-KEEP (default: #t, boolean / list of strings) is set to a value
|
|||||||
other than #t, the environment will be cleared, keeping only specified
|
other than #t, the environment will be cleared, keeping only specified
|
||||||
environment variables.
|
environment variables.
|
||||||
|
|
||||||
ENVIRONMENT-UNSET (default: %nix-wrapper-default-unset-env-vars, list of
|
ENVIRONMENT-UNSET (default: %nix-shell-default-unset-env-vars, list of
|
||||||
strings) unsets specified environment variables from the environment. It's only
|
strings) unsets specified environment variables from the environment. It's only
|
||||||
usable when ENVIRONMENT-KEEP is #t.
|
usable when ENVIRONMENT-KEEP is #t.
|
||||||
|
|
||||||
@@ -335,43 +364,17 @@ Examples:
|
|||||||
installables
|
installables
|
||||||
#:expression expression)))
|
#:expression expression)))
|
||||||
|
|
||||||
(define (nix-shell-wrapper->package 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
|
|
||||||
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
|
|
||||||
build environment and won't be able to interoperate with other packages in
|
|
||||||
practice."
|
|
||||||
(package
|
|
||||||
(name (nix-wrapper-name wrapper))
|
|
||||||
(version "0.0.0")
|
|
||||||
(source #f)
|
|
||||||
(build-system trivial-build-system)
|
|
||||||
(arguments
|
|
||||||
(list #:builder
|
|
||||||
(with-imported-modules '((guix build utils))
|
|
||||||
#~(begin
|
|
||||||
(use-modules (guix build utils))
|
|
||||||
(let ((dest (string-append #$output "/bin/"
|
|
||||||
#$(nix-wrapper-command wrapper))))
|
|
||||||
(mkdir-p (dirname dest))
|
|
||||||
(symlink #$wrapper dest))))))
|
|
||||||
(home-page #f)
|
|
||||||
(synopsis #f)
|
|
||||||
(description #f)
|
|
||||||
(license #f)))
|
|
||||||
|
|
||||||
(define (with-nix-profile packages)
|
(define (with-nix-profile packages)
|
||||||
"Transform PACKAGES, turning wrappers created by 'nix-shell-wrapper' into
|
"Transform PACKAGES, turning nix-wrapper into packages, additionally adding a
|
||||||
packages, additionally adding a package containing a build-nix-profile script
|
new package containing a build-nix-profile script created for them by
|
||||||
created for them by 'nix-expressions->profile-build-wrapper'.
|
'nix-expressions->profile-build-wrapper'.
|
||||||
|
|
||||||
The build-nix-profile script accepts an optional path argument and will symlink
|
The build-nix-profile script accepts an optional path argument and will symlink
|
||||||
the resulted profile to the path.
|
the resulted profile to the path.
|
||||||
|
|
||||||
This procedure 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.
|
declarations, to be used with services nix-search-paths-service-type and
|
||||||
|
home-nix-search-paths-service-type.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
@@ -383,8 +386,8 @@ Example:
|
|||||||
%base-packages))
|
%base-packages))
|
||||||
"
|
"
|
||||||
(let ((wrappers others (partition nix-wrapper? packages)))
|
(let ((wrappers others (partition nix-wrapper? packages)))
|
||||||
(append (list (nix-shell-wrapper->package
|
(append (list (nix-wrapper->package
|
||||||
(nix-expressions->profile-build-wrapper
|
(nix-expressions->profile-build-wrapper
|
||||||
(append-map nix-wrapper-expressions wrappers))))
|
(append-map nix-wrapper-expressions wrappers))))
|
||||||
(map nix-shell-wrapper->package wrappers)
|
(map nix-wrapper->package wrappers)
|
||||||
others)))
|
others)))
|
||||||
Reference in new issue
Block a user