forked from fediversity/fediversity
Compare commits
No commits in common. "bf488f89e120242dcf0509bbf51eef6219067a58" and "ba047997f2ff294cb28556a01bbfba4b414e743c" have entirely different histories.
bf488f89e1
...
ba047997f2
2 changed files with 39 additions and 43 deletions
|
@ -40,7 +40,7 @@ in
|
||||||
_class = "fediversity-resource-policy";
|
_class = "fediversity-resource-policy";
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
extra-config = mkOption {
|
extra-config = mkOptions {
|
||||||
description = "Any options from NixOS";
|
description = "Any options from NixOS";
|
||||||
};
|
};
|
||||||
apply = mkOption {
|
apply = mkOption {
|
||||||
|
@ -82,21 +82,23 @@ in
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
default = false;
|
default = false;
|
||||||
};
|
};
|
||||||
};
|
apply = mkOption {
|
||||||
config.resource-type = types.any; # TODO: splice out the user type from NixOS
|
type = with types; functionTo raw; # TODO: splice out the user type from NixOS
|
||||||
config.apply =
|
default =
|
||||||
requests:
|
requests:
|
||||||
let
|
let
|
||||||
# Filter out requests that need wheel if policy doesn't allow it
|
# Filter out requests that need wheel if policy doesn't allow it
|
||||||
validRequests = lib.filterAttrs (_name: req: !req.wheel || config.wheel) requests;
|
validRequests = lib.filterAttrs (name: req: !req.wheel || config.wheel) requests;
|
||||||
in
|
in
|
||||||
lib.optionalAttrs (validRequests != { }) {
|
lib.optionalAttrs (validRequests != { }) {
|
||||||
${config.username} = {
|
${config.username} = {
|
||||||
isNormalUser = true;
|
isNormalUser = true;
|
||||||
packages = with lib; concatMapAttrs (_name: request: attrValues request.packages) validRequests;
|
packages = with lib; concatMapAttrs (name: request: attrValues request.packages) validRequests;
|
||||||
extraGroups = lib.optional config.wheel "wheel";
|
extraGroups = lib.optional config.wheel "wheel";
|
||||||
};
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
applications.hello =
|
applications.hello =
|
||||||
|
@ -111,9 +113,7 @@ in
|
||||||
implementation =
|
implementation =
|
||||||
cfg:
|
cfg:
|
||||||
lib.optionalAttrs cfg.enable {
|
lib.optionalAttrs cfg.enable {
|
||||||
hello.login-shell.packages = {
|
dummy.login-shell.packages.hello = pkgs.hello;
|
||||||
inherit (pkgs) hello;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
environments.single-nixos-vm =
|
environments.single-nixos-vm =
|
||||||
|
@ -133,10 +133,10 @@ in
|
||||||
inputs.nixops4-nixos.modules.nixops4Resource.nixos
|
inputs.nixops4-nixos.modules.nixops4Resource.nixos
|
||||||
];
|
];
|
||||||
nixos.module =
|
nixos.module =
|
||||||
{ ... }:
|
{ pkgs, ... }:
|
||||||
{
|
{
|
||||||
users.users = config.resources.shell.login-shell.apply (
|
users.users = config.resources.shell.login-shell.apply (
|
||||||
lib.filterAttrs (_name: value: value ? login-shell) requests
|
lib.filterAttrs (name: value: value ? login-shell) requests
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -164,7 +164,8 @@ in
|
||||||
{
|
{
|
||||||
inherit (fediversity) example-deployment;
|
inherit (fediversity) example-deployment;
|
||||||
};
|
};
|
||||||
expected = {
|
expected =
|
||||||
};
|
{
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,11 @@ let
|
||||||
options.resources = mkOption {
|
options.resources = mkOption {
|
||||||
# TODO: maybe transpose, and group the resources by type instead
|
# TODO: maybe transpose, and group the resources by type instead
|
||||||
type = attrsOf (
|
type = attrsOf (
|
||||||
attrTag (lib.mapAttrs (_name: resource: mkOption { type = resource.request; }) config.resources)
|
attrTag (
|
||||||
|
lib.mapAttrs' (name: resource: {
|
||||||
|
${name} = mkOption { type = resource.request; };
|
||||||
|
}) config.resources
|
||||||
|
)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -33,7 +37,7 @@ in
|
||||||
description = "Collection of deployment resources that can be required by applications and policed by hosting providers";
|
description = "Collection of deployment resources that can be required by applications and policed by hosting providers";
|
||||||
type = attrsOf (
|
type = attrsOf (
|
||||||
submodule (
|
submodule (
|
||||||
{ ... }:
|
{ config, ... }:
|
||||||
{
|
{
|
||||||
_class = "fediversity-resource";
|
_class = "fediversity-resource";
|
||||||
options = {
|
options = {
|
||||||
|
@ -49,23 +53,12 @@ in
|
||||||
description = "Options for configuring the resource policy for the hosting provider, a description of how the resource is made available";
|
description = "Options for configuring the resource policy for the hosting provider, a description of how the resource is made available";
|
||||||
type = deferredModuleWith {
|
type = deferredModuleWith {
|
||||||
staticModules = [
|
staticModules = [
|
||||||
(policy: {
|
{
|
||||||
_class = "fediversity-resource-policy";
|
_class = "fediversity-resource-policy";
|
||||||
# TODO(@fricklerhandwerk): not sure it can be made
|
|
||||||
# sensible syntactically, but essentially we want to
|
|
||||||
# ensure that `apply` is defined, but since its output
|
|
||||||
# depends on the specific policy we also need to
|
|
||||||
# determine that somehow.
|
|
||||||
# hopefully this also helps with correct composition down the line.
|
|
||||||
options.resource-type = mkOption {
|
|
||||||
description = "The type of resource this policy configures";
|
|
||||||
type = types.optionType;
|
|
||||||
};
|
|
||||||
options.apply = mkOption {
|
options.apply = mkOption {
|
||||||
description = "Apply the policy to a request";
|
desciption = "Apply the policy to a request";
|
||||||
type = with types; functionTo policy.config.resource-type;
|
|
||||||
};
|
};
|
||||||
})
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -126,7 +119,9 @@ in
|
||||||
# TODO: maybe transpose, and group the resources by type instead
|
# TODO: maybe transpose, and group the resources by type instead
|
||||||
type = attrsOf (
|
type = attrsOf (
|
||||||
attrTag (
|
attrTag (
|
||||||
lib.mapAttrs (_name: resource: mkOption { type = submodule resource.policy; }) config.resources
|
lib.mapAttrs' (name: resource: {
|
||||||
|
${name} = mkOption { type = resource.policy; };
|
||||||
|
}) config.resources
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -145,7 +140,7 @@ in
|
||||||
};
|
};
|
||||||
deployment = mkOption {
|
deployment = mkOption {
|
||||||
description = "Generate a deployment from a configuration";
|
description = "Generate a deployment from a configuration";
|
||||||
type = functionTo (submodule environment.config.resource-mapping.output-type);
|
type = functionTo environment.config.resource-mapping.output-type;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
default =
|
default =
|
||||||
cfg:
|
cfg:
|
||||||
|
@ -166,13 +161,13 @@ in
|
||||||
description = "Configuration type declaring options to be set by operators";
|
description = "Configuration type declaring options to be set by operators";
|
||||||
type = optionType;
|
type = optionType;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
default = submodule {
|
default = submodule (configuration: {
|
||||||
options = {
|
options = {
|
||||||
enable = lib.mkEnableOption {
|
enable = lib.mkEnableOption {
|
||||||
description = "your Fediversity configuration";
|
description = "your Fediversity configuration";
|
||||||
};
|
};
|
||||||
applications = lib.mapAttrs (
|
applications = lib.mapAttrs (
|
||||||
_name: application:
|
name: application:
|
||||||
mkOption {
|
mkOption {
|
||||||
description = application.description;
|
description = application.description;
|
||||||
type = submodule application.module;
|
type = submodule application.module;
|
||||||
|
@ -180,7 +175,7 @@ in
|
||||||
}
|
}
|
||||||
) config.applications;
|
) config.applications;
|
||||||
};
|
};
|
||||||
};
|
});
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue