Frolic is a tool for materializing Nix dev shell scripts for lightning-fast direnv switches.
Using direnv and Nix development environments together is a magical combination but can sometimes be suboptimally slow due to evaluation time, especially in larger repos.
Frolic provides a solution to this problem by "materializing" the Bash scripts that Nix generates for your devShells outputs, copying those scripts into the .direnv directory, and then running those scripts directly when you cd into your direnv-enabled directory.
To get started, install the CLI:
nix profile add "https://flakehub.com/f/DeterminateSystems/frolic/0.1"Then make direnv aware of the frolic-extension.sh script by copying it into a directory that direnv is aware of:
cp ./scripts/frolic-extension.sh "${XDG_CONFIG_HOME:-$HOME/.config}/direnv/lib"Tip
As an alternative to manual installation, Frolic also offers a Home Manager module.
With the CLI and direnv extension installed, you can add the frolic directive to your .envrc files, potentially replacing any existing use flake directives:
# .envrc
frolicWith this directive in place, any time you cd into the flake's directory, direnv runs the materialized Bash script for the dev shell without Nix needing to evaluate anything, analogous to resolved store paths in FlakeHub Cache but applied to your local dev shells.
By default, Frolic works with the default dev shell output, but you can specify a different shell by name:
# .envrc
frolic <name>You can also load multiple dev shell outputs:
# .envrc
frolic ci db webTo make Frolic auto-update when your flake changes, which I recommend, use direnv's watch_file directive:
# .envrc
watch_file flake.nix flake.lock
frolicIf you don't use watch_file, you'll need to manually run frolic to update your dev shell script.
In some cases, not everyone working on your project will have Frolic set up.
In that case, you can run Frolic if available or fall back to use flake:
has frolic && frolic || use flakeFrolic also offers a Home Manager module:
# add to your flake inputs
inputs.frolic.url = "https://flakehub.com/f/DeterminateSystems/frolic/0.1";
# add to your Home Manager module list
modules = [
inputs.frolic.homeModules.default
];
# enable in your Home Manager configuration
{
frolic.enable = true;
}