Skip to content

Instantly share code, notes, and snippets.

🌮

Profpatsch

🌮
Block or report user

Report or block Profpatsch

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View nix-realize-in-build.nix
with import <nixpkgs> {};
let nixBin = "${pkgs.nix}/bin"; in
runCommand "foo" {}
''
set -e
datadir="${pkgs.nix}/share"
export TEST_ROOT=$(pwd)/test-tmp
export NIX_BUILD_HOOK=
export NIX_CONF_DIR=$TEST_ROOT/etc
export NIX_DB_DIR=$TEST_ROOT/db
@Profpatsch
Profpatsch / importBazelLocalCache.nix
Created Nov 6, 2018
Import all subfiles of a bazel local cache (content-addressable hash for each artifact) into the nix store, one derivation each
View importBazelLocalCache.nix
{ nixpkgs ? import <nixpkgs> {} }:
let
inherit (nixpkgs) lib;
importBazelLocalCache = cacheDir:
let
fileList = lib.mapAttrs
(dirname: type:
# sanity check
assert lib.assertMsg (type == "directory" || type == "regular")
@Profpatsch
Profpatsch / sexpr.dhall
Created Aug 14, 2018
dhall & dada s-expressions
View sexpr.dhall
let id = ./dada/id
in let SexprF = λ(f : Type) < Str : Text | Int : Integer | Sexpr : List f >
in let SexprC = λ(f : Type) constructors (SexprF f)
in let map =
λ(a : Type)
λ(b : Type)
λ(fn : a b)
@Profpatsch
Profpatsch / bazel-caching.nix
Last active Jul 18, 2018
Use `--disk_cache` to share the bazel cache between multiple derivations
View bazel-caching.nix
# This file uses the `--disk_cache` argument to share bazel caches
# between separate nix builds. Proof-of-work
# The second build succeds (after analyze phase) with:
# `INFO: 3 processes: 3 remote cache hit.`
with import <nixpkgs> {};
let
bazel-example = { name, buildPhase, caches }: stdenv.mkDerivation {
inherit name;
@Profpatsch
Profpatsch / GenericZipper.hs
Last active Jul 8, 2018
Going from a type implementing Generic1 to a Holey (which can be used to get a Zipper for free)
View GenericZipper.hs
{-# LANGUAGE TypeSynonymInstances, FlexibleInstances, MultiParamTypeClasses, TypeOperators, FlexibleContexts, TypeFamilies #-}
module FunctorCombo.Generic (
encode
) where
import GHC.Generics
import qualified FunctorCombo.Functor as F
class Encode gen where
type DerG gen :: * -> *
@Profpatsch
Profpatsch / enrich.hs
Created Apr 22, 2018
Enrich any type class with new methods without depending OrphanInstances
View enrich.hs
{-# LANGUAGE FlexibleInstances #-}
module Main where
import Data.Monoid
-- This definition would be in another module
class Monoid a => Group a where
inverse :: a -> a
newtype Enrich with a =
View nq.nix
{ lib, pkgs, stdenv }:
{ libPath ? <nixpkgs/lib> }:
# TODO: Do we need all of lib?
let
trans = pkgs.writeScript "nix-json-trans" ''
#!${stdenv.shell}
DIR=$(mktemp -d)
cat >$DIR/script-input.nix <<EOF
with import ${libPath};
@Profpatsch
Profpatsch / recursive.nix
Created Apr 5, 2018
Next iteration of bananas & barbed wire
View recursive.nix
with import <nixpkgs> {};
let
Recursive = { fmap, project }: {
cata = alg:
let c = val: alg (fmap c (project val));
in c;
};
matchDef = def: matcher: v:
View scrub.nix
with import <nixpkgs> {};
let
collectDeps = drv:
(lib.collect (v: (lib.isDerivation v && v != drv))) drv;
scrubDrv = f: drv: {
name = drv.name;
drv = drv;
deps = map f (collectDeps drv.drvAttrs);
@Profpatsch
Profpatsch / derivation-type-sigs.nix
Created Apr 4, 2018
Type signatures for derivations
View derivation-type-sigs.nix
{ lib }:
with lib.types-simple;
let
# TODO: use the types from lib/systems/parse.nix
# any should be lib.systems.parsed.types.system
systemT = any;
platformT = union [ string any ];
derivationPredicate = t: restrict {
You can’t perform that action at this time.