From 986df6e838c980fdea6bdad2723d1eec0aeccdd0 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 5 Jul 2024 22:49:10 +0200 Subject: [PATCH] lib/catalog: init --- lib/catalog.nix | 42 ++++++++++++++++++++++++++++++++++++++++++ lib/part.nix | 1 + 2 files changed, 43 insertions(+) create mode 100644 lib/catalog.nix diff --git a/lib/catalog.nix b/lib/catalog.nix new file mode 100644 index 0000000..b523fd4 --- /dev/null +++ b/lib/catalog.nix @@ -0,0 +1,42 @@ +{ config, lib, withSystem, ... }: + +{ + lib = { + catalog = { + init = lib.genAttrs config.systems (system: withSystem system ({ config, ... }: lib.mapAttrsToList (name: cell: { + cell = name; + cellBlocks = lib.mapAttrsToList (name: block: { + blockType = "catalogBlock"; + cellBlock = name; + targets = lib.mapAttrsToList (name: target: { + inherit name; + inherit (target) description; + actions = lib.mapAttrsToList (name: action: { + inherit name; + inherit (action) description; + }) target.actions; + }) block; + }) cell; + }) config.catalog)); + + actions = lib.genAttrs config.systems (system: withSystem system ({ config, pkgs, ... }: + lib.mapAttrs (name: cell: + lib.mapAttrs (name: block: + lib.mapAttrs (name: target: + lib.mapAttrs (name: action: + let + binPath = lib.makeBinPath action.packages; + in pkgs.writeShellScript name '' + # Void CLI Action + # --- + ${lib.optionalString (action.packages != []) ''export PATH="${binPath}:$PATH"''} + # --- + ${action.command} + '') target.actions + ) block + ) cell + ) + config.catalog)); + }; + }; +} diff --git a/lib/part.nix b/lib/part.nix index a0d09e7..9d259ad 100644 --- a/lib/part.nix +++ b/lib/part.nix @@ -7,6 +7,7 @@ ./meta.nix ./nginx.nix ./identity.nix + ./catalog.nix ]; options.lib = lib.mkOption {