on master help sign in
Add new loader for GitHub

This can use Nix 2.0’s builtins.fetchTarball if it is available. If not, it will fall back on old behavior.

commitc9283da0fd31d2d8ed3e659cdb2ec5f74318f1df authorMatthew Bauer <mjbauer95@gmail.com> dateThu 24 Jan 2019, 15:02 (8 years ago) parent4cdeba6
1 file changed+28−2
lib/command/src/Obelisk/Command/Thunk.hs+28−2
lib/command/src/Obelisk/Command/Thunk.hs+28−2
@@ -415,8 +415,9 @@ setThunk target gs branch = do
415415-- This tool will only ever produce the newest one when it writes a thunk.
416416gitHubStandaloneLoaders :: NonEmpty Text
417417gitHubStandaloneLoaders =
418− gitHubStandaloneLoaderV2 :|
419− [ gitHubStandaloneLoaderV3
418+ gitHubStandaloneLoaderV4 :|
419+ [ gitHubStandaloneLoaderV2
420+ , gitHubStandaloneLoaderV3
420421 , gitHubStandaloneLoaderV1
421422 ]
422423
@@ -456,6 +457,31 @@ gitHubStandaloneLoaderV3 = T.unlines
456457 , "in import (fetch (builtins.fromJSON (builtins.readFile ./github.json)))"
457458 ]
458459
460+gitHubStandaloneLoaderV4 :: Text
461+gitHubStandaloneLoaderV4 = T.unlines
462+ [ "# DO NOT HAND-EDIT THIS FILE"
463+ , "let"
464+ , " fetch = { private ? false, ... }@args:"
465+ , " if private && builtins.hasAttr \"fetchGit\" builtins"
466+ , " then fetchFromGitHubPrivate args"
467+ , " else fetchFromGitHub (builtins.removeAttrs args [\"branch\"]);"
468+ , " fetchFromGitHub = if builtins.hasAttr \"fetchTarball\" builtins then"
469+ , " ({ owner, repo, rev, sha256, ... }: builtins.fetchTarball {"
470+ , " url = \"https://github.com/${owner}/${repo}/archive/${rev}.tar.gz\";"
471+ , " inherit sha256; })"
472+ , " else (import <nixpkgs> {}).fetchFromGitHub;"
473+ , " fetchFromGitHubPrivate ="
474+ , " { owner, repo, rev, branch ? null, name ? null, sha256 ? null"
475+ , " , private ? false, fetchSubmodules ? false"
476+ , " , githubBase ? \"github.com\", ...}: assert !fetchSubmodules;"
477+ , " builtins.fetchGit ({"
478+ , " url = \"ssh://git@${githubBase}/${owner}/${repo}.git\";"
479+ , " inherit rev;"
480+ , " } // (if branch == null then {} else { ref = branch; })"
481+ , " // (if name == null then {} else { inherit name; }));"
482+ , "in import (fetch (builtins.fromJSON (builtins.readFile ./github.json)))"
483+ ]
484+
459485plainGitStandaloneLoaders :: NonEmpty Text
460486plainGitStandaloneLoaders =
461487 plainGitStandaloneLoaderV1 :|