Using Your Flake for nix run
Currently when you run nix run nixpkgs#python3
, nix will checkout the latest nixpkgs
and grab python3
.
This poses three potential problems
- Having to redownload nixpkgs is a bit much, especially when we already have it.
- If your package is marked unfree or insecure and you allowed it explicitly in your nix config previously, that exception won’t apply here.
- Overlays will not be applied.
Setting up a Flake Alias
To fix this, we can expose the instance of nixpkgs
that we make in flake.nix
to the nix
CLI.
- Add a new output in
flake.nix
forlegacyPackages
- In your nix configuration, add an entry to the flake registry
I use
p
here as that’s what I use in my config, you can change this to any string (I recommend a short one). - Rebuild and switch
Now, whenever you want to run/shell a package, use p
(or whatever alias you set up) instead of nixpkgs
.
This will use the instance of nixpkgs that your flake exports, with all of your config and overlays applied!