query
On this page

makeScriptWriter

pkgs.writers.makeScriptWriter

Functor
Docs pulled from | This Revision | about 9 hours ago


makeScriptWriter returns a derivation which creates an executable script.

Inputs

config (AttrSet)
interpreter (String)
the interpreter to use for the script.
check (String)
A command to check the script. For example, this could be a linting check.
makeWrapperArgs (Optional, [ String ], Default: [])
Arguments forwarded to (makeWrapper)[#fun-makeWrapper].
nameOrPath (String)
The name of the script or the path to the script. When a string starting with "/" is passed, the script will be created at the specified path in $out. I.e. "/bin/hello" will create a script at $out/bin/hello. Any other string is interpreted as a filename. It must be a POSIX filename starting with a letter, digit, dot, or underscore. Spaces or special characters are not allowed.
content (String)
The content of the script.

This function is used as base implementation for other high-level writer functions.

For example, writeBash can (roughly) be implemented as:

writeBash = makeScriptWriter { interpreter = "${pkgs.bash}/bin/bash"; }

Examples

pkgs.writers.makeScriptWriter dash example

:b makeScriptWriter { interpreter = "${pkgs.dash}/bin/dash"; } "hello" "echo hello world"
-> /nix/store/indvlr9ckmnv4f0ynkmasv2h4fxhand0-hello

The above example creates a script named hello that outputs hello world when executed.

> /nix/store/indvlr9ckmnv4f0ynkmasv2h4fxhand0-hello
hello world

pkgs.writers.makeScriptWriter python example

:b makeScriptWriter { interpreter = "${pkgs.python3}/bin/python"; } "python-hello" "print('hello world')"
-> /nix/store/4kvby1hqr45ffcdrvfpnpj62hanskw93-python-hello
> /nix/store/4kvby1hqr45ffcdrvfpnpj62hanskw93-python-hello
hello world

Noogle also knows

This is a Functor

Learn about functors