Local/personal development tools with flakes?

There’s a way you can do this without disrupting your main flake.lock. It also doesn’t require running nix develop multiple times.

  1. Create subdirectory in your project. Say mkdir extra.
  2. Create a new extra/flake.nix file. Have that flake refer to the main flake.nix as an input.
  3. Add extra/flake.nix and extra/flake.lock to the git index but hide it from your commits.
git add --intent-to-add extra/flake.nix
git update-index --assume-unchanged extra/flake.nix

Here’s what your extra/flake.nix might look like (you could write a cleaner flake, but I hope you get the idea):

{
  description = "Extra";
  inputs.otherFlake.url = "path:..";
  outputs = { self, otherFlake, ... }:
    {
      devShells.x86_64-linux = let
        pkgs = import otherFlake.inputs.nixpkgs { system = "x86_64-linux"; };
      in {
        default = pkgs.mkShell {
          buildInputs =
            otherFlake.outputs.devShells.x86_64-linux.default.buildInputs
            ++ [ pkgs.hello ];
        };
      };
    };
}

Then you can just run nix develop ./extra instead of nix develop . (no direnv required).

5 Likes