I’ve been banging my head on this for a week or so, and I wanted to make sure to document it so others wouldn’t bang their heads…
I’ve got a situation where I’m using a flake.nix to describe several machines. Some of these machines should use nonfree packages. As described variously online, nonfree packages in a flake means you must reimport the nixpkgs with a new config because the one imported by the flake described in “inputs” doesn’t have nonfree enabled. I got that far by searching, the basic structure is something like this:
{
description = "A basic NixOS flake";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
# nixpkgs.config.allowUnfreePredicate = pkg : true;
};
outputs = {self, nixpkgs, ...}@inputs:
let pkgs = import nixpkgs { system = "x86_64-linux"; config = {allowUnfree = true; }; lib=nixpkgs.lib; }; in
let
hostfuns = ( (import functions/hostfuns.nix) {inherit nixpkgs pkgs;}); in
{
nixosConfigurations = {
machinea = hostfuns.desktop "machinea";
machineb = hostfuns.desktop "machineb";
...
};
};
}
Ok, so hostfuns is basically a file where I create some functions for making different “types” of machines. In this case the examples “machinea” and “machineb” are configured using the “desktop” function and that’s passed the name of the machine so that machine-specific modules can be loaded.
the desktop function inside hostfuns looks something like this:
{nixpkgs, pkgs} : {
...
desktop = hostname :
nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
# specialArgs = {inherit pkgs;};
modules = [
../base/configuration.nix
../desktop/desktop.nix
../desktop/homenetwork.nix
../host/${hostname}.nix
];
};
}
So, with that line commented out about specialArgs, even though I’ve imported nixpkgs with the config that allows nonfree, things don’t work… It took me a while to figure this out. but when you construct the nixosSystem object and tell it what modules to use, eventually it has to call those modules with some arguments, and you need some way to tell it to call the module with pkgs that corresponds to your non-free package object. So that’s what specialArgs argument to nixosSystem constructor is for.
I found this in the nixos and flakes book.
So far it actually works… but when I do the build I get a message that I don’t understand, perhaps there’s some additional subtlety about how this should be done?
evaluation warning: You have set specialArgs.pkgs, which means that options like nixpkgs.config
and nixpkgs.overlays will be ignored. If you wish to reuse an already created
pkgs, which you know is configured correctly for this NixOS configuration,
please import the `nixosModules.readOnlyPkgs` module from the nixpkgs flake or
`(modulesPath + "/misc/nixpkgs/read-only.nix"), and set `{ nixpkgs.pkgs = <your pkgs>; }`.
This properly disables the ignored options to prevent future surprises.
I’ve been using Nix/NixOS for about 3 weeks, so the fact that I’ve got this far is quite remarkable to me, but I have literally no idea what this message is telling me, and I can’t seem to web-search up any readOnlyPkgs documentation or know if this warning is a real problem or not etc.
Hope this information is helpful to someone in the same boat, and/or that someone can explain that message or if I’m doing something wrong here.
Thanks to everyone in the community for making this stuff possible. Gonna make administering 20 odd machines much easier!