|
| 1 | +{ |
| 2 | + lib, |
| 3 | + pkgs, |
| 4 | + sources, |
| 5 | + types' ? import ./types.nix { inherit lib; }, |
| 6 | +}: |
| 7 | +let |
| 8 | + inherit (builtins) |
| 9 | + elem |
| 10 | + readDir |
| 11 | + trace |
| 12 | + ; |
| 13 | + |
| 14 | + inherit (lib) |
| 15 | + types |
| 16 | + mkOption |
| 17 | + ; |
| 18 | + |
| 19 | + inherit (lib.attrsets) |
| 20 | + concatMapAttrs |
| 21 | + mapAttrs |
| 22 | + ; |
| 23 | + |
| 24 | + baseDirectory = ./.; |
| 25 | + |
| 26 | + projectDirectories = |
| 27 | + let |
| 28 | + names = |
| 29 | + name: type: |
| 30 | + if type == "directory" then |
| 31 | + { ${name} = baseDirectory + "/${name}"; } |
| 32 | + # nothing else should be kept in this directory reserved for projects |
| 33 | + else |
| 34 | + assert elem name allowedFiles; |
| 35 | + { }; |
| 36 | + allowedFiles = |
| 37 | + [ |
| 38 | + "README.md" |
| 39 | + "default.nix" |
| 40 | + "models.nix" |
| 41 | + ] |
| 42 | + # TODO: remove after fully migrating types to the module system |
| 43 | + ++ [ |
| 44 | + "default-module.nix" |
| 45 | + "types.nix" |
| 46 | + ]; |
| 47 | + in |
| 48 | + # TODO: use fileset and filter for `gitTracked` files |
| 49 | + concatMapAttrs names (readDir baseDirectory); |
| 50 | +in |
| 51 | +{ |
| 52 | + options.projects = mkOption { |
| 53 | + type = |
| 54 | + with types; |
| 55 | + attrsOf ( |
| 56 | + submodule ( |
| 57 | + { name, ... }: |
| 58 | + { |
| 59 | + name = mkOption { |
| 60 | + type = with types; nullOr str; |
| 61 | + default = name; |
| 62 | + }; |
| 63 | + metadata = mkOption { |
| 64 | + type = |
| 65 | + with types; |
| 66 | + nullOr (submodule { |
| 67 | + options = { |
| 68 | + summary = mkOption { |
| 69 | + type = nullOr str; |
| 70 | + default = null; |
| 71 | + }; |
| 72 | + # TODO: convert all subgrants to `subgrant`, remove listOf |
| 73 | + subgrants = mkOption { |
| 74 | + type = either (listOf str) types'.subgrant; |
| 75 | + default = null; |
| 76 | + }; |
| 77 | + links = mkOption { |
| 78 | + type = attrsOf types'.link; |
| 79 | + default = { }; |
| 80 | + }; |
| 81 | + }; |
| 82 | + }); |
| 83 | + default = null; |
| 84 | + }; |
| 85 | + binary = mkOption { |
| 86 | + type = with types; attrsOf types'.binary; |
| 87 | + default = { }; |
| 88 | + }; |
| 89 | + nixos = mkOption { |
| 90 | + type = |
| 91 | + with types; |
| 92 | + submodule { |
| 93 | + options = { |
| 94 | + services = mkOption { |
| 95 | + type = nullOr (attrsOf (nullOr types'.service)); |
| 96 | + default = null; |
| 97 | + }; |
| 98 | + programs = mkOption { |
| 99 | + type = nullOr (attrsOf (nullOr types'.program)); |
| 100 | + default = null; |
| 101 | + }; |
| 102 | + # An application component may have examples using it in isolation, |
| 103 | + # but examples may involve multiple application components. |
| 104 | + # Having examples at both layers allows us to trace coverage more easily. |
| 105 | + # If this tends to be too cumbersome for package authors and we find a way obtain coverage information programmatically, |
| 106 | + # we can still reduce granularity and move all examples to the application level. |
| 107 | + examples = mkOption { |
| 108 | + type = nullOr (attrsOf types'.example); |
| 109 | + default = null; |
| 110 | + }; |
| 111 | + # TODO: Tests should really only be per example, in order to clarify that we care about tested examples more than merely tests. |
| 112 | + # But reality is such that most NixOS tests aren't based on self-contained, minimal examples, or if they are they can't be extracted easily. |
| 113 | + # Without this field, many applications will appear entirely untested although there's actually *some* assurance that *something* works. |
| 114 | + # Eventually we want to move to documentable tests exclusively, and then remove this field, but this may take a very long time. |
| 115 | + tests = mkOption { |
| 116 | + type = nullOr (attrsOf types'.test); |
| 117 | + default = null; |
| 118 | + }; |
| 119 | + }; |
| 120 | + }; |
| 121 | + }; |
| 122 | + } |
| 123 | + ) |
| 124 | + ); |
| 125 | + }; |
| 126 | + |
| 127 | + config.projects = mapAttrs ( |
| 128 | + name: directory: import directory { inherit lib pkgs sources; } |
| 129 | + ) projectDirectories; |
| 130 | +} |
0 commit comments