Apologies for the noob question, I just started using nix.
But the documentation doesn't explain it. And the AI didn't either (not in a way that made sense).
Also, why do I keep have to repeat nixpkgs
in every command ? Can't I set it as the default somewhere and be done with it ?
Many thanks!
ps.: I was recommended to map nixpkgs
to the NixOS unstable version in the registry -- I'm using nix on a Ubuntu box.
Don't worry, legacyPackages
doesn’t mean the packages themselves are outdated. It's called legacy because it doesn't use the flake package structure, but instead the old system we used for packages before flakes were a thing. The older system without flakes can introduce impurities and unpredictable builds. While the newer system with flakes explicitly declares all dependencies, ensuring fully reproducible builds.
Instead of nix search nixpkgs
, people recommend using search.nixos.org to find packages.
Or if you really want to stay in the CLI you can use this command:
nix search nixpkgs [your package] 2>/dev/null| sed -e 's|legacy.*linux\.||'
Also, why do I keep have to repeat nixpkgs in every command ? Can't I set it as the default somewhere and be done with it ?
An even better way would be using an alias or function. You can add this function to your .bashrc
or .zshrc
:
nixsearch() {
nix search nixpkgs "$@" 2>/dev/null | sed -E 's/legacyPackages\.[a-z0-9_\-]+\.//'
}
If your using home-manager the same thing can be done like this:
programs.zsh = {
enable = true;
initExtra = # bash
''
nixsearch() {
nix search nixpkgs "$@" 2>/dev/null | sed -E 's/legacyPackages\.[a-z0-9_\-]+\.//'
}
'';
};