From 315c09733e0fd5b449a41ffb6c183161554d6375 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Sun, 21 Nov 2021 15:47:11 +0100 Subject: [PATCH] Add freeformType to flake option --- all-modules.nix | 1 + lib.nix | 11 +++++++++++ modules/checks.nix | 5 ++++- modules/devShell.nix | 5 ++++- modules/flake.nix | 27 +++++++++++++++++++++++++++ modules/legacyPackages.nix | 5 ++++- modules/packages.nix | 5 ++++- 7 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 modules/flake.nix diff --git a/all-modules.nix b/all-modules.nix index 0e8019f..bc194a5 100644 --- a/all-modules.nix +++ b/all-modules.nix @@ -3,6 +3,7 @@ imports = [ ./modules/checks.nix ./modules/devShell.nix + ./modules/flake.nix ./modules/legacyPackages.nix ./modules/packages.nix ./modules/perSystem.nix diff --git a/lib.nix b/lib.nix index 1a1a71d..5f84901 100644 --- a/lib.nix +++ b/lib.nix @@ -16,6 +16,17 @@ let specialArgs = { inherit self flake-modules-core-lib; } // specialArgs; modules = [ ./all-modules.nix module ]; }; + + # For extending options in an already declared submodule. + # Workaround for https://github.com/NixOS/nixpkgs/issues/146882 + mkSubmoduleOptions = + options: + mkOption { + type = types.submoduleWith { + modules = [ { inherit options; } ]; + }; + }; }; + in flake-modules-core-lib diff --git a/modules/checks.nix b/modules/checks.nix index 1e745dc..f20bd56 100644 --- a/modules/checks.nix +++ b/modules/checks.nix @@ -8,10 +8,13 @@ let optionalAttrs types ; + inherit (flake-modules-core-lib) + mkSubmoduleOptions + ; in { options = { - flake = { + flake = mkSubmoduleOptions { checks = mkOption { type = types.lazyAttrsOf (types.lazyAttrsOf types.package); default = { }; diff --git a/modules/devShell.nix b/modules/devShell.nix index 3567328..27534db 100644 --- a/modules/devShell.nix +++ b/modules/devShell.nix @@ -8,10 +8,13 @@ let optionalAttrs types ; + inherit (flake-modules-core-lib) + mkSubmoduleOptions + ; in { options = { - flake = { + flake = mkSubmoduleOptions { devShell = mkOption { type = types.lazyAttrsOf types.package; default = { }; diff --git a/modules/flake.nix b/modules/flake.nix new file mode 100644 index 0000000..7202bee --- /dev/null +++ b/modules/flake.nix @@ -0,0 +1,27 @@ +{ config, lib, ... }: +let + inherit (lib) + filterAttrs + genAttrs + mapAttrs + mkOption + optionalAttrs + types + ; +in +{ + options = { + flake = mkOption { + type = types.submoduleWith { + modules = [ + { freeformType = types.lazyAttrsOf types.anything; } + ]; + }; + description = '' + Raw flake attributes. Any attribute can be set here, but some + attributes are represented by options, to provide appropriate + configuration merging. + ''; + }; + }; +} diff --git a/modules/legacyPackages.nix b/modules/legacyPackages.nix index 4f89151..492984d 100644 --- a/modules/legacyPackages.nix +++ b/modules/legacyPackages.nix @@ -8,10 +8,13 @@ let optionalAttrs types ; + inherit (flake-modules-core-lib) + mkSubmoduleOptions + ; in { options = { - flake = { + flake = mkSubmoduleOptions { legacyPackages = mkOption { type = types.lazyAttrsOf (types.lazyAttrsOf types.anything); default = { }; diff --git a/modules/packages.nix b/modules/packages.nix index 622e056..3829800 100644 --- a/modules/packages.nix +++ b/modules/packages.nix @@ -8,10 +8,13 @@ let optionalAttrs types ; + inherit (flake-modules-core-lib) + mkSubmoduleOptions + ; in { options = { - flake = { + flake = mkSubmoduleOptions { packages = mkOption { type = types.lazyAttrsOf (types.lazyAttrsOf types.package); default = { };