forked from fediversity/fediversity
Compare commits
No commits in common. "753dd0e0371fa87ec456bd8355962d188eab325b" and "0f7da573926331240dae97debb86af952b2f6487" have entirely different histories.
753dd0e037
...
0f7da57392
3 changed files with 65 additions and 119 deletions
|
|
@ -43,9 +43,11 @@ in
|
||||||
extra-config = mkOption {
|
extra-config = mkOption {
|
||||||
description = "Any options from NixOS";
|
description = "Any options from NixOS";
|
||||||
};
|
};
|
||||||
|
apply = mkOption {
|
||||||
|
type = with types; functionTo raw;
|
||||||
|
default = requests: lib.mkMerge (requests ++ [ config.extra-config ]);
|
||||||
|
};
|
||||||
};
|
};
|
||||||
config.resource-type = types.raw; # TODO: what's the type of a NixOS configuration?
|
|
||||||
config.apply = requests: lib.mkMerge (requests ++ [ config.extra-config ]);
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
resources.login-shell = {
|
resources.login-shell = {
|
||||||
|
|
@ -80,27 +82,25 @@ in
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
default = false;
|
default = false;
|
||||||
};
|
};
|
||||||
};
|
apply = mkOption {
|
||||||
config.resource-type = types.raw; # 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 (
|
validRequests = lib.filterAttrs (_name: req: !req.wheel || config.wheel) requests;
|
||||||
_name: req: !req.login-shell.wheel || config.wheel
|
|
||||||
) requests.resources;
|
|
||||||
in
|
in
|
||||||
lib.optionalAttrs (validRequests != { }) {
|
lib.optionalAttrs (validRequests != { }) {
|
||||||
${config.username} = {
|
${config.username} = {
|
||||||
isNormalUser = true;
|
isNormalUser = true;
|
||||||
packages =
|
packages = with lib; concatMapAttrs (_name: request: attrValues request.packages) validRequests;
|
||||||
with lib;
|
|
||||||
attrValues (concatMapAttrs (_name: request: request.login-shell.packages) validRequests);
|
|
||||||
extraGroups = lib.optional config.wheel "wheel";
|
extraGroups = lib.optional config.wheel "wheel";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
applications.hello =
|
applications.hello =
|
||||||
{ ... }:
|
{ ... }:
|
||||||
{
|
{
|
||||||
|
|
@ -108,22 +108,20 @@ in
|
||||||
module =
|
module =
|
||||||
{ ... }:
|
{ ... }:
|
||||||
{
|
{
|
||||||
options.enable = lib.mkEnableOption "Hello in the shell";
|
enable = lib.mkEnableOption "Hello in the shell";
|
||||||
};
|
|
||||||
implementation = cfg: {
|
|
||||||
input = cfg;
|
|
||||||
output = lib.optionalAttrs cfg.enable {
|
|
||||||
resources.hello.login-shell.packages.hello = pkgs.hello;
|
|
||||||
};
|
};
|
||||||
|
implementation =
|
||||||
|
cfg:
|
||||||
|
lib.optionalAttrs cfg.enable {
|
||||||
|
dummy.login-shell.packages.hello = pkgs.hello;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
environments.single-nixos-vm =
|
environments.single-nixos-vm =
|
||||||
{ config, ... }:
|
{ config, ... }:
|
||||||
{
|
{
|
||||||
resources.operator-environment.login-shell.username = "operator";
|
resources.shell.login-shell.username = "operator";
|
||||||
implementation = requests: {
|
implementation =
|
||||||
input = requests;
|
requests:
|
||||||
output =
|
|
||||||
{ providers, ... }:
|
{ providers, ... }:
|
||||||
{
|
{
|
||||||
providers = {
|
providers = {
|
||||||
|
|
@ -145,7 +143,6 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
|
||||||
options = {
|
options = {
|
||||||
example-configuration = mkOption {
|
example-configuration = mkOption {
|
||||||
type = config.configuration;
|
type = config.configuration;
|
||||||
|
|
@ -164,42 +161,11 @@ in
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
in
|
in
|
||||||
rec {
|
|
||||||
number-of-resources = with lib; length (attrNames fediversity.resources);
|
|
||||||
inherit (fediversity) example-configuration;
|
|
||||||
hello-package-exists =
|
|
||||||
(fediversity.applications.hello.resources example-configuration.applications.hello)
|
|
||||||
.resources.hello.login-shell.packages ? hello;
|
|
||||||
wheel-required =
|
|
||||||
(fediversity.applications.hello.resources example-configuration.applications.hello)
|
|
||||||
.resources.hello.login-shell.wheel;
|
|
||||||
wheel-allowed =
|
|
||||||
fediversity.environments.single-nixos-vm.resources.operator-environment.login-shell.wheel;
|
|
||||||
operator-shell =
|
|
||||||
let
|
|
||||||
resources = fediversity.applications.hello.resources example-configuration.applications.hello;
|
|
||||||
users = fediversity.environments.single-nixos-vm.resources.operator-environment.login-shell.apply resources;
|
|
||||||
in
|
|
||||||
{
|
{
|
||||||
inherit (users.operator) isNormalUser;
|
inherit (fediversity) example-deployment;
|
||||||
packages = with lib; map (p: "${p.pname}") users.operator.packages;
|
|
||||||
extraGroups = users.operator.extraGroups;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
expected = {
|
|
||||||
number-of-resources = 2;
|
|
||||||
example-configuration = {
|
|
||||||
enable = true;
|
|
||||||
applications.hello.enable = true;
|
|
||||||
};
|
|
||||||
hello-package-exists = true;
|
|
||||||
wheel-required = false;
|
|
||||||
wheel-allowed = false;
|
|
||||||
operator-shell = {
|
|
||||||
isNormalUser = true;
|
|
||||||
packages = [ "hello" ];
|
|
||||||
extraGroups = [ ];
|
|
||||||
};
|
};
|
||||||
|
expected =
|
||||||
|
{
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,28 +17,19 @@ let
|
||||||
;
|
;
|
||||||
|
|
||||||
functionType = import ./function.nix;
|
functionType = import ./function.nix;
|
||||||
application-resources = submodule {
|
application-resources = {
|
||||||
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 (
|
attrTag (
|
||||||
lib.mapAttrs (_name: resource: mkOption { type = submodule resource.request; }) config.resources
|
lib.mapAttrs' (name: resource: {
|
||||||
|
${name} = mkOption { type = resource.request; };
|
||||||
|
}) config.resources
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
nixops4Deployment = types.deferredModuleWith {
|
nixops4Deployment = inputs.nixops4.modules.nixops4Deployment.default;
|
||||||
staticModules = [
|
|
||||||
inputs.nixops4.modules.nixops4Deployment.default
|
|
||||||
|
|
||||||
{
|
|
||||||
_module.args = {
|
|
||||||
resourceProviderSystem = builtins.currentSystem;
|
|
||||||
resources = { };
|
|
||||||
};
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
|
|
@ -62,24 +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;
|
|
||||||
};
|
|
||||||
# TODO(@fricklerhandwerk): do we need a function type here as well, or is it in the way?
|
|
||||||
options.apply = mkOption {
|
options.apply = mkOption {
|
||||||
description = "Apply the policy to a request";
|
description = "Apply the policy to a request";
|
||||||
type = with types; functionTo policy.config.resource-type;
|
|
||||||
};
|
};
|
||||||
})
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -117,7 +96,7 @@ in
|
||||||
type = submodule functionType;
|
type = submodule functionType;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
default = {
|
default = {
|
||||||
input-type = submodule application.config.module;
|
input-type = application.config.module;
|
||||||
output-type = application-resources;
|
output-type = application-resources;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -154,12 +133,12 @@ in
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
default = {
|
default = {
|
||||||
input-type = application-resources;
|
input-type = application-resources;
|
||||||
output-type = types.raw;
|
output-type = nixops4Deployment;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
deployment = mkOption {
|
deployment = mkOption {
|
||||||
description = "Generate a deployment from a configuration";
|
description = "Generate a deployment from a configuration";
|
||||||
type = functionTo environment.config.resource-mapping.output-type;
|
type = functionTo (submodule environment.config.resource-mapping.output-type);
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
default =
|
default =
|
||||||
cfg:
|
cfg:
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
let
|
let
|
||||||
inherit (lib) mkOption types;
|
inherit (lib) mkOption types;
|
||||||
inherit (types)
|
inherit (types)
|
||||||
|
deferredModule
|
||||||
submodule
|
submodule
|
||||||
functionTo
|
functionTo
|
||||||
optionType
|
optionType
|
||||||
|
|
@ -13,10 +14,10 @@ in
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
input-type = mkOption {
|
input-type = mkOption {
|
||||||
type = optionType;
|
type = deferredModule;
|
||||||
};
|
};
|
||||||
output-type = mkOption {
|
output-type = mkOption {
|
||||||
type = optionType;
|
type = deferredModule;
|
||||||
};
|
};
|
||||||
function-type = mkOption {
|
function-type = mkOption {
|
||||||
type = optionType;
|
type = optionType;
|
||||||
|
|
@ -25,10 +26,10 @@ in
|
||||||
submodule (function: {
|
submodule (function: {
|
||||||
options = {
|
options = {
|
||||||
input = mkOption {
|
input = mkOption {
|
||||||
type = config.input-type;
|
type = submodule config.input-type;
|
||||||
};
|
};
|
||||||
output = mkOption {
|
output = mkOption {
|
||||||
type = config.output-type;
|
type = submodule config.output-type;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue