Hi all-
I’ve been on a bit of an adventure converting my NixOS configuration to a flake, including my home-manager config. It has mostly worked, but I have run into some issues that I’m not sure how to fully resolve.
As part of my system configuration flake, I declaratively define flake registry entries:
{
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.05";
inputs.nixpkgs-unstable.url = "github:NixOS/nixpkgs";
inputs.home-manager = {
url = "github:nix-community/home-manager/release-22.05";
inputs.nixpkgs.follows = "nixpkgs";
};
inputs.elgato.url = "github:waxlamp/elgato/flakes";
outputs = { self, nixpkgs, nixpkgs-unstable, home-manager, elgato }: {
nixosConfigurations.kahless = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
./configuration.nix
home-manager.nixosModules.home-manager {
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
users.roni = import ./home.nix;
extraSpecialArgs = {
inherit elgato;
};
};
}
# Set up nix registry with nixpkgs flakes.
({ lib, ... }: {
nix.registry.nixpkgs.flake = nixpkgs;
nix.registry.nixpkgs-unstable.flake = nixpkgs-unstable;
nix.registry.elgato.flake = elgato;
})
# Configure nixpkgs.
({ ... }: {
nixpkgs.config = {
allowUnfree = true;
};
})
];
};
};
}
so that I can use the experimental nix
commands, but I’d like to use these same flakes to specify packages in both the configuration.nix
and home.nix
files. As you can see above, I am currently passing the elgato
flake into the home-manager config via extraSpecialArgs
, and I am able to use that flake to install the elgato package.
However, if I similarly pass in nixpkgs
and nixpkgs-unstable
, I cannot install, e.g., spotify
or other unfree packages from those flakes (I get the error message about how to enable unfree packages, etc.). I know I can put nixpkgs.config.allowUnfree = true;
into home.nix, and then use the module’s pkgs
argument to install those packages, but I was hoping to be able to do so directly from my nixpkgs
flake.
So, here are my questions:
-
How is the
pkgs
argument passed into the system flake’s modules? This is largely a question about how the system flake runtime works. If I want finer control (or simply a better understanding) of how thepkgs
argument reaches the modules, what should I do here? This is important because I may also want to install packages from a source other than thepkgs
argument, for example, from mynixpkgs-unstable
flake. - How do I configure these flakes to allow for installing unfree packages from them?
- Is there a better way to pass flakes into my home-manager config than the
extraSpecialArgs
mechanism?
I can share other parts from my config if needed. Thanks!