2021-10-27 11:05:52 +02:00
{ config , lib , self , . . . }:
let
inherit ( lib )
2021-11-22 22:01:38 +01:00
genAttrs
2021-10-27 11:05:52 +02:00
mapAttrs
mkOption
types
;
rootConfig = config ;
in
{
options = {
systems = mkOption {
description = " A l l t h e s y s t e m t y p e s t o e n u m e r a t e i n t h e f l a k e . " ;
type = types . listOf types . str ;
} ;
perInput = mkOption {
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 . " ;
type = types . functionTo ( types . functionTo ( types . lazyAttrsOf types . unspecified ) ) ;
} ;
perSystem = mkOption {
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 . " ;
type = types . functionTo ( types . submoduleWith {
modules = [
( { config , system , . . . }: {
_file = ./perSystem.nix ;
config = {
_module . args . inputs' = mapAttrs ( k : rootConfig . perInput system ) self . inputs ;
_module . args . self' = rootConfig . perInput system self ;
} ;
} )
] ;
shorthandOnlyDefinesConfig = false ;
} ) ;
} ;
2021-11-22 22:01:38 +01:00
allSystems = mkOption {
type = types . lazyAttrsOf types . unspecified ;
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 . " ;
internal = true ;
} ;
} ;
config = {
perSystem = system : { _module . args . system = system ; } ;
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.
_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 11:05:52 +02:00
} ;
}