Skip to content

Commit 2be33ee

Browse files
committed
Create a library for bootstrapping
This is useful for before we have a nixpkgs, for example.
1 parent c3f3fbb commit 2be33ee

File tree

3 files changed

+53
-18
lines changed

3 files changed

+53
-18
lines changed

boot.nix

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# This is a tentative public interface.
2+
#
3+
# We may decide to stablize it, but for now it is still UNSTABLE.
4+
5+
let
6+
inherit (import ./private.nix)
7+
contentsMatch
8+
isThunkWithThunkNix
9+
;
10+
11+
in {
12+
# This only works with newer thunks, and is intended for the
13+
# bootstrapping usecase where:
14+
#
15+
# - We don't yet have a `lib,` `pkgs`, or `gitignoreSource`
16+
#
17+
# - We just need the repo in question for Nix code, and not source
18+
# files to copy to the store.
19+
thunkSourceNoFilter = p:
20+
let
21+
contents = builtins.readDir p;
22+
in if isThunkWithThunkNix contents then import (p + "/thunk.nix")
23+
else p;
24+
}

default.nix

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,32 @@
1313
(import ./dep/gitignore.nix { inherit lib; }).gitignoreSource,
1414
}:
1515

16-
rec {
16+
let
17+
inherit (import ./private.nix)
18+
contentsMatch
19+
isThunkWithThunkNix
20+
;
21+
22+
in rec {
23+
1724
# Retrieve source that is controlled by the hack-* scripts; it may be either a
1825
# stub or a checked-out git repo
1926
thunkSource = p:
2027
let
2128
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
3631
filterArgs = x: removeAttrs x [ "branch" ];
3732
hasValidThunk = name: if builtins.pathExists (p + ("/" + name))
3833
then
39-
contentsMatch {
34+
contentsMatch contents {
4035
required = { ${name} = "regular"; };
4136
optional = { "default.nix" = "regular"; ".attr-cache" = "directory"; };
4237
}
4338
|| 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)."
4439
else false;
4540
in
46-
if isObeliskThunkWithThunkNix then import (p + "/thunk.nix")
47-
else if hasValidThunk "git.json" then (
41+
if hasValidThunk "git.json" then (
4842
let gitArgs = filterArgs (builtins.fromJSON (builtins.readFile (p + "/git.json")));
4943
in if builtins.elem "@" (lib.stringToCharacters gitArgs.url)
5044
then pkgs.fetchgitPrivate gitArgs

private.nix

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Private library functions.
2+
#
3+
# UNSTABLE, do not rely on this in external repos.
4+
rec {
5+
contentsMatch = contents: { required, optional }:
6+
(let all = required // optional; in all // contents == all)
7+
&& builtins.intersectAttrs required contents == required;
8+
9+
# Newer obelisk thunks include the feature of hackGet with a thunk.nix file in the thunk.
10+
isThunkWithThunkNix = contents:
11+
let
12+
packed = jsonFileName: {
13+
required = { ${jsonFileName} = "regular"; "default.nix" = "regular"; "thunk.nix" = "regular"; };
14+
optional = { ".attr-cache" = "directory"; };
15+
};
16+
in builtins.any (n: contentsMatch contents (packed n)) [ "git.json" "github.json" ];
17+
}

0 commit comments

Comments
 (0)