From 8e6bca1b0afcfb4e5c5f9e21f100adf2b2ce2d08 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Sun, 30 Oct 2022 06:52:28 -0400 Subject: [PATCH] Add mkTransposedPerSystemModule for simple per-system exposed attrs --- lib.nix | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib.nix b/lib.nix index 0d728f3..2d38daa 100644 --- a/lib.nix +++ b/lib.nix @@ -98,6 +98,34 @@ let type = flake-parts-lib.mkPerSystemType module; }; + # Helper function for defining a per-system option that + # gets transposed by the usual flake system logic to a + # top-level flake attribute. + mkTransposedPerSystemModule = { name, option, file }: { + _file = file; + + options = { + flake = flake-parts-lib.mkSubmoduleOptions { + ${name} = mkOption { + type = types.lazyAttrsOf option.type; + default = { }; + description = lib.mdDoc '' + See {option}`perSystem.${name}` for description and examples. + ''; + }; + }; + + perSystem = flake-parts-lib.mkPerSystemOption { + _file = file; + + options.${name} = option; + }; + }; + + config = { + transposition.${name} = { }; + }; + }; }; in