Skip to content

Commit 6a64215

Browse files
committed
Create a library for bootstrapping
This is useful for before we have a nixpkgs, for example.
1 parent 5f41768 commit 6a64215

File tree

3 files changed

+55
-19
lines changed

3 files changed

+55
-19
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: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,37 @@ let defaultInputs = import ./defaultInputs.nix; in
1515
(import ./dep/gitignore.nix { inherit lib; }).gitignoreSource,
1616
}:
1717

18-
let myLib = import ./lib.nix { inherit haskell-nix pkgs; }; in
18+
let
19+
20+
myLib = import ./lib.nix { inherit haskell-nix pkgs; }; in
21+
22+
inherit (import ./private.nix)
23+
contentsMatch
24+
isThunkWithThunkNix
25+
;
26+
27+
in rec {
1928

20-
rec {
2129
command = (myLib.perGhc {}).command;
2230

2331
# Retrieve source that is controlled by the hack-* scripts; it may be either a
2432
# stub or a checked-out git repo
2533
thunkSource = p:
2634
let
2735
contents = builtins.readDir p;
28-
29-
contentsMatch = { required, optional }:
30-
(let all = required // optional; in all // contents == all)
31-
&& builtins.intersectAttrs required contents == required;
32-
33-
# Newer obelisk thunks include the feature of hackGet with a thunk.nix file in the thunk.
34-
isObeliskThunkWithThunkNix =
35-
let
36-
packed = jsonFileName: {
37-
required = { ${jsonFileName} = "regular"; "default.nix" = "regular"; "thunk.nix" = "regular"; };
38-
optional = { ".attr-cache" = "directory"; };
39-
};
40-
in builtins.any (n: contentsMatch (packed n)) [ "git.json" "github.json" ];
41-
36+
in if isThunkWithThunkNix contents then import (p + "/thunk.nix")
37+
else let # legacy cases
4238
filterArgs = x: removeAttrs x [ "branch" ];
4339
hasValidThunk = name: if builtins.pathExists (p + ("/" + name))
4440
then
45-
contentsMatch {
41+
contentsMatch contents {
4642
required = { ${name} = "regular"; };
4743
optional = { "default.nix" = "regular"; ".attr-cache" = "directory"; };
4844
}
4945
|| 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)."
5046
else false;
5147
in
52-
if isObeliskThunkWithThunkNix then import (p + "/thunk.nix")
53-
else if hasValidThunk "git.json" then (
48+
if hasValidThunk "git.json" then (
5449
let gitArgs = filterArgs (builtins.fromJSON (builtins.readFile (p + "/git.json")));
5550
in if builtins.elem "@" (lib.stringToCharacters gitArgs.url)
5651
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)