Locally excluding nix flakes when using nix independenly of upstream

What exactly would that .envrc look like? Is this a feature added by the direnv-nix integration thing or am I unaware of a nix environment variable for input overrides?

Asking because I have this exact workflow all over the place, when depending on my own flakes, and being able to skip the constant --override-input invocations would be really handy.

I think it cannot (easily) be done using nix-direnv since it doesn’t have a way to pass flags to the various nix commands used behind the scenes. However, @brendanzab has this in their .envrc:

So a change to

eval "$(nix print-dev-env "$(pwd)/../my-project-flake" —override-input my-project "$(pwd)")"

would apply the override each time the environment is computed.

1 Like

Ahh yeah, it seems I run into:

error: path '/absolute/path/to/my-project' is not a flake (because it doesn't contain a 'flake.nix' file)

Was a cool idea though! Would be nice if you could have a way to override non-flakified inputs somehow.

How do you read the contents of my-project ? for example I want to use flakes for python projects and I am using mach-nix to read requirements.txt file.

        pyEnv = mach.mkPython {
          requirements = builtins.readFile ./requirements.txt;
        };

Here I am getting error that

error: getting status of '/nix/store/zh6zsdpwrcysbiqjm6mripkjjf9wq6wc-source/my-project/requirements.txt': No such file or directory

git add requirements.txt, nix flakes require the file to be in version control if you’re using version control. It does this for reproducibility and so that it can exclude .gitignored files from the store import.

There’s some issues about getting better error messages for that.

the flake.nix is in my my-project-flake

    my-project = {
      url = "/Users/user_name/Developer/my-project";
      flake = false;
2    };

and the requirements.txt in my-project is under version control.

Here the problem is I don’t know how to reference the requirements.txt file from my input to flake.

Ah, then I think you are looking for something like

pyEnv = mach.mkPython {
  requirements = builtins.readFile "${my-project}/requirements.txt";
};

I think this is technically IFD, so naughty, but it should work.

1 Like

Just to suggest another possible workaround. You can also place the flake.nix in another directory and refer to that directory in envrc: use flake ~/projects/myflakes#myproject. Allows me to reuse devshell modules for different projects more easily, but it doesn’t allow me to refer to local project files (afaik).

1 Like

Thanks both of you @TLATER @bobvanderlinden !