2022-05-25 14:36:33 +00:00
{ config , lib , flake-parts-lib , self , . . . }:
2021-10-27 09:05:52 +00:00
let
inherit ( lib )
2021-11-22 21:01:38 +00:00
genAttrs
2021-10-27 09:05:52 +00:00
mapAttrs
mkOption
types
;
2022-05-25 14:36:33 +00:00
inherit ( flake-parts-lib )
2022-05-13 08:14:10 +00:00
mkPerSystemType
;
2021-10-27 09:05:52 +00:00
rootConfig = config ;
in
{
options = {
systems = mkOption {
2022-11-11 06:39:25 +00:00
description = ''
2022-11-11 05:40:37 +00:00
All the system types to enumerate in the flake output subattributes .
In other words , all valid values for ` system ` in e . g . ` packages . <system> . foo ` .
'' ;
2021-10-27 09:05:52 +00:00
type = types . listOf types . str ;
} ;
perInput = mkOption {
2022-11-11 06:39:25 +00:00
description = " F u n c t i o n f r o m s y s t e m t o f u n c t i o n f r o m f l a k e t o ` s y s t e m ` - s p e c i f i c a t t r i b u t e s . " ;
2021-10-27 09:05:52 +00:00
type = types . functionTo ( types . functionTo ( types . lazyAttrsOf types . unspecified ) ) ;
} ;
perSystem = mkOption {
2022-11-11 06:39:25 +00:00
description = " A f u n c t i o n f r o m s y s t e m t o f l a k e - l i k e a t t r i b u t e s o m i t t i n g t h e ` < s y s t e m > ` a t t r i b u t e . " ;
2022-05-13 08:14:10 +00:00
type = mkPerSystemType ( { config , system , . . . }: {
_file = ./perSystem.nix ;
config = {
_module . args . inputs' = mapAttrs ( k : rootConfig . perInput system ) self . inputs ;
_module . args . self' = rootConfig . perInput system self ;
} ;
2021-10-27 09:05:52 +00:00
} ) ;
2022-05-25 16:09:17 +00:00
apply = modules : system :
( lib . evalModules {
inherit modules ;
prefix = [ " p e r S y s t e m " system ] ;
specialArgs = {
inherit system ;
} ;
} ) . config ;
2021-10-27 09:05:52 +00:00
} ;
2021-11-22 21:01:38 +00:00
allSystems = mkOption {
type = types . lazyAttrsOf types . unspecified ;
2022-11-11 06:39:25 +00:00
description = " T h e s y s t e m - s p e c i f i c c o n f i g f o r e a c h o f s y s t e m s . " ;
2021-11-22 21:01:38 +00:00
internal = true ;
} ;
} ;
config = {
allSystems = genAttrs config . systems config . perSystem ;
# TODO: Sub-optimal error message. Get Nix to support a memoization primop, or get Nix Flakes to support systems properly or get Nix Flakes to add a name to flakes.
2022-04-06 16:01:26 +00:00
_module . args . getSystem = system : config . allSystems . ${ system } or ( builtins . trace " u s i n g n o n - m e m o i z e d s y s t e m ${ system } " config . perSystem system ) ;
2021-10-27 09:05:52 +00:00
} ;
}