1
0
Fork 0
mirror of https://github.com/hercules-ci/flake-parts.git synced 2024-12-14 11:47:31 +00:00

Add lib.defaultModule for extracting the default flakeModule

This commit is contained in:
Shea Levy 2022-10-18 11:52:13 -04:00
parent f3c79bef3b
commit 3c60ce7d7e
No known key found for this signature in database
GPG key ID: 5C0BD6957D86FE27

17
lib.nix
View file

@ -22,6 +22,12 @@ let
submoduleWith submoduleWith
; ;
# Polyfill isFlake until Nix with https://github.com/NixOS/nix/pull/7207 is common
isFlake = maybeFlake:
if maybeFlake ? _type
then maybeFlake._type == "flake"
else maybeFlake ? inputs && maybeFlake ? outputs && maybeFlake ? sourceInfo;
# Polyfill functionTo to make sure it has type merging. # Polyfill functionTo to make sure it has type merging.
# Remove 2022-12 # Remove 2022-12
functionTo = functionTo =
@ -118,6 +124,17 @@ let
} }
); );
# Function to extract the default flakeModule from
# what may be a flake, returning the argument unmodified
# if it's not a flake.
#
# Useful to map over an 'imports' list to make it less
# verbose in the common case.
defaultModule = maybeFlake:
if isFlake maybeFlake
then maybeFlake.flakeModules.default or maybeFlake
else maybeFlake;
mkFlake = args: module: mkFlake = args: module:
(flake-parts-lib.evalFlakeModule args module).config.flake; (flake-parts-lib.evalFlakeModule args module).config.flake;