Skip to content

What's the conventional way to pass environment variables to tests? #196

Answered by ipetkov
onsails asked this question in Q&A
Discussion options

You must be logged in to vote

Unfortunately there is no good (secure) way of using secrets within a derivation itself (besides turning off the Nix sandbox) other than using nix build .#whatever --impure. My advice would be to:

  1. use a regular cargo test --no-run derivation which builds but doesn't run the tests. This can be part of your flake checks and get built by default
  2. create a second derivation which uses the artifacts from the first and actually runs the cargo tests (shouldn't need to rebuild because of previous artifacts). Then you can hook up your ci to run MY_SECRET=hunter2 nix build .#mySecondCargoTestDrvWithSecret --impure

As an alternative, cargo nextest's archiving feature could be used to more easily ru…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@onsails
Comment options

Comment options

You must be logged in to vote
1 reply
@onsails
Comment options

Answer selected by onsails
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants