I’m at my wit’s end trying to understand why I get this error.
error: The option `containers.rev-proxy.services.log2ban-hammer' does not exist. Definition values:
- In `/nix/store/giacnj560kxrspb2ccwf8s4m05ikska1-source/nixos/modules/virtualisation/nixos-containers.nix':
{
enable = true;
redis = {
host = "127.0.0.1";
};
...
Yet, I can use that service in the configuration.nix (root?).
# /etc/nixos/configuration.nix
{ config, pkgs, ... }: {
imports = ...;
networking = ...;
services.log2ban-hammer = {
enable = true;
redis.host = "127.0.0.1";
};
...
}
The setup
I converted NixOS server A to use nix flakes, thusly.
# /etc/nixos/flake.nix
{
description = "server A config";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.05-small";
log2ban = {
url = "git+https://gitea.local/boxofrox/log2ban";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, deploy-rs, log2ban, ... }:
let
system = "x86_64-linux";
inherit (nixpkgs) lib;
pkgs = import nixpkgs { inherit system; };
in {
nixosConfigurations.server-a = lib.nixosSystem {
inherit system;
modules = [
log2ban.nixosModules.${system}.log2ban-hammer
({ pkgs, ... }: {
nixpkgs.overlays = [ (final: prev: { log2ban = log2ban.packages.${system}.default; }) ];
})
./configuration.nix
];
};
};
}
The container on server A is created like so:
# /etc/nixos/configuration.nix
{ config, pkgs, ... }: {
imports = [
./containers/rev-proxy/default.nix
];
networking = ...;
...
}
# /etc/nixos/containers/rev-proxy/default.nix
{ ... }: {
containers.rev-proxy = {
autoStart = true;
config = { pkgs, ... }: {
imports = [ ];
networking.firewall = {
enable = true;
allowedTCPPorts = [ 80 443 ];
};
services.log2ban-hammer = {
enable = true;
redis.host = "127.0.0.1";
};
system.stateVersion = "22.05";
};
};
}
So, if the configuration.nix can use services.log2ban-hammer, then the import of the log2ban.nixosModule in the flake.nix put the module in what I presume is the “nixpkgs environment”, so what must I do to get the module in the container’s “nixpkgs environment”?
My main reason for using the flake.outputs.nixosConfigurations.<name>.modules was to use the system var defined in the flake instead of trying to snatch the value from pkgs, lib, or config, inside the configuration.nix, and mucking something up.
This behavior is not intuitive to me, and even less intuitive is trying to decipher what things are in nix without a type system to describe what things are expected to look like.