Created
July 28, 2015 23:05
-
-
Save adnelson/47963b076ce7ac1ba2f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
### THIS WORKS | |
# Fetches a package from a github repo. | |
fetchRepo = {repo, name, version, sha256}: | |
let | |
github_token = builtins.getEnv "GITHUB_TOKEN"; | |
url = "https://api.github.com/repos/adnelson/${repo}/tarball/${name}%2F${version}"; | |
curlCmd = "curl --fail -fL -H 'Authorization: token ${github_token}'"; | |
in | |
pkgs.stdenv.mkDerivation { | |
name = "${repo}-${name}-${version}-snapshot.tar.gz"; | |
buildInputs = [pkgs.curl pkgs.cacert]; | |
phases = ["buildPhase"]; | |
CURL_CA_BUNDLE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"; | |
buildPhase = '' | |
${curlCmd} ${url} > $out | |
''; | |
outputHash = sha256; | |
outputHashAlgo = "sha256"; | |
outputHashMode = "flat"; | |
}; | |
# Uses the repo fetched from `fetchRepo` to pull the package source out. | |
fetchPathInRepo = {repo, pathInRepo, name, version, sha256}: | |
let | |
fetchedRepo = fetchRepo {inherit repo name version sha256;}; | |
in | |
pkgs.runCommand "${name}-${version}-folder" {} '' | |
tar -xf ${fetchedRepo} | |
cp -r adnelson-${repo}-*/${pathInRepo} $out | |
''; | |
### THIS FAILS | |
# Fetches a package from a github repo. | |
fetchRepo = {repo, name, version, sha256}: | |
let | |
github_token = builtins.getEnv "GITHUB_TOKEN"; | |
url = "https://api.github.com/repos/adnelson/${repo}/tarball/${name}%2F${version}"; | |
curlCmd = "curl --fail -fL -H 'Authorization: token ${github_token}'"; | |
in | |
pkgs.stdenv.mkDerivation { | |
name = "${repo}-${name}-${version}-snapshot.tar.gz"; | |
buildInputs = [pkgs.curl pkgs.cacert]; | |
phases = ["buildPhase"]; | |
CURL_CA_BUNDLE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"; | |
buildPhase = '' | |
${curlCmd} ${url} > $out | |
''; | |
outputHash = sha256; | |
outputHashAlgo = "sha256"; | |
outputHashMode = "flat"; | |
}; | |
# Uses the repo fetched from `fetchRepo` to pull the package source out. | |
fetchPathInRepo = {repo, pathInRepo, name, version, sha256}: | |
let | |
fetchedRepo = fetchRepo {inherit repo name version sha256;}; | |
in | |
pkgs.runCommand "${name}-${version}-folder" { | |
buildInputs = [fetchedRepo]; | |
} '' | |
tar -xf ${fetchedRepo} | |
cp -r adnelson-${repo}-*/${pathInRepo} $out | |
''; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment