Reproducible direnv setup on NixOS

I wrote a post about setting up direnv in a reproducible way, since the available tutorials contained some imperative steps.

2 Likes

Good effort and to the point. Could be the good start of a series. Some hints:

I believe this line should be the other way around:

$ direnv allow && echo "use nix" > .envrc

Not only will direnv allow fail if there isn’t an .envrc file already in the folder. But also, when you do changes to .envrc, you need to run direnv allow again.

Also, if you want this to be truly reproducible (as in: three years down the line, you will still get the very same binaries in the very same versions when you check out that source), you probably want to use Flakes or something like Niv to pin Nixpkgs.

Alt:

  imports = [ inputs.home-manager.nixosModules.home-manager ];
  home-manager.users.${username}.programs.direnv = {
      enable = true;
      nix-direnv.enable = true;
  };

I escpecially enjoy being able to group devshells in a flake somewhere:

flake.nix:

outputs = {nixpkgs, ...}:
{
  devShells.${system} = {
    "shellA" = pkgs.mkShellNoCC {
    };
    "shellB" = pkgs.mkShellNoCC {
    };
  }
}

.envrc:

use flake ~/flakerepo#shellA

I am currently trying lorri for this purpose.

Hosted by Flying Circus.