|
9 | 9 | inherit (lib) types; |
10 | 10 |
|
11 | 11 | kernelName = "rust"; |
12 | | - |
| 12 | + |
13 | 13 | # Helper function to coerce overlays into a list with validation |
14 | | - mkOverlays = overlays: |
15 | | - let |
16 | | - validateOverlay = overlay: |
17 | | - if builtins.isFunction overlay then overlay |
18 | | - else throw "Expected function, got ${builtins.typeOf overlay}"; |
19 | | - in |
20 | | - if builtins.isFunction overlays then [ overlays ] |
21 | | - else if builtins.isList overlays then map validateOverlay overlays |
22 | | - else throw "Expected a function or list of functions for overlays"; |
| 14 | + mkOverlays = overlays: let |
| 15 | + validateOverlay = overlay: |
| 16 | + if builtins.isFunction overlay |
| 17 | + then overlay |
| 18 | + else throw "Expected function, got ${builtins.typeOf overlay}"; |
| 19 | + in |
| 20 | + if builtins.isFunction overlays |
| 21 | + then [overlays] |
| 22 | + else if builtins.isList overlays |
| 23 | + then map validateOverlay overlays |
| 24 | + else throw "Expected a function or list of functions for overlays"; |
23 | 25 |
|
24 | 26 | kernelOptions = { |
25 | 27 | config, |
|
86 | 88 | } |
87 | 89 | // extraKernelSpc; |
88 | 90 | in { |
89 | | - options = { |
90 | | - evcxr = lib.mkOption { |
91 | | - type = types.package; |
92 | | - default = config.nixpkgs.evcxr; |
93 | | - example = lib.literalExpression "pkgs.evcxr"; |
94 | | - description = '' |
95 | | - An evaluation context for Rust. |
96 | | - ''; |
97 | | - }; |
| 91 | + options = |
| 92 | + { |
| 93 | + evcxr = lib.mkOption { |
| 94 | + type = types.package; |
| 95 | + default = config.nixpkgs.evcxr; |
| 96 | + example = lib.literalExpression "pkgs.evcxr"; |
| 97 | + description = '' |
| 98 | + An evaluation context for Rust. |
| 99 | + ''; |
| 100 | + }; |
98 | 101 |
|
99 | | - # Allow users to pass one or more overlay functions directly |
100 | | - overlays = lib.mkOption { |
101 | | - type = types.listOf types.function; |
102 | | - default = [ self.inputs.rust-overlay.overlays.default ]; |
103 | | - defaultText = lib.literalExpression "[ self.inputs.rust-overlay.overlays.default ]"; |
104 | | - example = lib.literalExpression "[ myCustomOverlay ]"; |
105 | | - description = '' |
106 | | - A list of nixpkgs overlay functions to apply when building the Rust kernel. |
107 | | - Each overlay should have the form: `final: prev: { … }`. |
108 | | - ''; |
109 | | - }; |
| 102 | + # Allow users to pass one or more overlay functions directly |
| 103 | + overlays = lib.mkOption { |
| 104 | + type = types.listOf (types.functionTo (types.functionTo types.attrs)); |
| 105 | + default = [self.inputs.rust-overlay.overlays.default]; |
| 106 | + defaultText = lib.literalExpression "[ self.inputs.rust-overlay.overlays.default ]"; |
| 107 | + example = lib.literalExpression "[ myCustomOverlay ]"; |
| 108 | + description = '' |
| 109 | + A list of nixpkgs overlay functions to apply when building the Rust kernel. |
| 110 | + Each overlay should have the form: `final: prev: { … }`. |
| 111 | + ''; |
| 112 | + }; |
110 | 113 |
|
111 | | - # Allow users to pin or replace the nixpkgs they want |
112 | | - nixpkgs = lib.mkOption { |
113 | | - type = types.submodule { |
114 | | - options = { |
115 | | - path = lib.mkOption { |
116 | | - type = types.path; |
117 | | - default = self.inputs.nixpkgs; |
118 | | - defaultText = lib.literalExpression "self.inputs.nixpkgs"; |
119 | | - example = lib.literalExpression "self.inputs.nixpkgs"; |
120 | | - description = "Path (or flake URL) of the nixpkgs to use for Rust."; |
121 | | - }; |
122 | | - extraOverlays = lib.mkOption { |
123 | | - type = types.listOf types.function; |
124 | | - default = []; |
125 | | - example = lib.literalExpression "[ (import ./my-overlay.nix) ]"; |
126 | | - description = "Additional overlay functions to merge with `overlays`."; |
| 114 | + # Allow users to pin or replace the nixpkgs they want |
| 115 | + nixpkgs = lib.mkOption { |
| 116 | + type = types.submodule { |
| 117 | + options = { |
| 118 | + path = lib.mkOption { |
| 119 | + type = types.path; |
| 120 | + default = self.inputs.nixpkgs; |
| 121 | + defaultText = lib.literalExpression "self.inputs.nixpkgs"; |
| 122 | + example = lib.literalExpression "self.inputs.nixpkgs"; |
| 123 | + description = "Path (or flake URL) of the nixpkgs to use for Rust."; |
| 124 | + }; |
| 125 | + extraOverlays = lib.mkOption { |
| 126 | + type = types.listOf (types.functionTo (types.functionTo types.attrs)); |
| 127 | + default = []; |
| 128 | + example = lib.literalExpression "[ (import ./my-overlay.nix) ]"; |
| 129 | + description = "Additional overlay functions to merge with `overlays`."; |
| 130 | + }; |
127 | 131 | }; |
128 | 132 | }; |
| 133 | + default = { |
| 134 | + path = self.inputs.nixpkgs; |
| 135 | + extraOverlays = []; |
| 136 | + }; |
| 137 | + description = "Configuration for the nixpkgs instance used by the Rust kernel."; |
129 | 138 | }; |
130 | | - default = { |
131 | | - path = self.inputs.nixpkgs; |
132 | | - extraOverlays = []; |
133 | | - }; |
134 | | - description = "Configuration for the nixpkgs instance used by the Rust kernel."; |
135 | | - }; |
136 | | - } |
137 | | - // kernelModule.options; |
138 | | - |
| 139 | + } |
| 140 | + // kernelModule.options; |
| 141 | + |
139 | 142 | config = lib.mkIf config.enable { |
140 | 143 | build = mkKernel (kernelFunc config.kernelArgs); |
141 | 144 | kernelArgs = |
|
145 | 148 | # Import nixpkgs with all overlays applied |
146 | 149 | pkgs = let |
147 | 150 | allOverlays = config.overlays ++ config.nixpkgs.extraOverlays; |
148 | | - in import config.nixpkgs.path { |
149 | | - inherit system; |
150 | | - overlays = allOverlays; |
151 | | - }; |
| 151 | + in |
| 152 | + import config.nixpkgs.path { |
| 153 | + inherit system; |
| 154 | + overlays = allOverlays; |
| 155 | + }; |
152 | 156 | }; |
153 | 157 | }; |
154 | 158 | }; |
|
0 commit comments