diff --git a/boot.nix b/boot.nix new file mode 100644 index 0000000..a2d4f48 --- /dev/null +++ b/boot.nix @@ -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; +} diff --git a/default.nix b/default.nix index f1f31aa..f3002e5 100644 --- a/default.nix +++ b/default.nix @@ -15,9 +15,17 @@ 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 @@ -25,32 +33,19 @@ rec { 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 diff --git a/lib.nix b/packaging.nix similarity index 100% rename from lib.nix rename to packaging.nix diff --git a/private.nix b/private.nix new file mode 100644 index 0000000..4ea4f7f --- /dev/null +++ b/private.nix @@ -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" ]; +} diff --git a/release.nix b/release.nix index 845be2b..92c337a 100644 --- a/release.nix +++ b/release.nix @@ -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; };