|
1 | 1 | {
|
2 | 2 | lib,
|
3 | 3 | config,
|
4 |
| - options, |
5 | 4 | ...
|
6 | 5 | }:
|
7 |
| -let |
8 |
| - cfg = config.facter; |
9 |
| - modulePath = lib.concatStringsSep "/" (lib.take 4 (lib.splitString [ "/" ] __curPos.file)); |
10 |
| -in |
11 | 6 | {
|
12 | 7 | imports = [
|
13 | 8 | ./bluetooth.nix
|
|
23 | 18 | options.facter = with lib; {
|
24 | 19 | report = mkOption {
|
25 | 20 | type = types.raw;
|
26 |
| - default = builtins.fromJSON (builtins.readFile config.facter.reportPath); |
| 21 | + default = if config.facter.reportPath == null then {} else builtins.fromJSON (builtins.readFile config.facter.reportPath); |
27 | 22 | description = "An import for the reportPath.";
|
28 | 23 | };
|
29 | 24 |
|
30 | 25 | reportPath = mkOption {
|
31 |
| - type = types.path; |
| 26 | + type = types.nullOr types.path; |
| 27 | + default = null; |
32 | 28 | description = "Path to a report generated by nixos-facter.";
|
33 | 29 | };
|
34 |
| - |
35 |
| - debug = { |
36 |
| - options = mkOption { |
37 |
| - type = types.raw; |
38 |
| - description = "All of the options affected by Facter modules"; |
39 |
| - }; |
40 |
| - config = mkOption { |
41 |
| - type = types.raw; |
42 |
| - description = "A breakdown of the NixOS config being applied by each Facter module."; |
43 |
| - }; |
44 |
| - }; |
45 | 30 | };
|
46 |
| - |
47 |
| - config.facter.debug = { |
48 |
| - options = |
49 |
| - let |
50 |
| - # we want all options except our own, otherwise we get into recursive issues |
51 |
| - otherOptions = lib.filterAttrs (n: _: n != "facter") options; |
52 |
| - |
53 |
| - # a filter for identifying options where a Facter module has affected the value |
54 |
| - touchedByFacter = |
55 |
| - { definitionsWithLocations, ... }: |
56 |
| - let |
57 |
| - # some options fail when we try to evaluate them, so we wrap this in tryEval |
58 |
| - eval = builtins.tryEval ( |
59 |
| - builtins.any ( |
60 |
| - { |
61 |
| - file ? "", |
62 |
| - ... |
63 |
| - }: |
64 |
| - # we only want options affected by our modules |
65 |
| - lib.hasPrefix "${modulePath}/modules/nixos" file |
66 |
| - ) definitionsWithLocations |
67 |
| - ); |
68 |
| - in |
69 |
| - eval.success && eval.value; |
70 |
| - in |
71 |
| - lib.fold (a: b: lib.recursiveUpdate a b) { } ( |
72 |
| - map (value@{ loc, ... }: lib.setAttrByPath loc value) ( |
73 |
| - # we collect the options first with simple option filter, and then we filter them some more, otherwise we get |
74 |
| - # a max-call depth exceeded error (dunno why) |
75 |
| - lib.filter touchedByFacter (lib.collect lib.isOption otherOptions) |
76 |
| - ) |
77 |
| - ); |
78 |
| - |
79 |
| - config = |
80 |
| - # extract the config values for each option, broken down by facter module |
81 |
| - lib.mapAttrsRecursiveCond |
82 |
| - ( |
83 |
| - { |
84 |
| - definitionsWithLocations ? null, |
85 |
| - ... |
86 |
| - }: |
87 |
| - # keep recursing if we are not processing an option, otherwise apply the map function |
88 |
| - definitionsWithLocations == null |
89 |
| - ) |
90 |
| - ( |
91 |
| - _: |
92 |
| - { definitionsWithLocations, ... }: |
93 |
| - builtins.listToAttrs ( |
94 |
| - map |
95 |
| - ( |
96 |
| - { file, value }: |
97 |
| - { |
98 |
| - name = "<facter>${lib.removePrefix modulePath file}"; |
99 |
| - inherit value; |
100 |
| - } |
101 |
| - ) |
102 |
| - ( |
103 |
| - # we only want facter modules |
104 |
| - lib.filter ({ file, ... }: lib.hasPrefix modulePath file) definitionsWithLocations |
105 |
| - ) |
106 |
| - ) |
107 |
| - ) |
108 |
| - cfg.debug.options; |
109 |
| - }; |
110 |
| - |
111 | 31 | }
|
0 commit comments