|
4 | 4 |
|
5 | 5 | with pkgs.haskell.lib; |
6 | 6 |
|
7 | | -let inherit (pkgs) lib; in rec { |
| 7 | +let nixThunkLib = import ./lib.nix { inherit (pkgs) lib; }; in rec { |
| 8 | + inherit (nixThunkLib) thunkSource mapSubdirectories; |
| 9 | + |
8 | 10 | # The version of nixpkgs that we use for fetching packing thunks (by |
9 | 11 | # themselves). Not to be used for building packages. |
10 | 12 | packedThunkNixpkgs = builtins.fetchTarball { |
@@ -107,51 +109,6 @@ let inherit (pkgs) lib; in rec { |
107 | 109 |
|
108 | 110 | inherit (import ./dep/gitignore.nix { inherit lib; }) gitignoreSource; |
109 | 111 |
|
110 | | - # Retrieve source that is controlled by the hack-* scripts; it may be either a stub or a checked-out git repo |
111 | | - thunkSource = p: |
112 | | - let |
113 | | - contents = builtins.readDir p; |
114 | | - |
115 | | - contentsMatch = { required, optional }: |
116 | | - (let all = required // optional; in all // contents == all) |
117 | | - && builtins.intersectAttrs required contents == required; |
118 | | - |
119 | | - # Newer obelisk thunks include the feature of hackGet with a thunk.nix file in the thunk. |
120 | | - isObeliskThunkWithThunkNix = |
121 | | - let |
122 | | - packed = jsonFileName: { |
123 | | - required = { ${jsonFileName} = "regular"; "default.nix" = "regular"; "thunk.nix" = "regular"; }; |
124 | | - optional = { ".attr-cache" = "directory"; }; |
125 | | - }; |
126 | | - in builtins.any (n: contentsMatch (packed n)) [ "git.json" "github.json" ]; |
127 | | - |
128 | | - filterArgs = x: removeAttrs x [ "branch" ]; |
129 | | - hasValidThunk = name: if builtins.pathExists (p + ("/" + name)) |
130 | | - then |
131 | | - contentsMatch { |
132 | | - required = { ${name} = "regular"; }; |
133 | | - optional = { "default.nix" = "regular"; ".attr-cache" = "directory"; }; |
134 | | - } |
135 | | - || 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)." |
136 | | - else false; |
137 | | - in |
138 | | - if isObeliskThunkWithThunkNix then import (p + "/thunk.nix") |
139 | | - else if hasValidThunk "git.json" then ( |
140 | | - let gitArgs = filterArgs (builtins.fromJSON (builtins.readFile (p + "/git.json"))); |
141 | | - in if builtins.elem "@" (lib.stringToCharacters gitArgs.url) |
142 | | - then pkgs.fetchgitPrivate gitArgs |
143 | | - else pkgs.fetchgit gitArgs |
144 | | - ) |
145 | | - else if hasValidThunk "github.json" then |
146 | | - pkgs.fetchFromGitHub (filterArgs (builtins.fromJSON (builtins.readFile (p + "/github.json")))) |
147 | | - else { |
148 | | - name = baseNameOf p; |
149 | | - outPath = gitignoreSource p; |
150 | | - }; |
151 | | - |
152 | | - #TODO: This really shouldn't include *all* symlinks, just ones that point at directories |
153 | | - mapSubdirectories = f: dir: lib.mapAttrs (name: _: f (dir + "/${name}")) (lib.filterAttrs (_: type: type == "directory" || type == "symlink") (builtins.readDir dir)); |
154 | | - |
155 | 112 | ############################################################################## |
156 | 113 | # Deprecated functions |
157 | 114 | ############################################################################## |
|
0 commit comments