factor out function wrapper to module function

note that this does not yet contain the 'type check', as this does not
function yet.
this could be added in `data-model.nix` like:

```nix
function-type-check = mkOption {
  type = application.config.config-mapping.function-type;
  readOnly = true;
  default = input: {
    inherit input;
    output = application.config.config-mapping.implementation-type
input;
  };
};
```

... or even to `function.nix` itself, like:

```nix
function-type-check = mkOption {
  type = config.function-type;
  readOnly = true;
  default = input: {
    inherit input;
    output = config.implementation-type input;
  };
};
```
This commit is contained in:
Kiara Grouwstra 2025-08-01 17:56:35 +02:00
parent 9c219341b1
commit 6fa9c40662
Signed by: kiara
SSH key fingerprint: SHA256:COspvLoLJ5WC5rFb9ZDe5urVCkK4LJZOsjfF4duRJFU
3 changed files with 32 additions and 30 deletions

View file

@ -99,40 +99,37 @@ in
{
options.enable = lib.mkEnableOption "Hello in the shell";
};
implementation = cfg: {
input = cfg;
output = lib.optionalAttrs cfg.enable {
implementation =
cfg:
lib.optionalAttrs cfg.enable {
resources.hello.login-shell.packages.hello = pkgs.hello;
};
};
};
environments.single-nixos-vm =
{ config, ... }:
{
resources.operator-environment.login-shell.username = "operator";
implementation = requests: {
input = requests;
output =
{ providers, ... }:
{
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
);
};
};
implementation =
requests:
{ providers, ... }:
{
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
);
};
};
};
};
};
options = {

View file

@ -99,13 +99,13 @@ in
};
implementation = mkOption {
description = "Mapping of application configuration to deployment resources, a description of what an application needs to run";
type = application.config.config-mapping.function-type;
type = application.config.config-mapping.implementation-type;
};
resources = mkOption {
description = "Compute resources required by an application";
type = functionTo application.config.config-mapping.output-type;
readOnly = true;
default = input: (application.config.implementation input).output;
default = application.config.implementation;
};
# TODO(@fricklerhandwerk): this needs a better name, it's just the type
config-mapping = mkOption {
@ -142,7 +142,7 @@ in
};
implementation = mkOption {
description = "Mapping of resources required by applications to available resources; the result can be deployed";
type = environment.config.resource-mapping.function-type;
type = environment.config.resource-mapping.implementation-type;
};
resource-mapping = mkOption {
description = "Function type for the mapping from resources to a (NixOps4) deployment";
@ -168,7 +168,7 @@ in
name: application-settings: config.applications.${name}.resources application-settings
) cfg.applications;
in
(environment.config.implementation required-resources).output;
environment.config.implementation required-resources;
};
};

View file

@ -18,6 +18,11 @@ in
output-type = mkOption {
type = optionType;
};
implementation-type = mkOption {
type = optionType;
readOnly = true;
default = functionTo config.output-type;
};
function-type = mkOption {
type = optionType;
readOnly = true;