Compare commits

...
Sign in to create a new pull request.

10 commits

6 changed files with 234 additions and 37 deletions

View file

@ -0,0 +1,9 @@
{
_class = "fediversity";
config = {
applications = {
# mastodon.module = import ./mastodon.nix;
};
};
}

View file

@ -11,35 +11,57 @@ 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 = {
providers.ssh-host =
{ ... }: { ... }:
{ {
system.stateVersion = "25.05"; system.stateVersion = "25.05";
}; };
}; resources.bar.runtime-environment.ssh-host = {
applications.foo = { ssh = {
module = host = "localhost";
username = "root";
authentication.password = "";
};
};
applications.foo.module =
{ pkgs, ... }: { pkgs, ... }:
{ {
environment.systemPackages = [ environment.systemPackages = [
pkgs.hello pkgs.hello
]; ];
}; };
}; deployments.baz = {
}; module = { };
runtime-environment = config.resources.bar.runtime-environment;
};
migrations.boo = {
deployment = config.deployments.baz;
runtime-environment = config.resources.bar.runtime-environment;
};
}
);
in in
{ {
has-runtime = lib.isAttrs example.runtime-environments.bar.nixos.module; has-provider = lib.isAttrs example.providers.ssh-host;
has-resource = lib.isAttrs example.resources.bar.runtime-environment.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-provider = true;
has-resource = true;
has-application = true; has-application = true;
has-deployment = true;
has-migration = true;
}; };
}; };
} }

View file

@ -1,43 +1,180 @@
{ {
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
;
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;
};
};
application = submoduleWith {
description = "A Fediversity application";
modules = [
{
options = {
module = mkOption {
description = ''
The NixOS module to configure the 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 = {
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;
}; };
applications = mkOption { applications = mkOption {
description = "Collection of Fediversity applications"; description = "Collection of (available) 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; # 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;
];
});
}; };
}; };
} }

View file

@ -0,0 +1,10 @@
{
_class = "fediversity";
config = {
providers = {
qemu = import ./qemu.nix;
ssh-host = import ./ssh-host.nix;
};
};
}

View file

@ -0,0 +1,11 @@
{
modulesPath,
...
}:
{
_class = "nixos";
imports = [
"${modulesPath}/profiles/qemu-guest.nix"
];
}

View file

@ -0,0 +1,8 @@
{
_class = "nixos";
services.openssh = {
enable = true;
settings.PasswordAuthentication = false;
};
}