I don’t what to define the overlay in multiple places (host and container). How can I define once and then apply to both?
flake inputs does not work.
I don’t what to define the overlay in multiple places (host and container). How can I define once and then apply to both?
flake inputs does not work.
{ pkgs, ... }: {
containers.somename.config = { ... }: {
nixpkgs.config.pkgs = pkgs;
# ...
};
}
And make sure not to add pkgs to the container module’s entrypoint args. If you want to split its config, or import it from another file, use imports.
As for your original question:
{ inputs, ... }: {
containers.somename = {
specialArgs = { inherit inputs; };
config = { inputs, ... }: {
# ...
};
};
}
Though that’s kinda redundant if you don’t use imports to add additional modules.
Really thanks! I missed the specialArgs of containers.
Also
nixpkgs.config.pkgs = pkgs;
seems the easiest way to do it
I have to add specialArgs = { inherit pkgs; }; to make it work like this
{ pkgs, ... }: {
containers.somename = {
specialArgs = { inherit pkgs; };
config = { ... }: {
nixpkgs.config.pkgs = pkgs;
# ...
};
};
}
but this warning shows up, whats does it mean?
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.
No you don’t. pkgs remains in scope, there’s no magic here. That can only be true if you actually write this:
{ pkgs, ... }: {
containers.somename.config = { pkgs, ... }: {
nixpkgs.config.pkgs = pkgs;
# ...
};
}
The second pkgs overrides the first, and then causes infinite recursion.
And to that I say:
You shouldn’t use specialArgs to override pkgs because it doesn’t:
Thanks for the explanation, but my code still not using the overlay form the host.
This is the exact code that don’t work without specialArgs:
The container is still using 0-unstable-2026-05-16 (I am using nixos-26.05) and the host use 0-unstable-2026-07-08.
searx.nix
{
pkgs,
lib,
...
}:
let
settings = {
server.port = 8080;
server.bind_address = "0.0.0.0";
server.secret_key = "$SEARX_SECRET_KEY";
engines = [
{
name = "wolframalpha";
shortcut = "wa";
api_key = "$WOLFRAM_API_KEY";
engine = "wolframalpha_api";
}
];
};
in
{
services.searx = {
enable = true;
inherit settings;
};
nixpkgs.overlays = [
(final: prev: {
searxng = prev.searxng.overrideAttrs (
finalAttrs: previousAttrs: {
version = "0-unstable-2026-07-08";
src = prev.fetchFromGitHub {
owner = "searxng";
repo = "searxng";
rev = "1412926f5c80ffabc90719450578eb98fda9e161";
hash = "sha256-w3nXXI2qVFqIsnaYgzsyjDdvQ0nQmQdVMClw2fG2Zmg=";
};
# This preBuild block is copied from searxng package and have some modification
preBuild =
let
versionString = lib.concatStringsSep "." (
map (lib.removePrefix "0") (
builtins.tail (lib.splitString "-" (lib.removePrefix "0-" finalAttrs.version))
)
);
commitAbbrev = builtins.substring 0 8 finalAttrs.src.rev;
in
''
export SEARX_DEBUG="true";
cat > searx/version_frozen.py <<EOF
VERSION_STRING="${versionString}+${commitAbbrev}"
VERSION_TAG="${versionString}+${commitAbbrev}"
DOCKER_TAG="${versionString}-${commitAbbrev}"
GIT_URL="https://github.com/searxng/searxng"
GIT_BRANCH="master"
EOF
'';
}
);
})
];
containers.searxng = {
autoStart = true;
ephemeral = true;
# specialArgs = {inherit pkgs;};
config =
{ lib, ... }:
{
nixpkgs.config.pkgs = pkgs;
networking = {
firewall.enable = false;
useHostResolvConf = lib.mkForce false;
};
services.searx = {
# package = pkgs.searxng;
enable = true;
inherit settings;
};
};
};
}
Version checked by sudo nixos-container root-login searxng and sudo systemctl status searx.
I don’t want to use let in to declare overlays because typically I have a different overlays.nix file to put all the overlays there, not in this searx.nix. I put it together here just for demo.
====================
NOTE:
I just tested again. I have to explicitly stated services.searx.package = pkgs.searxng; inside the container then the container searx use the overlayed version, no specialArgs required.
Interesting; it’s possible that you have to overlay pkgs inside the container as well, though I’m surprised it works that way? Something like:
{
nixpkgs.overlays = config.nixpkgs.overlays;
}
That’s another option.
Yes, confirmed adding nixpkgs.overlays = config.nixpkgs.overlays; is required to make the container use the host’s overlay. Thank you so much!