forked from Fediversity/Fediversity
Compare commits
11 commits
main
...
data-model
Author | SHA1 | Date | |
---|---|---|---|
1d519dceab | |||
dbd3e90238 | |||
7906e9fc92 | |||
d135c94afa | |||
c764c0f7b6 | |||
34529a7de4 | |||
6c2022d064 | |||
f51462afc9 | |||
fefcd93bc1 | |||
c1f3aa6aed | |||
8b2ee21dbe |
4 changed files with 221 additions and 45 deletions
19
deployment/applications/default.nix
Normal file
19
deployment/applications/default.nix
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
{
|
||||||
|
lib,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
applications = [
|
||||||
|
"mastodon"
|
||||||
|
];
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options = lib.genAttrs applications (
|
||||||
|
k:
|
||||||
|
# TODO: how to type entries here to conform to some common structure?
|
||||||
|
lib.mkOption {
|
||||||
|
description = "configuration options for ${k}";
|
||||||
|
type = lib.types.submodule ./${k};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
19
deployment/applications/mastodon/default.nix
Normal file
19
deployment/applications/mastodon/default.nix
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
{
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
{
|
||||||
|
options =
|
||||||
|
{
|
||||||
|
fediversity.domain = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "fediversity.tld";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// import ../../../services/fediversity/sharedOptions.nix {
|
||||||
|
inherit config lib;
|
||||||
|
serviceName = "mastodon";
|
||||||
|
serviceDocName = "Mastodon";
|
||||||
|
};
|
||||||
|
}
|
|
@ -11,35 +11,55 @@ 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 =
|
let
|
||||||
|
inherit (config.resources.bar.runtime-environment) runtime-environment;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
providers.ssh-host =
|
||||||
{ ... }:
|
{ ... }:
|
||||||
{
|
{
|
||||||
system.stateVersion = "25.05";
|
system.stateVersion = "25.05";
|
||||||
};
|
};
|
||||||
};
|
resources.bar.runtime-environment.ssh-host = {
|
||||||
applications.foo = {
|
ssh = {
|
||||||
module =
|
host = "localhost";
|
||||||
{ pkgs, ... }:
|
username = "root";
|
||||||
{
|
authentication.password = "";
|
||||||
environment.systemPackages = [
|
|
||||||
pkgs.hello
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
deployments.baz = {
|
||||||
|
inherit runtime-environment;
|
||||||
|
application-configuration = {
|
||||||
|
mastodon = {
|
||||||
|
enable = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
migrations.boo = {
|
||||||
|
inherit runtime-environment;
|
||||||
|
deployment = config.deployments.baz;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
has-runtime = lib.isAttrs example.runtime-environments.bar.nixos.module;
|
has-provider = lib.isAttrs example.providers.ssh-host;
|
||||||
has-application = lib.isAttrs example.applications.foo.module;
|
has-resource = lib.isAttrs example.resources.bar.runtime-environment.ssh-host.module;
|
||||||
|
has-deployment = example.deployments.baz.application-configuration.mastodon.enable == true;
|
||||||
|
has-migration = lib.isAttrs example.migrations.boo.deployment;
|
||||||
};
|
};
|
||||||
expected = {
|
expected = {
|
||||||
has-runtime = true;
|
has-provider = true;
|
||||||
has-application = true;
|
has-resource = true;
|
||||||
|
has-deployment = true;
|
||||||
|
has-migration = true;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,43 +1,161 @@
|
||||||
{
|
{
|
||||||
lib,
|
lib,
|
||||||
|
config,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
inherit (lib) types mkOption;
|
applications = ./applications; # how to make this configurable?
|
||||||
in
|
inherit (lib)
|
||||||
with types;
|
attrNames
|
||||||
{
|
mapAttrs
|
||||||
options = {
|
mkOption
|
||||||
runtime-environments = mkOption {
|
genAttrs
|
||||||
description = "Collection of runtime environments into which applications can be deployed";
|
;
|
||||||
type = attrsOf (attrTag {
|
inherit (lib.types)
|
||||||
nixos = mkOption {
|
attrsOf
|
||||||
description = "A single NixOS machine";
|
attrTag
|
||||||
|
deferredModule
|
||||||
|
mergeTypes
|
||||||
|
nullOr
|
||||||
|
submoduleWith
|
||||||
|
submodule
|
||||||
|
str
|
||||||
|
;
|
||||||
|
provider = mkOption {
|
||||||
|
description = "The NixOS module of a provider";
|
||||||
|
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 provider";
|
||||||
|
type = deferredModule;
|
||||||
|
default = config.providers.${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;
|
};
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
resource = attrTag {
|
||||||
|
runtime-environment = mkOption {
|
||||||
|
description = "A run-time environment one may deploy a NixOS configuration to.";
|
||||||
|
type = runtime-environment;
|
||||||
};
|
};
|
||||||
applications = mkOption {
|
};
|
||||||
description = "Collection of Fediversity applications";
|
deployment = submoduleWith {
|
||||||
type = attrsOf (submoduleWith {
|
description = "A deployment of a configuration of applications to a run-time environment";
|
||||||
modules = [
|
modules = [
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
module = mkOption {
|
application-configuration = mkOption {
|
||||||
description = "The NixOS module for that application, for configuring that application";
|
description = ''
|
||||||
type = deferredModule;
|
Configuration to be deployed
|
||||||
};
|
'';
|
||||||
};
|
type = submodule applications;
|
||||||
}
|
};
|
||||||
];
|
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 = {
|
||||||
|
providers = mkOption {
|
||||||
|
description = "Collection of providers for run-time environments to deploy applications to";
|
||||||
|
type = attrTag (genAttrs (attrNames runtime-environment.nestedTypes) (_: provider));
|
||||||
|
};
|
||||||
|
resources = mkOption {
|
||||||
|
description = "Collection of resources for use in Fediversity applications";
|
||||||
|
type = attrsOf resource;
|
||||||
|
};
|
||||||
|
deployments = mkOption {
|
||||||
|
description = "Deployment of a configuration of applications to a run-time environment";
|
||||||
|
type = attrsOf deployment;
|
||||||
|
};
|
||||||
|
# XXX should this be more ephemeral than something that just.. exists?
|
||||||
|
migrations = mkOption {
|
||||||
|
description = "Migrations from Fediversity deployments to Fediversity run-time environments";
|
||||||
|
type = attrsOf migration;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue