Keep an existing Nix flake as the environment
This page shows how to keep a repository's Nix flake dev shell as its development environment, activated by reprobuild, without changing the flake.
Before you start
- Install reprobuild and Nix.
- The repository has a
flake.nixwith a dev shell. - Load the shell hook in your shell.
Steps
1. Create the project file
Create repro.nim at the repository root:
import repro_project_dsl
import repro_dsl_stdlib/foreign_env
package projectEnvironment:
devEnv:
useFlakeDevShell()If the repository already has a repro.nim, add the devEnv: block with useFlakeDevShell() to its package instead.
2. Ignore the local activation files
Add .repro/ to .gitignore. reprobuild keeps the activation's local files there.
3. Allow the directory
Allow the directory:
repro allow4. Enter the directory again
Leave the directory and enter it again. The hook activates the flake's dev shell. You do not need direnv.
Use another flake or another shell
Pass flakeRef to useFlakeDevShell:
useFlakeDevShell(flakeRef = "./nix") # a flake in a subdirectory
useFlakeDevShell(flakeRef = ".#ci") # another dev shell of this flakeThe default reference includes the repository's initialised git submodules (.?submodules=1). If the repository declares a submodule that is not initialised, for example in a clone made without --recurse-submodules, reprobuild uses the plain . reference instead: activation succeeds, and the flake does not see that submodule's contents. Run git submodule update --init when the shell needs them.
In a workspace: build against your sibling checkouts
Inside a workspace, a local flake's inputs that refer to repositories you have checked out side by side are pointed at those checkouts automatically, using repro flake override-args. An entry in overrideInputs takes precedence, and workspaceOverrides = false turns the automatic overrides off. If an override cannot be resolved, activation fails instead of using different sources without telling you.
Check that it worked
In the repository, run a tool that only the flake's dev shell provides, with --version.