Skip to content

Instantly share code, notes, and snippets.

View adnelson's full-sized avatar

Allen Nelson adnelson

View GitHub Profile
{
### 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 {
@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> {};
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
"""
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)):
@adnelson
adnelson / uses_pv.nix
Created September 8, 2015 17:39
This should output something with PV, but it doesn't.
with import <pkgs>;
stdenv.mkDerivation {
name = "test_of_stuff";
buildInputs = [python pv];
buildCommand = ''
echo "doing some random stuff..."
cat <<EOF | python
import random, string, os
letters = string.letters + ' '
source $stdenv/setup
echo test1 > $out
export FOO=BAR
echo "FOO from d1 is: $FOO"
nan = float('nan')
def convert_nans(obj):
if isinstance(obj, list):
return [convert_nans(x) for x in obj]
elif isinstance(obj, dict):
return {k: convert_nans(v) for k, v in obj.iter()}
elif obj is nan or obj is None:
return None
elif isinstance(obj, (str, float, int)):
return obj
{pkgs}:
{
# Fetches a tag from a github repo.
fetchRepo = {owner, repo, tag, sha256, requireToken ? false}:
let
url = "https://api.github.com/repos/${owner}/${repo}/tarball/${tag}";
in
pkgs.stdenv.mkDerivation {
inherit requireToken;
name = "${repo}-${tag}-snapshot.tar.gz";
git clone https://github.com/adnelson/nixfromnpm
cd nixfromnpm
git checkout -b fetch_dev_dependencies
git pull origin fetch_dev_dependencies
nix-shell --pure
# In nix-shell:
cabal configure
cabal build
cabal run -- -p grunt -o results

Building nix with a repo over SSH

It's pretty simple to use a repo to aid the building of nix packages. You need:

  • Two machines, let's call them Builder and Repo.
  • Each machine has nix installed. Let's say that Repo has a nix installation owned by the user nix-repo, and Builder has one owned by nix-builder.
  • nix-builder is able to SSH into Repo as nix-repo.

Once you have this, to build a package on Builder using Repo: