|
| 1 | +{ lib }: |
| 2 | +with lib.types-simple; |
| 3 | + |
| 4 | +let |
| 5 | + # TODO: use the types from lib/systems/parse.nix |
| 6 | + # any should be lib.systems.parsed.types.system |
| 7 | + systemT = any; |
| 8 | + platformT = union [ string any ]; |
| 9 | + |
| 10 | + derivationPredicate = t: restrict { |
| 11 | + description = "<δ>";#: ${t.description}"; |
| 12 | + type = t; |
| 13 | + check = v: lib.isDerivation v |
| 14 | + # TODO it would be nice to have a custom |
| 15 | + # type error when this check fails. |
| 16 | + # `impureEnvVars` only makes sense in a |
| 17 | + # fixed-output derivation. |
| 18 | + # since we don’t check that all three |
| 19 | + # `outputHash*` attributes need exist, we use |
| 20 | + # one of them arbitrarily to check whether |
| 21 | + # this is a fixed-output derivation. |
| 22 | + && (v ? impureEnvVars -> v ? outputHashAlgo); |
| 23 | + }; |
| 24 | + |
| 25 | + metaT = productOpt { |
| 26 | + req = {}; |
| 27 | + opt = { |
| 28 | + # These keys are documented |
| 29 | + description = string; |
| 30 | + homepage = union [ (list string) string ]; |
| 31 | + longDescription = string; |
| 32 | + branch = string; |
| 33 | + downloadPage = string; |
| 34 | + license = |
| 35 | + let |
| 36 | + licenseT = productOpt { |
| 37 | + req = { |
| 38 | + shortName = string; |
| 39 | + fullName = string; |
| 40 | + free = bool; |
| 41 | + }; |
| 42 | + opt = { |
| 43 | + spdxId = string; |
| 44 | + url = string; |
| 45 | + }; |
| 46 | + }; |
| 47 | + in union [ licenseT (list licenseT) string ]; |
| 48 | + maintainers = list (productOpt { |
| 49 | + req = { |
| 50 | + name = string; |
| 51 | + email = string; |
| 52 | + }; |
| 53 | + opt = { |
| 54 | + github = string; |
| 55 | + }; |
| 56 | + }); |
| 57 | + priority = int; |
| 58 | + platforms = list platformT; |
| 59 | + hydraPlatforms = list platformT; |
| 60 | + broken = bool; |
| 61 | + tests = |
| 62 | + let |
| 63 | + testT = derivationPredicate (productOpt { |
| 64 | + open = true; |
| 65 | + opt = {}; |
| 66 | + req = { |
| 67 | + name = string; |
| 68 | + passthru = product { |
| 69 | + isVmTest = bool; |
| 70 | + }; |
| 71 | + # TODO: meta should reuse metaT and add some |
| 72 | + # fields to the req attribute |
| 73 | + meta = productOpt { |
| 74 | + open = true; |
| 75 | + req.description = string; |
| 76 | + opt.platforms = list platformT; |
| 77 | + }; |
| 78 | + }; |
| 79 | + }); |
| 80 | + in attrs testT; |
| 81 | + |
| 82 | + # Weirder stuff that doesn't appear in the documentation? |
| 83 | + knownVulnerabilities = list string; |
| 84 | + name = string; |
| 85 | + version = string; |
| 86 | + tag = string; |
| 87 | + updateWalker = bool; |
| 88 | + executables = list string; |
| 89 | + outputsToInstall = list string; |
| 90 | + position = string; |
| 91 | + available = bool; |
| 92 | + repositories = attrs string; |
| 93 | + isBuildPythonPackage = list platformT; |
| 94 | + schedulingPriority = int; |
| 95 | + downloadURLRegexp = string; |
| 96 | + isFcitxEngine = bool; |
| 97 | + isIbusEngine = bool; |
| 98 | + isGutenprint = bool; |
| 99 | + }; |
| 100 | + }; |
| 101 | + |
| 102 | + storePathT = restrict { |
| 103 | + description = "storepath"; |
| 104 | + type = string; |
| 105 | + check = lib.hasPrefix (toString builtins.storeDir); |
| 106 | + }; |
| 107 | + |
| 108 | + # fields and types taken from the manual |
| 109 | + derivationTArgs = { |
| 110 | + open = true; |
| 111 | + req = { |
| 112 | + name = string; |
| 113 | + system = string; |
| 114 | + builder = union [ storePathT path ]; |
| 115 | + }; |
| 116 | + opt = { |
| 117 | + args = let u = union [ string path ]; |
| 118 | + in union [ u (list u) ]; |
| 119 | + outputs = list string; |
| 120 | + meta = metaT; |
| 121 | + allowedReferences = list storePathT; |
| 122 | + allowedRequisites = list storePathT; |
| 123 | + # this type is crazy and we can’t check it correctly (see manual) |
| 124 | + exportReferencesGraph = list (union [ string storePathT ]); |
| 125 | + # see also `derivationPedicate.check` |
| 126 | + impureEnvVars = list string; |
| 127 | + passAsFile = list string; |
| 128 | + preferLocalBuild = bool; |
| 129 | + }; |
| 130 | + }; |
| 131 | + |
| 132 | + derivationT = derivationPredicate (productOpt derivationTArgs); |
| 133 | + |
| 134 | + derivationOnlyMetaT = derivationPredicate (productOpt { |
| 135 | + open = true; |
| 136 | + req = {}; |
| 137 | + opt.meta = metaT; |
| 138 | + }); |
| 139 | + |
| 140 | + mkDerivationT = derivationPredicate (productOpt { |
| 141 | + req = derivationTArgs.req; |
| 142 | + opt = derivationTArgs.opt // { |
| 143 | + buildInputs = list mkDerivationT; |
| 144 | + nativeBuildInputs = list (union [ mkDerivationT path ]); |
| 145 | + propagatedBuildInput = list mkDerivationT; |
| 146 | + propagatedNativeBuildInputs = list mkDerivationT; |
| 147 | + }; |
| 148 | + inherit (derivationTArgs) open; |
| 149 | + }); |
| 150 | + |
| 151 | +in { inherit derivationT derivationOnlyMetaT mkDerivationT; } |
0 commit comments