Skip to content

Support running/evaluating built functions #56

Description

@considerate

Spago assumes a backed has a --run Module.Name.function flag that will execute the given function. This is also how tests are implemented. I think the following snippet is a reasonable implementation for --run in purenix.

mkdir tmp-nix
export NIX_STORE_PATH=$(pwd)/tmp-nix/store
export NIX_DATA_DIR=$(pwd)/tmp-nix/share
export NIX_LOG_DIR=$(pwd)/tmp-nix/log/nix
export NIX_STATE_DIR=$(pwd)/tmp-nix/log/nix
nix-instantiate --eval --readonly-mode -E "let module = import ./output/Test.Main; in module.main null"

This would of course be implemented within Haskell and the module to import as well as the function to evaluate is defined by the flag.

The snippet runs evaluation against a temporary nix store and in readonly-mode so it should be fine run inside a nix build. I've only tested that it does indeed run in the simplest of scenarios so far.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions