forked from fediversity/fediversity
Compare commits
10 commits
0f7da57392
...
753dd0e037
| Author | SHA1 | Date | |
|---|---|---|---|
| 753dd0e037 | |||
| 37fd4d6642 | |||
| 8c571c2dbe | |||
| a102ad93b7 | |||
| 89b22df3a4 | |||
| b49e426ed4 | |||
| 421d7b6f93 | |||
| bf488f89e1 | |||
| 7066b2cb69 | |||
| 243ef4425b |
3 changed files with 119 additions and 65 deletions
|
|
@ -43,11 +43,9 @@ 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 = {
|
||||||
|
|
@ -82,23 +80,25 @@ in
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
default = false;
|
default = false;
|
||||||
};
|
};
|
||||||
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";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
config.resource-type = types.raw; # 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.login-shell.wheel || config.wheel
|
||||||
|
) requests.resources;
|
||||||
|
in
|
||||||
|
lib.optionalAttrs (validRequests != { }) {
|
||||||
|
${config.username} = {
|
||||||
|
isNormalUser = true;
|
||||||
|
packages =
|
||||||
|
with lib;
|
||||||
|
attrValues (concatMapAttrs (_name: request: request.login-shell.packages) validRequests);
|
||||||
|
extraGroups = lib.optional config.wheel "wheel";
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
applications.hello =
|
applications.hello =
|
||||||
|
|
@ -108,39 +108,42 @@ in
|
||||||
module =
|
module =
|
||||||
{ ... }:
|
{ ... }:
|
||||||
{
|
{
|
||||||
enable = lib.mkEnableOption "Hello in the shell";
|
options.enable = lib.mkEnableOption "Hello in the shell";
|
||||||
};
|
};
|
||||||
implementation =
|
implementation = cfg: {
|
||||||
cfg:
|
input = cfg;
|
||||||
lib.optionalAttrs cfg.enable {
|
output = lib.optionalAttrs cfg.enable {
|
||||||
dummy.login-shell.packages.hello = pkgs.hello;
|
resources.hello.login-shell.packages.hello = pkgs.hello;
|
||||||
};
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
environments.single-nixos-vm =
|
environments.single-nixos-vm =
|
||||||
{ config, ... }:
|
{ config, ... }:
|
||||||
{
|
{
|
||||||
resources.shell.login-shell.username = "operator";
|
resources.operator-environment.login-shell.username = "operator";
|
||||||
implementation =
|
implementation = requests: {
|
||||||
requests:
|
input = requests;
|
||||||
{ providers, ... }:
|
output =
|
||||||
{
|
{ providers, ... }:
|
||||||
providers = {
|
{
|
||||||
inherit (inputs.nixops4.modules.nixops4Provider) local;
|
providers = {
|
||||||
|
inherit (inputs.nixops4.modules.nixops4Provider) local;
|
||||||
|
};
|
||||||
|
resources.the-machine = {
|
||||||
|
type = providers.local.exec;
|
||||||
|
imports = [
|
||||||
|
inputs.nixops4-nixos.modules.nixops4Resource.nixos
|
||||||
|
];
|
||||||
|
nixos.module =
|
||||||
|
{ ... }:
|
||||||
|
{
|
||||||
|
users.users = config.resources.shell.login-shell.apply (
|
||||||
|
lib.filterAttrs (_name: value: value ? login-shell) requests
|
||||||
|
);
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
resources.the-machine = {
|
};
|
||||||
type = providers.local.exec;
|
|
||||||
imports = [
|
|
||||||
inputs.nixops4-nixos.modules.nixops4Resource.nixos
|
|
||||||
];
|
|
||||||
nixos.module =
|
|
||||||
{ ... }:
|
|
||||||
{
|
|
||||||
users.users = config.resources.shell.login-shell.apply (
|
|
||||||
lib.filterAttrs (_name: value: value ? login-shell) requests
|
|
||||||
);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
options = {
|
options = {
|
||||||
|
|
@ -161,11 +164,42 @@ in
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
in
|
in
|
||||||
{
|
rec {
|
||||||
inherit (fediversity) example-deployment;
|
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;
|
||||||
|
packages = with lib; map (p: "${p.pname}") users.operator.packages;
|
||||||
|
extraGroups = users.operator.extraGroups;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
expected =
|
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 = [ ];
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,19 +17,28 @@ let
|
||||||
;
|
;
|
||||||
|
|
||||||
functionType = import ./function.nix;
|
functionType = import ./function.nix;
|
||||||
application-resources = {
|
application-resources = submodule {
|
||||||
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: {
|
lib.mapAttrs (_name: resource: mkOption { type = submodule resource.request; }) config.resources
|
||||||
${name} = mkOption { type = resource.request; };
|
|
||||||
}) config.resources
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
nixops4Deployment = inputs.nixops4.modules.nixops4Deployment.default;
|
nixops4Deployment = types.deferredModuleWith {
|
||||||
|
staticModules = [
|
||||||
|
inputs.nixops4.modules.nixops4Deployment.default
|
||||||
|
|
||||||
|
{
|
||||||
|
_module.args = {
|
||||||
|
resourceProviderSystem = builtins.currentSystem;
|
||||||
|
resources = { };
|
||||||
|
};
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
|
|
@ -53,12 +62,24 @@ 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;
|
||||||
};
|
};
|
||||||
}
|
})
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -96,7 +117,7 @@ in
|
||||||
type = submodule functionType;
|
type = submodule functionType;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
default = {
|
default = {
|
||||||
input-type = application.config.module;
|
input-type = submodule application.config.module;
|
||||||
output-type = application-resources;
|
output-type = application-resources;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -133,12 +154,12 @@ in
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
default = {
|
default = {
|
||||||
input-type = application-resources;
|
input-type = application-resources;
|
||||||
output-type = nixops4Deployment;
|
output-type = types.raw;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
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:
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@
|
||||||
let
|
let
|
||||||
inherit (lib) mkOption types;
|
inherit (lib) mkOption types;
|
||||||
inherit (types)
|
inherit (types)
|
||||||
deferredModule
|
|
||||||
submodule
|
submodule
|
||||||
functionTo
|
functionTo
|
||||||
optionType
|
optionType
|
||||||
|
|
@ -14,10 +13,10 @@ in
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
input-type = mkOption {
|
input-type = mkOption {
|
||||||
type = deferredModule;
|
type = optionType;
|
||||||
};
|
};
|
||||||
output-type = mkOption {
|
output-type = mkOption {
|
||||||
type = deferredModule;
|
type = optionType;
|
||||||
};
|
};
|
||||||
function-type = mkOption {
|
function-type = mkOption {
|
||||||
type = optionType;
|
type = optionType;
|
||||||
|
|
@ -26,10 +25,10 @@ in
|
||||||
submodule (function: {
|
submodule (function: {
|
||||||
options = {
|
options = {
|
||||||
input = mkOption {
|
input = mkOption {
|
||||||
type = submodule config.input-type;
|
type = config.input-type;
|
||||||
};
|
};
|
||||||
output = mkOption {
|
output = mkOption {
|
||||||
type = submodule config.output-type;
|
type = config.output-type;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue