forked from Fediversity/Fediversity
Compare commits
6 commits
main
...
data-model
Author | SHA1 | Date | |
---|---|---|---|
34529a7de4 | |||
6c2022d064 | |||
f51462afc9 | |||
fefcd93bc1 | |||
c1f3aa6aed | |||
8b2ee21dbe |
2 changed files with 195 additions and 41 deletions
|
@ -11,35 +11,61 @@ let
|
||||||
}).config;
|
}).config;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
_class = "nix-unit";
|
||||||
|
|
||||||
test-eval = {
|
test-eval = {
|
||||||
expr =
|
expr =
|
||||||
let
|
let
|
||||||
example = eval {
|
example = eval (
|
||||||
runtime-environments.bar.nixos = {
|
{ config, ... }:
|
||||||
module =
|
{
|
||||||
|
runtime-configurations.single-ssh-host =
|
||||||
{ ... }:
|
{ ... }:
|
||||||
{
|
{
|
||||||
system.stateVersion = "25.05";
|
system.stateVersion = "25.05";
|
||||||
};
|
};
|
||||||
};
|
runtime-environments.bar = {
|
||||||
applications.foo = {
|
single-ssh-host = {
|
||||||
module =
|
ssh = {
|
||||||
{ pkgs, ... }:
|
host = "localhost";
|
||||||
{
|
username = "root";
|
||||||
environment.systemPackages = [
|
authentication.password = "";
|
||||||
pkgs.hello
|
};
|
||||||
];
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
applications.foo = {
|
||||||
|
module =
|
||||||
|
{ pkgs, ... }:
|
||||||
|
{
|
||||||
|
environment.systemPackages = [
|
||||||
|
pkgs.hello
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
deployments.baz = {
|
||||||
|
module = { };
|
||||||
|
runtime-environment = config.runtime-environments.bar;
|
||||||
|
};
|
||||||
|
migrations.boo = {
|
||||||
|
deployment = config.deployments.baz;
|
||||||
|
runtime-environment = config.runtime-environments.bar;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
has-runtime = lib.isAttrs example.runtime-environments.bar.nixos.module;
|
has-runtime-configuration = lib.isAttrs example.runtime-configurations.single-ssh-host;
|
||||||
|
has-runtime-environment = lib.isAttrs example.runtime-environments.bar.single-ssh-host.module;
|
||||||
has-application = lib.isAttrs example.applications.foo.module;
|
has-application = lib.isAttrs example.applications.foo.module;
|
||||||
|
has-deployment = lib.isAttrs example.deployments.baz.module;
|
||||||
|
has-migration = lib.isAttrs example.migrations.boo.deployment;
|
||||||
};
|
};
|
||||||
expected = {
|
expected = {
|
||||||
has-runtime = true;
|
has-runtime-configuration = true;
|
||||||
|
has-runtime-environment = true;
|
||||||
has-application = true;
|
has-application = true;
|
||||||
|
has-deployment = true;
|
||||||
|
has-migration = true;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,43 +1,171 @@
|
||||||
{
|
{
|
||||||
lib,
|
lib,
|
||||||
|
config,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
inherit (lib) types mkOption;
|
inherit (lib)
|
||||||
in
|
attrNames
|
||||||
with types;
|
mapAttrs
|
||||||
{
|
mkOption
|
||||||
options = {
|
genAttrs
|
||||||
runtime-environments = mkOption {
|
;
|
||||||
description = "Collection of runtime environments into which applications can be deployed";
|
inherit (lib.types)
|
||||||
type = attrsOf (attrTag {
|
attrsOf
|
||||||
nixos = mkOption {
|
attrTag
|
||||||
description = "A single NixOS machine";
|
deferredModule
|
||||||
|
mergeTypes
|
||||||
|
nullOr
|
||||||
|
submoduleWith
|
||||||
|
submodule
|
||||||
|
str
|
||||||
|
;
|
||||||
|
runtime-configuration = mkOption {
|
||||||
|
description = "The NixOS module of a run-time environment";
|
||||||
|
type = deferredModule;
|
||||||
|
default = {
|
||||||
|
_class = "nixos";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
runtime-environment = attrTag (
|
||||||
|
mapAttrs
|
||||||
|
(
|
||||||
|
name:
|
||||||
|
option@{ type, ... }:
|
||||||
|
mkOption (
|
||||||
|
option
|
||||||
|
// {
|
||||||
|
type = mergeTypes type (submodule {
|
||||||
|
options.module = mkOption {
|
||||||
|
description = "The NixOS module of the run-time environment";
|
||||||
|
type = deferredModule;
|
||||||
|
default = config.runtime-configurations.${name};
|
||||||
|
readOnly = true;
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
vm = {
|
||||||
|
description = "A VM to deploy to.";
|
||||||
type = submodule {
|
type = submodule {
|
||||||
options = {
|
options = {
|
||||||
module = mkOption {
|
};
|
||||||
description = "The NixOS module describing the base configuration for that machine";
|
};
|
||||||
type = deferredModule;
|
};
|
||||||
|
single-ssh-host = {
|
||||||
|
description = "A single host to deploy to by SSH.";
|
||||||
|
type = submodule {
|
||||||
|
options = {
|
||||||
|
ssh = mkOption {
|
||||||
|
description = "SSH connection info";
|
||||||
|
type = submodule {
|
||||||
|
options = {
|
||||||
|
host = mkOption {
|
||||||
|
description = "the host to access by SSH";
|
||||||
|
type = str;
|
||||||
|
};
|
||||||
|
username = mkOption {
|
||||||
|
description = "the SSH user to use";
|
||||||
|
type = nullOr str;
|
||||||
|
default = null;
|
||||||
|
};
|
||||||
|
authentication = mkOption {
|
||||||
|
description = "authentication method";
|
||||||
|
type = attrsOf (attrTag {
|
||||||
|
private-key = mkOption {
|
||||||
|
description = "path to the user's SSH private key";
|
||||||
|
type = str;
|
||||||
|
example = "/root/.ssh/id_ed25519";
|
||||||
|
};
|
||||||
|
password = mkOption {
|
||||||
|
description = "SSH password";
|
||||||
|
# TODO: mark as sensitive
|
||||||
|
type = str;
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
application = submoduleWith {
|
||||||
|
description = "A Fediversity application";
|
||||||
|
modules = [
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
module = mkOption {
|
||||||
|
description = "The NixOS module for that application, for configuring that application";
|
||||||
|
type = deferredModule;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
deployment = submoduleWith {
|
||||||
|
description = "A deployment of a configuration of applications to a run-time environment";
|
||||||
|
modules = [
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
# the `applications` option consists of configuration for the above applications
|
||||||
|
module = mkOption {
|
||||||
|
description = ''
|
||||||
|
Configuration to be deployed
|
||||||
|
'';
|
||||||
|
type = deferredModule;
|
||||||
|
};
|
||||||
|
runtime-environment = mkOption {
|
||||||
|
description = "The run-time environment to deploy to";
|
||||||
|
type = runtime-environment;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
migration = submoduleWith {
|
||||||
|
description = "Migration of a Fediversity deployment to a Fediversity run-time environment";
|
||||||
|
modules = [
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
deployment = mkOption {
|
||||||
|
description = "Deployment to migrate";
|
||||||
|
type = deployment;
|
||||||
|
};
|
||||||
|
runtime-environment = mkOption {
|
||||||
|
description = "Run-time environment to migrate the deployment to";
|
||||||
|
type = runtime-environment;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
runtime-configurations = mkOption {
|
||||||
|
description = "Collection of runtime environments into which applications can be deployed";
|
||||||
|
type = attrTag (genAttrs (attrNames runtime-environment.nestedTypes) (_: runtime-configuration));
|
||||||
|
};
|
||||||
|
runtime-environments = mkOption {
|
||||||
|
description = "Collection of runtime environments into which applications can be deployed";
|
||||||
|
type = attrsOf runtime-environment;
|
||||||
};
|
};
|
||||||
applications = mkOption {
|
applications = mkOption {
|
||||||
description = "Collection of Fediversity applications";
|
description = "Collection of Fediversity applications";
|
||||||
type = attrsOf (submoduleWith {
|
type = attrsOf application;
|
||||||
modules = [
|
};
|
||||||
{
|
deployments = mkOption {
|
||||||
options = {
|
description = "Deployment of a configuration of applications to a run-time environment";
|
||||||
module = mkOption {
|
type = attrsOf deployment;
|
||||||
description = "The NixOS module for that application, for configuring that application";
|
};
|
||||||
type = deferredModule;
|
migrations = mkOption {
|
||||||
};
|
description = "Migrations from Fediversity deployments to Fediversity run-time environments";
|
||||||
};
|
type = attrsOf migration;
|
||||||
}
|
|
||||||
];
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue