Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support running/evaluating built functions #56

Open
considerate opened this issue May 5, 2023 · 2 comments
Open

Support running/evaluating built functions #56

considerate opened this issue May 5, 2023 · 2 comments

Comments

@considerate
Copy link
Member

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.

@jonascarpay
Copy link
Member

What's the reasoning behind isolating the store this much? Why not just use the global store?

@considerate
Copy link
Member Author

Isolating the store might not be necessary in the general sense. I’m trying to support running tests within a nix derivation, hence the need for the isolation. The last line (without readonly-mode) is likely the thing that purenix should do and the rest should be provided by a wrapper to support the tests in nix use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants