|
38 | 38 | let |
39 | 39 | envVarName = "NPINS_OVERRIDE_${saneName}"; |
40 | 40 | saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; |
41 | | - ersatz = builtins.getEnv envVarName; |
| 41 | + replacement = builtins.getEnv envVarName; |
42 | 42 | in |
43 | | - if ersatz == "" then |
| 43 | + if replacement == "" then |
44 | 44 | path |
45 | 45 | else |
46 | 46 | # this turns the string into an actual Nix path (for both absolute and |
47 | 47 | # relative paths) |
48 | | - builtins.trace "Overriding path of \"${name}\" with \"${ersatz}\" due to set \"${envVarName}\"" ( |
49 | | - if builtins.substring 0 1 ersatz == "/" then |
50 | | - /. + ersatz |
51 | | - else |
52 | | - /. + builtins.getEnv "PWD" + "/${ersatz}" |
53 | | - ); |
| 48 | + builtins.trace "Overriding path of \"${name}\" with \"${replacement}\" due to set \"${envVarName}\"" |
| 49 | + ( |
| 50 | + if builtins.substring 0 1 replacement == "/" then |
| 51 | + /. + replacement |
| 52 | + else |
| 53 | + /. + builtins.getEnv "PWD" + "/${replacement}" |
| 54 | + ); |
54 | 55 |
|
55 | 56 | mkSource = |
56 | 57 | name: spec: |
57 | 58 | { |
58 | 59 | pkgs ? null, |
| 60 | + patches ? [ ], |
59 | 61 | }: |
60 | 62 | assert spec ? type; |
61 | 63 | let |
|
98 | 100 | }; |
99 | 101 |
|
100 | 102 | path = |
101 | | - if spec.type == "Git" then |
102 | | - mkGitSource fetchers spec |
103 | | - else if spec.type == "GitRelease" then |
104 | | - mkGitSource fetchers spec |
105 | | - else if spec.type == "PyPi" then |
106 | | - mkPyPiSource fetchers spec |
107 | | - else if spec.type == "Channel" then |
108 | | - mkChannelSource fetchers spec |
109 | | - else if spec.type == "Url" || spec.type == "MutableUrl" then |
110 | | - mkUrlSource fetchers spec |
111 | | - else if spec.type == "Container" then |
112 | | - mkContainerSource pkgs spec |
| 103 | + { |
| 104 | + "Git" = mkGitSource fetchers spec; |
| 105 | + "GitRelease" = mkGitSource fetchers spec; |
| 106 | + "PyPi" = mkPyPiSource fetchers spec; |
| 107 | + "Channel" = mkChannelSource fetchers spec; |
| 108 | + "Url" = mkUrlSource fetchers spec; |
| 109 | + "MutableUrl" = mkUrlSource fetchers spec; |
| 110 | + "Container" = mkContainerSource pkgs spec; |
| 111 | + } |
| 112 | + .${spec.type} or (builtins.throw "Unknown source type ${spec.type}"); |
| 113 | + |
| 114 | + overridePath = mayOverride name path; |
| 115 | + patchedPath = |
| 116 | + if patches == [ ] then |
| 117 | + overridePath |
| 118 | + else if pkgs != null then |
| 119 | + pkgs.applyPatches { |
| 120 | + inherit name patches; |
| 121 | + src = overridePath; |
| 122 | + } |
113 | 123 | else |
114 | | - builtins.throw "Unknown source type ${spec.type}"; |
| 124 | + builtins.throw "${name}: pkgs is required to apply patches"; |
115 | 125 | in |
116 | | - spec // { outPath = mayOverride name path; }; |
| 126 | + spec |
| 127 | + // { |
| 128 | + outPath = patchedPath; |
| 129 | + unpatchedPath = overridePath; |
| 130 | + }; |
117 | 131 |
|
118 | 132 | mkGitSource = |
119 | 133 | { |
|
0 commit comments