I looked this up but only found a bunch of posts asking how to fix specific users configurations which are hard to follow along with, and none of them provide a complete example for someone to copy. Searching for examples as well as asking LLMs didn’t yield results either (the examples showed dev shells and derivations, which seem to be overkill). When trying I got errors like duplicate formal function argument 'pkgs' and expected a set but found a function: «lambda.
I wont share my config, I think it would be much better for someone to post a working example of everything to specify in flake.nix and configuration.nix.
# configuration.nix
{ pkgs, flake-inputs, ... }: {
environment.systemPackages = [
flake-inputs.nixpkgs-unstable.legacyPackages.${pkgs.stdenv.hostPlatform.system}.bar
];
# All your other config
}
Note that your settings from nixpkgs.config wil not apply to the unstable instance. If you want to use unfree packages from unstable, use nixpkgs-unfree. This is just a limitation of flakes, they need to be redesigned to be able to handle that specific use case properly.
You can technically use import, since a flake resolves to its path in /nix/store, and nixpkgs happens to contain a default.nix that does what you’d expect, but at that point you’re bypassing the entire flake concept and should just switch to npins.
I’ll also point out that, depending on your use case, overriding the source of the package you’d like to use from unstable is often a better idea than to do multi-nixpkgs setups.
TBH if you only are using this for nixos-unstable it’s fine, especially if you might have other flake inputs. This is also basically what nixpkgs-unfree does, but with a nicer interface.
If you use ALL your inputs like this definitely use npins though. Or Nixtamal as that seems to be the cool new thing in non-flake inputs pinning.
in a NixOS module somewhere instead of setting specialArgs.flake-inputs = inputs; so you can do inputs'.nixpkgs-unstable.legacyPackages.bar and remove the ${pkgs.stdenv.hostPlatform.system} bit.
Yep, I agree that’s pretty reasonable, though it does obfuscate a bit what’s going on. If you grokked the code I shared, adding that does indeed save you a bit of typing - the pkgs.stdenv.hostPlatform thing can get super annoying.