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";
|
||||
|
||||
options = {
|
||||
extra-config = mkOption {
|
||||
extra-config = mkOptions {
|
||||
description = "Any options from NixOS";
|
||||
};
|
||||
apply = mkOption {
|
||||
|
@ -82,21 +82,23 @@ in
|
|||
type = types.bool;
|
||||
default = false;
|
||||
};
|
||||
};
|
||||
config.resource-type = types.any; # TODO: splice out the user type from NixOS
|
||||
config.apply =
|
||||
requests:
|
||||
let
|
||||
# Filter out requests that need wheel if policy doesn't allow it
|
||||
validRequests = lib.filterAttrs (_name: req: !req.wheel || config.wheel) requests;
|
||||
in
|
||||
lib.optionalAttrs (validRequests != { }) {
|
||||
${config.username} = {
|
||||
isNormalUser = true;
|
||||
packages = with lib; concatMapAttrs (_name: request: attrValues request.packages) validRequests;
|
||||
extraGroups = lib.optional config.wheel "wheel";
|
||||
};
|
||||
apply = mkOption {
|
||||
type = with types; functionTo raw; # TODO: splice out the user type from NixOS
|
||||
default =
|
||||
requests:
|
||||
let
|
||||
# Filter out requests that need wheel if policy doesn't allow it
|
||||
validRequests = lib.filterAttrs (name: req: !req.wheel || config.wheel) requests;
|
||||
in
|
||||
lib.optionalAttrs (validRequests != { }) {
|
||||
${config.username} = {
|
||||
isNormalUser = true;
|
||||
packages = with lib; concatMapAttrs (name: request: attrValues request.packages) validRequests;
|
||||
extraGroups = lib.optional config.wheel "wheel";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
applications.hello =
|
||||
|
@ -111,9 +113,7 @@ in
|
|||
implementation =
|
||||
cfg:
|
||||
lib.optionalAttrs cfg.enable {
|
||||
hello.login-shell.packages = {
|
||||
inherit (pkgs) hello;
|
||||
};
|
||||
dummy.login-shell.packages.hello = pkgs.hello;
|
||||
};
|
||||
};
|
||||
environments.single-nixos-vm =
|
||||
|
@ -133,10 +133,10 @@ in
|
|||
inputs.nixops4-nixos.modules.nixops4Resource.nixos
|
||||
];
|
||||
nixos.module =
|
||||
{ ... }:
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
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;
|
||||
};
|
||||
expected = {
|
||||
};
|
||||
expected =
|
||||
{
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -21,7 +21,11 @@ let
|
|||
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)
|
||||
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";
|
||||
type = attrsOf (
|
||||
submodule (
|
||||
{ ... }:
|
||||
{ config, ... }:
|
||||
{
|
||||
_class = "fediversity-resource";
|
||||
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";
|
||||
type = deferredModuleWith {
|
||||
staticModules = [
|
||||
(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 {
|
||||
description = "Apply the policy to a request";
|
||||
type = with types; functionTo policy.config.resource-type;
|
||||
desciption = "Apply the policy to a request";
|
||||
};
|
||||
})
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
|
@ -126,7 +119,9 @@ in
|
|||
# TODO: maybe transpose, and group the resources by type instead
|
||||
type = attrsOf (
|
||||
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 {
|
||||
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;
|
||||
default =
|
||||
cfg:
|
||||
|
@ -166,13 +161,13 @@ in
|
|||
description = "Configuration type declaring options to be set by operators";
|
||||
type = optionType;
|
||||
readOnly = true;
|
||||
default = submodule {
|
||||
default = submodule (configuration: {
|
||||
options = {
|
||||
enable = lib.mkEnableOption {
|
||||
description = "your Fediversity configuration";
|
||||
};
|
||||
applications = lib.mapAttrs (
|
||||
_name: application:
|
||||
name: application:
|
||||
mkOption {
|
||||
description = application.description;
|
||||
type = submodule application.module;
|
||||
|
@ -180,7 +175,7 @@ in
|
|||
}
|
||||
) config.applications;
|
||||
};
|
||||
};
|
||||
});
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue