File tree Expand file tree Collapse file tree 4 files changed +81
-17
lines changed
Expand file tree Collapse file tree 4 files changed +81
-17
lines changed Original file line number Diff line number Diff line change 11{
2+ config ,
23 lib ,
34 extendModules ,
45 ...
56} : let
7+ inherit
8+ ( lib )
9+ types
10+ ;
611 # attrs of all format modules from ./formats
712 formatModules =
813 lib . flip lib . mapAttrs' ( builtins . readDir ./formats )
2126 } ;
2227
2328 # evaluated configs for all formats
24- allConfigs = lib . mapAttrs ( formatName : evalFormat ) formatModules ;
29+ allConfigs = lib . mapAttrs ( formatName : evalFormat ) config . formatConfigs ;
2530
2631 # attrset of formats to be exposed under config.system.formats
2732 formats = lib . flip lib . mapAttrs allConfigs (
3742 key = "github:nix-community/nixos-generators/all-formats.nix" ;
3843
3944 # declare option for exposing all formats
40- options . system . formats = lib . mkOption {
45+ options . formats = lib . mkOption {
4146 type = lib . types . lazyAttrsOf lib . types . raw ;
4247 description = ''
4348 Different target formats generated for this NixOS configuratation.
4449 '' ;
4550 } ;
4651
52+ options . formatConfigs = lib . mkOption {
53+ type = types . attrsOf types . deferredModule ;
54+ } ;
55+
4756 # expose all formats
48- config . system = { inherit formats ; } ;
57+ config . formats = formats ;
58+
59+ #
60+ config . formatConfigs = lib . flip lib . mapAttrs formatModules ( name : module : {
61+ imports = [ module ] ;
62+ } ) ;
4963}
Original file line number Diff line number Diff line change 2828 testedFormats =
2929 lib . filterAttrs
3030 ( name : _ : ! exclude ? ${ name } )
31- conf . config . system . formats ;
31+ conf . config . formats ;
3232in
3333 testedFormats
Original file line number Diff line number Diff line change 1+ {
2+ nixpkgs ? <nixpkgs> ,
3+ system ? builtins . currentSystem ,
4+ lib ? import ( nixpkgs + /lib ) ,
5+ } : let
6+ nixosSystem = import ( nixpkgs + /nixos/lib/eval-config.nix ) ;
7+
8+ userModule1 = { ...} : {
9+ formatConfigs . amazon . amazonImage . name = "xyz" ;
10+ } ;
11+
12+ userModule2 = { ...} : {
13+ formatConfigs . amazon . amazonImage . name = lib . mkForce "custom-name" ;
14+ } ;
15+
16+ conf = nixosSystem {
17+ inherit system ;
18+ modules = [
19+ ../configuration.nix
20+ ../all-formats.nix
21+ userModule1
22+ userModule2
23+ ] ;
24+ } ;
25+ in
26+ assert lib . hasInfix "custom-name" "${ conf . config . formats . amazon } " ;
27+ conf . config . formats . amazon
Original file line number Diff line number Diff line change 1111 self ,
1212 nixpkgs ,
1313 nixlib ,
14- } :
15- # Library modules (depend on nixlib)
14+ } : let
15+ lib = nixpkgs . lib ;
16+
17+ # Ensures a derivation's name can be accessed without evaluating it deeply.
18+ # Prevents `nix flake show` from being very slow.
19+ makeLazyDrv = name : drv : {
20+ inherit name ;
21+ inherit
22+ ( drv )
23+ drvPath
24+ outPath
25+ outputName
26+ ;
27+ type = "derivation" ;
28+ } ;
29+ in
30+ # Library modules (depend on nixlib)
1631 {
1732 # export all generator formats in ./formats
1833 nixosModules = nixlib . lib . mapAttrs' ( file : _ : {
109124 } ) ;
110125
111126 checks =
112- nixpkgs . lib . genAttrs [ "x86_64-linux" "aarch64-linux" ]
127+ lib . genAttrs [ "x86_64-linux" "aarch64-linux" ]
113128 (
114129 system : let
115130 allFormats = import ./checks/test-all-formats.nix {
116131 inherit nixpkgs system ;
117132 } ;
133+ test-customize-format = import ./checks/test-customize-format.nix {
134+ inherit nixpkgs system ;
135+ } ;
118136 in
119- {
120- inherit
121- ( self . packages . ${ system } )
122- nixos-generate
123- ;
124- is-formatted = import ./checks/is-formatted.nix {
125- pkgs = nixpkgs . legacyPackages . ${ system } ;
126- } ;
127- }
128- // allFormats
137+ lib . mapAttrs makeLazyDrv (
138+ {
139+ inherit
140+ ( self . packages . ${ system } )
141+ nixos-generate
142+ ;
143+
144+ inherit test-customize-format ;
145+
146+ is-formatted = import ./checks/is-formatted.nix {
147+ pkgs = nixpkgs . legacyPackages . ${ system } ;
148+ } ;
149+ }
150+ // allFormats
151+ )
129152 ) ;
130153
131154 devShells = forAllSystems ( system : let
You can’t perform that action at this time.
0 commit comments