From 2e91782d7e2b55c90f47f7fba1da57f3cb3b46da Mon Sep 17 00:00:00 2001 From: Kiara Grouwstra Date: Sun, 17 Aug 2025 17:51:23 +0200 Subject: [PATCH] turn function.nix into a reflective type --- deployment/data-model.nix | 6 ++--- deployment/function.nix | 49 +++++++++++++++++++++------------------ 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/deployment/data-model.nix b/deployment/data-model.nix index c3d5d53a..88069508 100644 --- a/deployment/data-model.nix +++ b/deployment/data-model.nix @@ -15,7 +15,7 @@ let functionTo ; - functionType = import ./function.nix; + functionType = import ./function.nix { inherit lib; }; application-resources = submodule { options.resources = mkOption { # TODO: maybe transpose, and group the resources by type instead @@ -110,7 +110,7 @@ in # TODO(@fricklerhandwerk): this needs a better name, it's just the type config-mapping = mkOption { description = "Function type for the mapping from application configuration to required resources"; - type = submodule functionType; + type = functionType; readOnly = true; default = { input-type = submodule application.config.module; @@ -146,7 +146,7 @@ in }; resource-mapping = mkOption { description = "Function type for the mapping from resources to a (NixOps4) deployment"; - type = submodule functionType; + type = functionType; readOnly = true; default = { input-type = application-resources; diff --git a/deployment/function.nix b/deployment/function.nix index f0210a34..21d8aecc 100644 --- a/deployment/function.nix +++ b/deployment/function.nix @@ -1,7 +1,7 @@ /** Modular function type */ -{ config, lib, ... }: +{ lib, ... }: let inherit (lib) mkOption types; inherit (types) @@ -10,27 +10,30 @@ let optionType ; in -{ - options = { - input-type = mkOption { - type = optionType; - }; - output-type = mkOption { - type = optionType; - }; - function-type = mkOption { - type = optionType; - readOnly = true; - default = functionTo (submodule { - options = { - input = mkOption { - type = config.input-type; +submodule ( + { config, ... }: + { + options = { + input-type = mkOption { + type = optionType; + }; + output-type = mkOption { + type = optionType; + }; + function-type = mkOption { + type = optionType; + readOnly = true; + default = functionTo (submodule { + options = { + input = mkOption { + type = config.input-type; + }; + output = mkOption { + type = config.output-type; + }; }; - output = mkOption { - type = config.output-type; - }; - }; - }); + }); + }; }; - }; -} + } +)