From 8a692498f2e902e2770194c3a22ed7dfcd329a87 Mon Sep 17 00:00:00 2001 From: oddlama Date: Fri, 12 Jul 2024 21:41:35 +0200 Subject: [PATCH] feat: add support for flake-parts --- flake-module.nix | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 2 ++ 2 files changed, 72 insertions(+) create mode 100644 flake-module.nix diff --git a/flake-module.nix b/flake-module.nix new file mode 100644 index 0000000..d518ade --- /dev/null +++ b/flake-module.nix @@ -0,0 +1,70 @@ +/* +A module to import into flakes based on flake-parts. +Makes integration into a flake easy and tidy. +See https://flake.parts, https://flake.parts/options/agenix-rekey +*/ +{ + lib, + self, + config, + flake-parts-lib, + ... +}: let + inherit + (lib) + mkOption + types + ; +in { + options = { + flake = flake-parts-lib.mkSubmoduleOptions { + topology = mkOption { + type = types.lazyAttrsOf types.unspecified; + default = + lib.mapAttrs + (_system: config': + import ./. { + inherit (config'.topology) pkgs; + modules = + config'.topology.modules + ++ [ + {inherit (config'.topology) nixosConfigurations;} + ]; + }) + config.allSystems; + defaultText = "Automatically filled by nix-topology"; + readOnly = true; + description = '' + The evaluated topology configuration, for each of the specified systems. + Build the output by running `nix build .#topology.$system.config.output`. + ''; + }; + }; + + perSystem = flake-parts-lib.mkPerSystemOption ({ + lib, + pkgs, + ... + }: { + options.topology = { + nixosConfigurations = mkOption { + type = types.lazyAttrsOf types.unspecified; + description = "All nixosSystems that should be evaluated for topology definitions."; + default = self.nixosConfigurations; + defaultText = lib.literalExpression "self.nixosConfigurations"; + }; + pkgs = mkOption { + type = types.unspecified; + description = "The package set to use for the topology evaluation on this system."; + default = pkgs; + defaultText = lib.literalExpression "pkgs # (module argument)"; + }; + modules = mkOption { + type = types.listOf types.unspecified; + description = "A list of additional topology modules to evaluate in your global topology."; + default = []; + }; + }; + }); + }; +} diff --git a/flake.nix b/flake.nix index b61787a..4341d64 100644 --- a/flake.nix +++ b/flake.nix @@ -26,6 +26,8 @@ ... } @ inputs: { + flakeModule = ./flake-module.nix; + # Expose NixOS module nixosModules.topology = ./nixos/module.nix; nixosModules.default = self.nixosModules.topology;