Create a Nix expression running a Julia function
Usage
rxp_jl(
name,
jl_expr,
additional_files = "",
nix_env = "default.nix",
serialize_function = NULL,
unserialize_function = NULL,
env_var = NULL
)
Arguments
- name
Symbol, name of the derivation.
- jl_expr
Character, Julia code to generate the expression.
- additional_files
Character vector, additional files to include. Custom functions must go into a script called "functions.jl", and additional files that need to be accessible during the build process can be named anything.
- nix_env
Character, path to the Nix environment file, default is "default.nix".
- serialize_function
Character, defaults to NULL. The name of the Julia function used to serialize the object. It must accept two arguments: the object to serialize (first), and the target file path (second). If NULL, the default behavior uses the built‐in
Serialization.serialize
API. Define any custom serializer infunctions.jl
.- unserialize_function
Character, defaults to NULL. The name of the Julia function used to unserialize the object. It must accept one argument: the file path. If NULL, the default is assumed to be
Serialization.deserialize
.- env_var
Character vector, defaults to NULL. A named vector of environment variables to set before running the Julia script, e.g.,
c("JULIA_DEPOT_PATH" = "/path/to/depot")
. Each entry will be added as anexport
statement in the build phase.
Details
At a basic level,
rxp_jl(filtered_data, "filter(df, :col .> 10)")
is equivalent to
filtered_data = filter(df, :col .> 10)
in Julia. rxp_jl()
generates the
required Nix boilerplate to output a so‐called "derivation" in Nix jargon.
A Nix derivation is a recipe that defines how to create an output (in this
case filtered_data
) including its dependencies, build steps, and output
paths.
See also
Other derivations:
rxp_py()
,
rxp_py_file()
,
rxp_qmd()
,
rxp_r()
,
rxp_r_file()
,
rxp_rmd()
Examples
if (FALSE) { # \dontrun{
# Basic usage, no custom serializer
rxp_jl(
name = filtered_df,
jl_expr = "filter(df, :col .> 10)"
)
# Custom serialization: assume `save_my_obj(obj, path)` is defined in functions.jl
rxp_jl(
name = model_output,
jl_expr = "train_model(data)",
serialize_function = "save_my_obj",
additional_files = "functions.jl"
)
} # }