From 9292a75ffa32ce7919175bee1c1381fde8751df0 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Sat, 28 Sep 2024 18:59:13 +0800 Subject: [PATCH] flake-parts/setups/nixos: add specialArgs through declarative setups --- modules/flake-parts/setups/default.nix | 15 +++++++++++++++ modules/flake-parts/setups/nixos.nix | 10 ++++++++++ .../setups/shared/special-args-options.nix | 14 ++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 modules/flake-parts/setups/shared/special-args-options.nix diff --git a/modules/flake-parts/setups/default.nix b/modules/flake-parts/setups/default.nix index 4a861015..95968272 100644 --- a/modules/flake-parts/setups/default.nix +++ b/modules/flake-parts/setups/default.nix @@ -39,5 +39,20 @@ allowUnfree = true; }; }; + + sharedSpecialArgs = lib.mkOption { + type = with lib.types; attrsOf anything; + description = '' + Shared set of arguments to be assigned as part of `_module.specialArgs` + of each of the declarative setups. + ''; + default = { }; + example = lib.literalExpression '' + { + location = "Inside of your walls"; + utilsLib = import ./lib/utils.nix; + } + ''; + }; }; } diff --git a/modules/flake-parts/setups/nixos.nix b/modules/flake-parts/setups/nixos.nix index 4c50e5a6..0bc89a66 100644 --- a/modules/flake-parts/setups/nixos.nix +++ b/modules/flake-parts/setups/nixos.nix @@ -170,6 +170,7 @@ let }; config.nixpkgs.config = cfg.sharedNixpkgsConfig; + config.specialArgs = cfg.sharedSpecialArgs; config.modules = [ # Bring in the required modules. @@ -209,6 +210,13 @@ in ''; }; + sharedSpecialArgs = options.setups.sharedSpecialArgs // { + description = '' + Shared set of module arguments as part of `_module.specialArgs` of the + configuration. + ''; + }; + sharedModules = lib.mkOption { type = with lib.types; listOf deferredModule; default = [ ]; @@ -222,6 +230,7 @@ in (import ./shared/nix-conf.nix { inherit inputs; }) (import ./shared/config-options.nix { inherit (config) systems; }) ./shared/nixpkgs-options.nix + ./shared/special-args-options.nix configType ]); default = { }; @@ -318,6 +327,7 @@ in in lib.nameValuePair system (mkHost { inherit pkgs system; + inherit (metadata) specialArgs; extraModules = cfg.sharedModules ++ metadata.modules; }) ) diff --git a/modules/flake-parts/setups/shared/special-args-options.nix b/modules/flake-parts/setups/shared/special-args-options.nix new file mode 100644 index 00000000..c208ca21 --- /dev/null +++ b/modules/flake-parts/setups/shared/special-args-options.nix @@ -0,0 +1,14 @@ +{ config, lib, ... }: + +{ + options.specialArgs = lib.mkOption { + type = with lib.types; attrsOf anything; + default = { }; + example = lib.literalExpression '' + { + location = "Your mom's home"; + utilsLib = import ./lib/utils.nix; + } + ''; + }; +}