Skip to content

Instantly share code, notes, and snippets.

View adnelson's full-sized avatar

Allen Nelson adnelson

View GitHub Profile
def raise_msg(msg, path):
if len(path) > 0:
msg = 'At path {}: {}'.format('.'.join(path), msg)
raise AssertionError(msg)
def list_diff(list1, list2, path):
if len(list1) != len(list2):
raise_msg('List lengths differ: {} vs {}'
.format(len(list1), len(list2)), path)
for i, (obj1, obj2) in enumerate(zip(list1, list2)):
class ParseError(Exception):
pass
# Each parser function should take a list of characters and an index
# into that list, and return something that it parsed and a new index.
def parse_optionally(parser):
"""
Parses or returns None
"""
@adnelson
adnelson / default.nix
Last active April 12, 2017 04:05
Nix release builder
# Function which takes a list of packages to install and creates a
# tarball which contains the full list of dependencies of those paths,
# and a script which will install them.
#
# For example, here's how you would create a tarball packaging up
# python3 and nodejs:
#
#
# let
# pkgs = import <nixpkgs> {};
{
### 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 {