Does `nix develop --redirect` work at the flake or derivation level?

Hello all,

The --redirect option of nix develop looks helpful for when developers are working on local copies of repos. However I’m not quite clear on what it’s doing behind-the-scenes. Does it work at the level of the derivation, or the flake?

We are using a single flake to package up multiple derivations - if I do, say nix develop .#pkgA --redirect .#baseLevelDependency ./base_level_dependency, will this apply just to pkgA, or will it also apply to pkgB, pkgC and other packages in the flake that depend upon baseLevelDependency?


Hello @harris-chris, it works at the derivation level. For the flake level, you would probably want --override-input or something like that.

How nix develop --redirect works is simple. Before entering the development shell it will calculate the store path of .#baseLevelDependency (as per nix path-info). Then it will search through the shell environment and replace all instances of that store path with (the absolute path of) ./base_level_dependency. Then it will start bash using that environment.

The redirection will only apply to the environment of the shell process started by nix develop. It won’t rebuild the pkgB and pkgC derivations to use the redirected baseLevelDependency.

I assume that you have a dependency tree like this:

├── pkgA
│   ├── baseLevelDependency
│   ├── pkgB
│   │   └── baseLevelDependency
│   └── pkgC
│   │   └── baseLevelDependency
└── ...

For this flake project, I suspect what you need is a single devShell which includes the combined dependencies of baseLevelDependency, pkgA, pkgB, and pkgC all together. Then you can check out local source trees of each package and use your normal build tools to configure, build, and install each package to a custom prefix in your home directory, while making changes and rebuilding any or all of these packages.