forked from Fediversity/Fediversity
WIP: implement applications.mastodon
as a sample use-case of our data model #2
4 changed files with 159 additions and 50 deletions
|
@ -9,6 +9,8 @@ let
|
||||||
git-hooks
|
git-hooks
|
||||||
gitignore
|
gitignore
|
||||||
;
|
;
|
||||||
|
inherit (import sources.flake-inputs) import-flake;
|
||||||
|
inputs = (import-flake { src = ./.; }).inputs;
|
||||||
inherit (pkgs) lib;
|
inherit (pkgs) lib;
|
||||||
pre-commit-check =
|
pre-commit-check =
|
||||||
(import "${git-hooks}/nix" {
|
(import "${git-hooks}/nix" {
|
||||||
|
@ -67,6 +69,7 @@ in
|
||||||
# re-export inputs so they can be overridden granularly
|
# re-export inputs so they can be overridden granularly
|
||||||
# (they can't be accessed from the outside any other way)
|
# (they can't be accessed from the outside any other way)
|
||||||
inherit
|
inherit
|
||||||
|
inputs
|
||||||
sources
|
sources
|
||||||
system
|
system
|
||||||
pkgs
|
pkgs
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
let
|
let
|
||||||
inherit (import ../default.nix { }) pkgs;
|
inherit (import ../default.nix { }) pkgs inputs;
|
||||||
inherit (pkgs) lib;
|
inherit (pkgs) lib;
|
||||||
|
inherit (lib) mkOption;
|
||||||
eval =
|
eval =
|
||||||
module:
|
module:
|
||||||
(lib.evalModules {
|
(lib.evalModules {
|
||||||
|
specialArgs = {
|
||||||
|
inherit inputs;
|
||||||
|
};
|
||||||
modules = [
|
modules = [
|
||||||
module
|
module
|
||||||
./data-model.nix
|
./data-model.nix
|
||||||
|
@ -14,32 +18,51 @@ in
|
||||||
test-eval = {
|
test-eval = {
|
||||||
expr =
|
expr =
|
||||||
let
|
let
|
||||||
example = eval {
|
fediversity = eval (
|
||||||
runtime-environments.bar.nixos = {
|
{ config, ... }:
|
||||||
module =
|
{
|
||||||
{ ... }:
|
config = {
|
||||||
{
|
applications.hello =
|
||||||
system.stateVersion = "25.05";
|
{ ... }:
|
||||||
|
{
|
||||||
|
description = ''Command-line tool that will print "Hello, world!" on the terminal'';
|
||||||
|
module =
|
||||||
|
{ ... }:
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
enable = lib.mkEnableOption "Hello in the shell";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
implementation =
|
||||||
|
cfg:
|
||||||
|
lib.optionalAttrs cfg.enable {
|
||||||
|
dummy.login-shell.packages.hello = pkgs.hello;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
options = {
|
||||||
|
example-configuration = mkOption {
|
||||||
|
type = config.configuration;
|
||||||
|
readOnly = true;
|
||||||
|
default = {
|
||||||
|
enable = true;
|
||||||
|
applications.hello.enable = true;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
applications.foo = {
|
}
|
||||||
module =
|
);
|
||||||
{ pkgs, ... }:
|
|
||||||
{
|
|
||||||
environment.systemPackages = [
|
|
||||||
pkgs.hello
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
has-runtime = lib.isAttrs example.runtime-environments.bar.nixos.module;
|
inherit (fediversity)
|
||||||
has-application = lib.isAttrs example.applications.foo.module;
|
example-configuration
|
||||||
|
;
|
||||||
};
|
};
|
||||||
expected = {
|
expected = {
|
||||||
has-runtime = true;
|
example-configuration = {
|
||||||
has-application = true;
|
enable = true;
|
||||||
|
applications.hello.enable = true;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,43 +1,87 @@
|
||||||
{
|
{
|
||||||
lib,
|
lib,
|
||||||
|
config,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
inherit (lib) types mkOption;
|
inherit (lib) mkOption types;
|
||||||
|
inherit (lib.types)
|
||||||
|
attrsOf
|
||||||
|
attrTag
|
||||||
|
deferredModuleWith
|
||||||
|
submodule
|
||||||
|
optionType
|
||||||
|
functionTo
|
||||||
|
;
|
||||||
|
|
||||||
|
functionType = import ./function.nix;
|
||||||
|
application-resources = {
|
||||||
|
options.resources = mkOption {
|
||||||
|
# TODO: maybe transpose, and group the resources by type instead
|
||||||
|
type = attrsOf (
|
||||||
|
attrTag (lib.mapAttrs (_name: resource: mkOption { type = resource.request; }) config.resources)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
};
|
||||||
in
|
in
|
||||||
with types;
|
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
runtime-environments = mkOption {
|
applications = mkOption {
|
||||||
description = "Collection of runtime environments into which applications can be deployed";
|
description = "Collection of Fediversity applications";
|
||||||
type = attrsOf (attrTag {
|
type = attrsOf (
|
||||||
nixos = mkOption {
|
submodule (application: {
|
||||||
description = "A single NixOS machine";
|
_class = "fediversity-application";
|
||||||
type = submodule {
|
options = {
|
||||||
options = {
|
description = mkOption {
|
||||||
module = mkOption {
|
description = "Description to be shown in the application overview";
|
||||||
description = "The NixOS module describing the base configuration for that machine";
|
type = types.str;
|
||||||
type = deferredModule;
|
};
|
||||||
|
module = mkOption {
|
||||||
|
description = "Operator-facing configuration options for the application";
|
||||||
|
type = deferredModuleWith { staticModules = [ { _class = "fediversity-application-config"; } ]; };
|
||||||
|
};
|
||||||
|
implementation = mkOption {
|
||||||
|
description = "Mapping of application configuration to deployment resources, a description of what an application needs to run";
|
||||||
|
type = application.config.config-mapping.function-type;
|
||||||
|
};
|
||||||
|
resources = mkOption {
|
||||||
|
description = "Compute resources required by an application";
|
||||||
|
type = functionTo application.config.config-mapping.output-type;
|
||||||
|
readOnly = true;
|
||||||
|
default = input: (application.config.implementation input).output;
|
||||||
|
};
|
||||||
|
config-mapping = mkOption {
|
||||||
|
description = "Function type for the mapping from application configuration to required resources";
|
||||||
|
type = submodule functionType;
|
||||||
|
readOnly = true;
|
||||||
|
default = {
|
||||||
|
input-type = application.config.module;
|
||||||
|
output-type = application-resources;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
})
|
||||||
});
|
);
|
||||||
};
|
};
|
||||||
applications = mkOption {
|
configuration = mkOption {
|
||||||
description = "Collection of Fediversity applications";
|
description = "Configuration type declaring options to be set by operators";
|
||||||
type = attrsOf (submoduleWith {
|
type = optionType;
|
||||||
modules = [
|
readOnly = true;
|
||||||
{
|
default = submodule {
|
||||||
options = {
|
options = {
|
||||||
module = mkOption {
|
enable = lib.mkEnableOption {
|
||||||
description = "The NixOS module for that application, for configuring that application";
|
description = "your Fediversity configuration";
|
||||||
type = deferredModule;
|
};
|
||||||
};
|
applications = lib.mapAttrs (
|
||||||
};
|
_name: application:
|
||||||
}
|
mkOption {
|
||||||
];
|
description = application.description;
|
||||||
});
|
type = submodule application.module;
|
||||||
|
default = { };
|
||||||
|
}
|
||||||
|
) config.applications;
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
39
deployment/function.nix
Normal file
39
deployment/function.nix
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
/**
|
||||||
|
Modular function type
|
||||||
|
*/
|
||||||
|
{ config, lib, ... }:
|
||||||
|
let
|
||||||
|
inherit (lib) mkOption types;
|
||||||
|
inherit (types)
|
||||||
|
deferredModule
|
||||||
|
submodule
|
||||||
|
functionTo
|
||||||
|
optionType
|
||||||
|
;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
input-type = mkOption {
|
||||||
|
type = deferredModule;
|
||||||
|
};
|
||||||
|
output-type = mkOption {
|
||||||
|
type = deferredModule;
|
||||||
|
};
|
||||||
|
function-type = mkOption {
|
||||||
|
type = optionType;
|
||||||
|
readOnly = true;
|
||||||
|
default = functionTo (
|
||||||
|
submodule (function: {
|
||||||
|
options = {
|
||||||
|
input = mkOption {
|
||||||
|
type = submodule config.input-type;
|
||||||
|
};
|
||||||
|
output = mkOption {
|
||||||
|
type = submodule config.output-type;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
})
|
||||||
|
);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue