The issue I'm seeing seems only happens when using a module in a separate file, so it might be me misunderstanding modules. Or maybe it's a bug in kubenix because I'm not doing anything unusual I think.
Here's a repro for the error I'm seeing:
# ==> repro.nix <==
{
nixpkgs ? import <nixpkgs> {},
kubenix ? import (nixpkgs.fetchgit {
url = "https://github.com/xtruder/kubenix/";
rev = "611059a329493a77ec0e862fcce4671cd3768f32";
sha256 = "1lmmzb087ahmx2mdjarbi52a9424qczhzqbxrvcrg11cbmv9b191";
}) {}
}:
rec {
config = (kubenix.evalModules {
modules = [
./module.nix { inherit kubenix; }
];
}).config;
generated = config.kubernetes.generated;
result = config.kubernetes.result;
}
# ==> module.nix <==
{ config, lib, pkgs, kubenix, ... }:
with kubenix.lib;
let exampleYaml = pkgs.writeText "namespace.yaml" ''
apiVersion: v1
kind: Namespace
metadata:
name: default
'';
in
{
imports = with kubenix.modules; [
k8s
];
kubernetes.imports = [
exampleYaml
];
}
If I try to build that kubernetes object, I get:
$ nix-build repro.nix
error: The option `kubenix.buildResources' defined in `<unknown-file>' does not exist.
(use '--show-trace' to show detailed location information)
I think it's related to modules because if I shove it all in one file, like so, then it builds correctly:
{
nixpkgs ? import <nixpkgs> {},
kubenix ? import (nixpkgs.fetchgit {
url = "https://github.com/xtruder/kubenix/";
rev = "611059a329493a77ec0e862fcce4671cd3768f32";
sha256 = "1lmmzb087ahmx2mdjarbi52a9424qczhzqbxrvcrg11cbmv9b191";
}) {}
}:
let exampleYaml = nixpkgs.writeText "namespace.yaml" ''
apiVersion: v1
kind: Namespace
metadata:
name: default
'';
in
rec {
config = (kubenix.evalModules {
modules = [
{
imports = with kubenix.modules; [
k8s
];
kubernetes.imports = [
exampleYaml
];
}
];
}).config;
generated = config.kubernetes.generated;
result = config.kubernetes.result;
}
One other thing to note: after poking through the stacktrace, I realized the inscrutable error may have actually been trying to say "kubenix.project wasn't set".
If I delete the two lines in modules/k8s.nix
that reference config.kubenix.project
(
|
metadata.labels."kubenix/project-name" = config.kubenix.project; |
and line 388), my repro no longer errors out and produces something that works for me.
My totally uneducated understanding is that kubenix.evalModules
is breaking the default for project = "kubenix"
somehow, and when I don't split the module into a separate file, I don't see this issue because I guess I'm using the kubenix from the outer scope anyway? Yeah, I'm not totally sure.