writeGuile
pkgs.writers.writeGuile
Functor
Docs pulled from | This Revision | 10 minutes ago
writeGuile
returns a derivation that creates an executable Guile script.
Inputs
nameOrPath
(String)- Name of or path to the script. The semantics is the same as that of
makeScriptWriter
. config
(AttrSet)-
guile
(Optional, Derivation, Default:pkgs.guile
)- Guile package used for the script.
-
libraries
(Optional, [ Derivation ], Default: [])- Extra Guile libraries exposed to the script.
-
r6rs
andr7rs
(Optional, Boolean, Default: false)- Whether to adapt Guile’s initial environment to better support R6RS/ R7RS. See the Guile Reference Manual for details.
-
srfi
(Optional, [ Int ], Default: [])- SRFI module to be loaded into the interpreter before evaluating a script file or starting the REPL. See the Guile Reference Manual to know which SRFI are supported.
- Other attributes are directly passed to
makeScriptWriter
. content
(String)- Content of the script.
Examples
pkgs.writers.writeGuile
with default config
writeGuile "guile-script" { }
''
(display "Hello, world!")
''
pkgs.writers.writeGuile
with SRFI-1 enabled and extra libraries
writeGuile "guile-script" {
libraries = [ pkgs.guile-semver ];
srfi = [ 1 ];
}
''
(use-modules (semver))
(make-semver 1 (third '(2 3 4)) 5) ; => #<semver 1.4.5>
''
Noogle detected
This is a Functor
Learn about functors
Implementation
The following is the current implementation of this function.
writeGuile =
nameOrPath:
{
guile ? pkgs.guile,
libraries ? [ ],
r6rs ? false,
r7rs ? false,
srfi ? [ ],
...
}@config:
content:
assert builtins.all builtins.isInt srfi;
let
finalGuile = pkgs.buildEnv {
name = "guile-env";
paths = [ guile ] ++ libraries;
passthru = {
inherit (guile) siteDir siteCcacheDir;
};
meta.mainProgram = guile.meta.mainProgram or "guile";
};
in
makeScriptWriter
(
(builtins.removeAttrs config [
"guile"
"libraries"
"r6rs"
"r7rs"
"srfi"
])
// {
interpreter = "${lib.getExe finalGuile} \\";
makeWrapperArgs = [
"--set"
"GUILE_LOAD_PATH"
"${finalGuile}/${finalGuile.siteDir}:${finalGuile}/lib/scheme-libs"
"--set"
"GUILE_LOAD_COMPILED_PATH"
"${finalGuile}/${finalGuile.siteCcacheDir}:${finalGuile}/lib/libobj"
"--set"
"LD_LIBRARY_PATH"
"${finalGuile}/lib/ffi"
"--set"
"DYLD_LIBRARY_PATH"
"${finalGuile}/lib/ffi"
];
}
)
nameOrPath
/**
Spaces, newlines and tabs are significant for the "meta switch" of Guile, so
certain complication must be made to ensure correctness.
*/
(
lib.concatStringsSep "\n" [
(lib.concatStringsSep " " (
[ "--no-auto-compile" ]
++ lib.optional r6rs "--r6rs"
++ lib.optional r7rs "--r7rs"
++ lib.optional (srfi != [ ]) ("--use-srfi=" + concatMapStringsSep "," builtins.toString srfi)
++ [ "-s" ]
))
"!#"
content
]
);