|
13 | 13 | (import ./dep/gitignore.nix { inherit lib; }).gitignoreSource, |
14 | 14 | }: |
15 | 15 |
|
16 | | -rec { |
| 16 | +let |
| 17 | + inherit (import ./private.nix) |
| 18 | + contentsMatch |
| 19 | + isThunkWithThunkNix |
| 20 | + ; |
| 21 | + |
| 22 | +in rec { |
| 23 | + |
17 | 24 | # Retrieve source that is controlled by the hack-* scripts; it may be either a |
18 | 25 | # stub or a checked-out git repo |
19 | 26 | thunkSource = p: |
20 | 27 | let |
21 | 28 | contents = builtins.readDir p; |
22 | | - |
23 | | - contentsMatch = { required, optional }: |
24 | | - (let all = required // optional; in all // contents == all) |
25 | | - && builtins.intersectAttrs required contents == required; |
26 | | - |
27 | | - # Newer obelisk thunks include the feature of hackGet with a thunk.nix file in the thunk. |
28 | | - isObeliskThunkWithThunkNix = |
29 | | - let |
30 | | - packed = jsonFileName: { |
31 | | - required = { ${jsonFileName} = "regular"; "default.nix" = "regular"; "thunk.nix" = "regular"; }; |
32 | | - optional = { ".attr-cache" = "directory"; }; |
33 | | - }; |
34 | | - in builtins.any (n: contentsMatch (packed n)) [ "git.json" "github.json" ]; |
35 | | - |
| 29 | + in if isThunkWithThunkNix contents then import (p + "/thunk.nix") |
| 30 | + else let # legacy cases |
36 | 31 | filterArgs = x: removeAttrs x [ "branch" ]; |
37 | 32 | hasValidThunk = name: if builtins.pathExists (p + ("/" + name)) |
38 | 33 | then |
39 | | - contentsMatch { |
| 34 | + contentsMatch contents { |
40 | 35 | required = { ${name} = "regular"; }; |
41 | 36 | optional = { "default.nix" = "regular"; ".attr-cache" = "directory"; }; |
42 | 37 | } |
43 | 38 | || throw "Thunk at ${toString p} has files in addition to ${name} and optionally default.nix and .attr-cache. Remove either ${name} or those other files to continue (check for leftover .git too)." |
44 | 39 | else false; |
45 | 40 | in |
46 | | - if isObeliskThunkWithThunkNix then import (p + "/thunk.nix") |
47 | | - else if hasValidThunk "git.json" then ( |
| 41 | + if hasValidThunk "git.json" then ( |
48 | 42 | let gitArgs = filterArgs (builtins.fromJSON (builtins.readFile (p + "/git.json"))); |
49 | 43 | in if builtins.elem "@" (lib.stringToCharacters gitArgs.url) |
50 | 44 | then pkgs.fetchgitPrivate gitArgs |
|
0 commit comments