Compare commits

..

No commits in common. "fbb2bca24221be35376a3156640c0148c2b62dfb" and "63c200f8379f8372f334ca965941725220558979" have entirely different histories.

3 changed files with 134 additions and 179 deletions

View file

@ -22,7 +22,6 @@ in
fediversity = eval (
{ config, ... }:
{
_class = "fediversity-settings";
config = {
resources.nixos-configuration = {
description = "An entire NixOS configuration";
@ -52,7 +51,6 @@ in
};
};
resources.login-shell = {
_class = "fediversity-resource";
description = "The operator needs to be able to log into the shell";
request =
{ ... }:
@ -106,12 +104,10 @@ in
applications.hello =
{ ... }:
{
_class = "fediversity-application";
description = ''Command-line tool that will print "Hello, world!" on the terminal'';
module =
{ ... }:
{
_class = "fediversity-application-config";
options = {
enable = lib.mkEnableOption "Hello in the shell";
};
@ -119,25 +115,21 @@ in
implementation =
cfg:
lib.optionalAttrs cfg.enable {
_class = "fediversity-application-requirements";
dummy.login-shell.packages.hello = pkgs.hello;
};
};
environments.single-nixos-vm =
{ config, ... }:
{
_class = "fediversity-environment";
resources.shell.login-shell.username = "operator";
implementation =
requests:
{ providers, ... }:
{
_class = "nixops4Deployment";
providers = {
inherit (inputs.nixops4.modules.nixops4Provider) local;
};
resources.the-machine = {
_class = "nixops4Resource";
type = providers.local.exec;
imports = [
inputs.nixops4-nixos.modules.nixops4Resource.nixos
@ -145,7 +137,6 @@ in
nixos.module =
{ ... }:
{
_class = "nixos";
users.users = config.resources.shell.login-shell.apply (
lib.filterAttrs (_name: value: value ? login-shell) requests
);
@ -159,16 +150,12 @@ in
type = config.configuration;
readOnly = true;
default = {
_class = "fediversity-configuration";
enable = true;
applications.hello.enable = true;
};
};
example-deployment = mkOption {
type = types.submoduleWith {
class = "nixops4Deployment";
modules = [ nixops4Deployment ];
};
type = types.submodule nixops4Deployment;
readOnly = true;
default = config.environments.single-nixos-vm.deployment config.example-configuration;
};

View file

@ -10,14 +10,13 @@ let
attrsOf
attrTag
deferredModuleWith
submoduleWith
submodule
optionType
functionTo
;
functionType = import ./function.nix;
application-requirements = {
_class = "fediversity-application-requirements";
application-resources = {
options.resources = mkOption {
# TODO: maybe transpose, and group the resources by type instead
type = attrsOf (
@ -28,16 +27,14 @@ let
nixops4Deployment = inputs.nixops4.modules.nixops4Deployment.default;
in
{
_class = "fediversity-settings";
options = {
resources = mkOption {
description = "Collection of deployment resources that can be required by applications and policed by hosting providers";
type = attrsOf (submoduleWith {
class = "fediversity-resource";
modules = [
(
type = attrsOf (
submodule (
{ ... }:
{
_class = "fediversity-resource";
options = {
description = mkOption {
description = "Description of the resource to help application module authors and hosting providers to work with it";
@ -49,10 +46,10 @@ in
};
policy = mkOption {
description = "Options for configuring the resource policy for the hosting provider, a description of how the resource is made available";
type = submoduleWith {
class = "fediversity-resource-policy";
modules = [
type = deferredModuleWith {
staticModules = [
{
_class = "fediversity-resource-policy";
options.apply = mkOption {
description = "Apply the policy to a request";
};
@ -63,15 +60,13 @@ in
};
}
)
];
});
);
};
applications = mkOption {
description = "Collection of Fediversity applications";
type = attrsOf (submoduleWith {
class = "fediversity-application";
modules = [
(application: {
type = attrsOf (
submodule (application: {
_class = "fediversity-application";
options = {
description = mkOption {
description = "Description to be shown in the application overview";
@ -93,27 +88,22 @@ in
};
config-mapping = mkOption {
description = "Function type for the mapping from application configuration to required resources";
type = submoduleWith {
class = "module-function";
modules = [ functionType ];
};
type = submodule functionType;
readOnly = true;
default = {
input-type = application.config.module;
output-type = application-requirements;
output-type = application-resources;
};
};
};
})
];
});
);
};
environments = mkOption {
description = "Run-time environments for Fediversity applications to be deployed to";
type = attrsOf (submoduleWith {
class = "fediversity-environment";
modules = [
(environment: {
type = attrsOf (
submodule (environment: {
_class = "fediversity-environment";
options = {
resources = mkOption {
description = ''
@ -124,15 +114,7 @@ in
# TODO: maybe transpose, and group the resources by type instead
type = attrsOf (
attrTag (
lib.mapAttrs (
_name: resource:
mkOption {
type = submoduleWith {
class = "fediversity-resource-policy";
modules = [ resource.policy ];
};
}
) config.resources
lib.mapAttrs (_name: resource: mkOption { type = submodule resource.policy; }) config.resources
)
);
};
@ -142,22 +124,16 @@ in
};
resource-mapping = mkOption {
description = "Function type for the mapping from resources to a (NixOps4) deployment";
type = submoduleWith {
class = "module-function";
modules = [ functionType ];
};
type = submodule functionType;
readOnly = true;
default = {
input-type = application-requirements;
input-type = application-resources;
output-type = nixops4Deployment;
};
};
deployment = mkOption {
description = "Generate a deployment from a configuration";
type = functionTo (submoduleWith {
class = "fediversity-deployment";
modules = [ environment.config.resource-mapping.output-type ];
});
type = functionTo (submodule environment.config.resource-mapping.output-type);
readOnly = true;
default =
cfg:
@ -172,17 +148,13 @@ in
};
};
})
];
});
);
};
configuration = mkOption {
description = "Configuration type declaring options to be set by operators";
type = optionType;
readOnly = true;
default = submoduleWith {
class = "fediversity-configuration";
modules = [
{
default = submodule {
options = {
enable = lib.mkEnableOption {
description = "your Fediversity configuration";
@ -191,16 +163,11 @@ in
_name: application:
mkOption {
description = application.description;
type = submoduleWith {
class = "fediversity-application-config";
modules = [ application.module ];
};
type = submodule application.module;
default = { };
}
) config.applications;
};
}
];
};
};
};

View file

@ -13,7 +13,6 @@ let
in
{
options = {
_class = "module-function";
input-type = mkOption {
type = deferredModule;
};
@ -23,7 +22,8 @@ in
function-type = mkOption {
type = optionType;
readOnly = true;
default = functionTo (submodule {
default = functionTo (
submodule (function: {
options = {
input = mkOption {
type = submodule config.input-type;
@ -32,7 +32,8 @@ in
type = submodule config.output-type;
};
};
});
})
);
};
};
}