Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions boot.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This is a tentative public interface.
#
# We may decide to stablize it, but for now it is still UNSTABLE.

let
inherit (import ./private.nix)
contentsMatch
isThunkWithThunkNix
;

in {
# This only works with newer thunks, and is intended for the
# bootstrapping usecase where:
#
# - We don't yet have a `lib,` `pkgs`, or `gitignoreSource`
#
# - We just need the repo in question for Nix code, and not source
# files to copy to the store.
thunkSourceNoFilter = p:
let
contents = builtins.readDir p;
in if isThunkWithThunkNix contents then import (p + "/thunk.nix")
else p;
}
33 changes: 14 additions & 19 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,37 @@ let defaultInputs = import ./defaultInputs.nix; in
(import ./dep/gitignore.nix { inherit lib; }).gitignoreSource,
}:

let myLib = import ./lib.nix { inherit haskell-nix pkgs; }; in
let

myLib = import ./lib.nix { inherit haskell-nix pkgs; }; in

inherit (import ./private.nix)
contentsMatch
isThunkWithThunkNix
;

in rec {

rec {
command = (myLib.perGhc {}).command;

# Retrieve source that is controlled by the hack-* scripts; it may be either a
# stub or a checked-out git repo
thunkSource = p:
let
contents = builtins.readDir p;

contentsMatch = { required, optional }:
(let all = required // optional; in all // contents == all)
&& builtins.intersectAttrs required contents == required;

# Newer obelisk thunks include the feature of hackGet with a thunk.nix file in the thunk.
isObeliskThunkWithThunkNix =
let
packed = jsonFileName: {
required = { ${jsonFileName} = "regular"; "default.nix" = "regular"; "thunk.nix" = "regular"; };
optional = { ".attr-cache" = "directory"; };
};
in builtins.any (n: contentsMatch (packed n)) [ "git.json" "github.json" ];

in if isThunkWithThunkNix contents then import (p + "/thunk.nix")
else let # legacy cases
filterArgs = x: removeAttrs x [ "branch" ];
hasValidThunk = name: if builtins.pathExists (p + ("/" + name))
then
contentsMatch {
contentsMatch contents {
required = { ${name} = "regular"; };
optional = { "default.nix" = "regular"; ".attr-cache" = "directory"; };
}
|| 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)."
else false;
in
if isObeliskThunkWithThunkNix then import (p + "/thunk.nix")
else if hasValidThunk "git.json" then (
if hasValidThunk "git.json" then (
let gitArgs = filterArgs (builtins.fromJSON (builtins.readFile (p + "/git.json")));
in if builtins.elem "@" (lib.stringToCharacters gitArgs.url)
then pkgs.fetchgitPrivate gitArgs
Expand Down
File renamed without changes.
17 changes: 17 additions & 0 deletions private.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Private library functions.
#
# UNSTABLE, do not rely on this in external repos.
rec {
contentsMatch = contents: { required, optional }:
(let all = required // optional; in all // contents == all)
&& builtins.intersectAttrs required contents == required;

# Newer obelisk thunks include the feature of hackGet with a thunk.nix file in the thunk.
isThunkWithThunkNix = contents:
let
packed = jsonFileName: {
required = { ${jsonFileName} = "regular"; "default.nix" = "regular"; "thunk.nix" = "regular"; };
optional = { ".attr-cache" = "directory"; };
};
in builtins.any (n: contentsMatch contents (packed n)) [ "git.json" "github.json" ];
}
2 changes: 1 addition & 1 deletion release.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let versions = import ./versions.nix;
nix-thunk = import ./lib.nix {};
nix-thunk = import ./packaging.nix {};
instances = builtins.listToAttrs (map (ghcVersion: {
name = ghcVersion;
value = nix-thunk.perGhc { ghc = ghcVersion; };
Expand Down