-
I am defining the structure of deployments in a flake with flake-parts. It should be:
So far, I've come up to this {
outputs = inputs @ {flake-parts, ...}:
flake-parts.lib.mkFlake {inherit inputs;} {
imports = [
({
config,
flake-parts-lib,
lib,
...
}: let
deploymentType = lib.types.submodule {
options = {
version = lib.mkOption {
type = lib.types.enum ["15.0" "16.0"];
};
spec.filestore.size = lib.mkOption {
default = "5Gi";
type = lib.types.str;
};
spec.replicas = lib.mkOption {
default = 1;
type = lib.types.ints.positive;
};
spec.domains = lib.types.listOf domainType;
};
};
domainType = lib.types.submodule {
options = {
host = lib.mkOption {
type = lib.types.str;
};
secure = lib.mkOption {
default = false;
type = lib.types.bool;
};
};
};
tierType = lib.mkOption {
default = {};
type = lib.types.lazyAttrsOf deploymentType;
};
tiersType = lib.types.submodule {
options = {
development = tierType;
production = tierType;
staging = tierType;
};
};
in {
options.flake = flake-parts-lib.mkSubmoduleOptions {
deployments = lib.mkOption {
default = {};
type = lib.types.lazyAttrsOf tiersType;
};
};
})
];
systems = ["x86_64-linux"];
flake.deployments.development.review15 = {
version = "15.0";
domains = [{host = "review15.example.com";}];
};
};
} flake.lock{
"nodes": {
"flake-parts": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1693611461,
"narHash": "sha256-aPODl8vAgGQ0ZYFIRisxYG5MOGSkIczvu2Cd8Gb9+1Y=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "7f53fdb7bdc5bb237da7fefef12d099e4fd611ca",
"type": "github"
},
"original": {
"id": "flake-parts",
"type": "indirect"
}
},
"nixpkgs-lib": {
"locked": {
"dir": "lib",
"lastModified": 1693471703,
"narHash": "sha256-0l03ZBL8P1P6z8MaSDS/MvuU8E75rVxe5eE1N6gxeTo=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "3e52e76b70d5508f3cec70b882a29199f4d1ee85",
"type": "github"
},
"original": {
"dir": "lib",
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-parts": "flake-parts"
}
}
},
"root": "root",
"version": 7
} However, it's not working. It tells me that ➤ nix eval .#deployments --show-trace
error:
… while evaluating the attribute 'development'
at «none»:0: (source not available)
… while calling anonymous lambda
at /nix/store/3c825qhdxqbnys0s5cxiyawqpj5fbymb-source/lib/types.nix:565:29:
564| merge = loc: defs:
565| zipAttrsWith (name: defs:
| ^
566| let merged = mergeDefinitions (loc ++ [name]) elemType defs;
… from call site
at /nix/store/3c825qhdxqbnys0s5cxiyawqpj5fbymb-source/lib/modules.nix:837:59:
836| if isDefined then
837| if all (def: type.check def.value) defsFinal then type.merge loc defsFinal
| ^
838| else let allInvalid = filter (def: ! type.check def.value) defsFinal;
… while calling 'merge'
at /nix/store/3c825qhdxqbnys0s5cxiyawqpj5fbymb-source/lib/types.nix:762:22:
761| check = x: isAttrs x || isFunction x || path.check x;
762| merge = loc: defs:
| ^
763| (base.extendModules {
error: The option `flake.deployments.development.review15' does not exist. Definition values:
- In `/nix/store/gf4f7napsyjlyr16d1dqb0jgi4bvvp9b-source/flake.nix':
{
domains = [
{
host = "review15.example.com";
}
... How could I fix the interface, so that it allows me to define what I expect? Thanks! |
Beta Was this translation helpful? Give feedback.
Answered by
yajo
Sep 29, 2023
Replies: 1 comment 1 reply
-
Working my way through the attribute path and the types simultaneously, it looks like your definitions should be
or you might have too many |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ah yes, indeed! Thank you, you helped me to find the fix. Applying this diff makes it work: