Created
February 27, 2017 15:41
Simple overrides vs Old-style overrides
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
let | |
inherit (import <nixpkgs> {}) lib stdenv; | |
# helper to make a really simply derivation | |
deriv = { name, deps, buildDeps, ... }: stdenv.mkDerivation { | |
inherit name; | |
deps = deps (lib.mapAttrs (_: pkg: pkg.drvBuilder pkg) buildDeps); | |
buildCommand = "cat $deps > $out"; | |
}; | |
asDerivation = lib.mapAttrs (_: pkg: pkg.drvBuilder pkg); | |
close = super: set: let s = lib.mapAttrs (_: pkg: pkg s super) set; in s; | |
pkgs = { | |
foo = self: super: { | |
name = "foo"; | |
buildDeps = {}; | |
deps = ctx: []; | |
drvBuilder = deriv; | |
}; | |
bar = self: super: { | |
name = "bar"; | |
buildDeps = { inherit (self) foo; }; | |
deps = ctx: [ ctx.foo ]; | |
drvBuilder = deriv; | |
}; | |
qux = self: super: { | |
name = "qux"; | |
buildDeps = { inherit (self) foo bar; }; | |
deps = ctx: [ ctx.foo ctx.bar ]; drvBuilder = deriv; | |
}; | |
}; | |
in asDerivation (close {} pkgs) |
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
let | |
inherit (import <nixpkgs>) stdenv lib; | |
# very simple callPackage implementation, only supports overriding, no auto-finding deps | |
callPackage = fun: args: fun args // { | |
override = f: callPackage fun (f args); | |
}; | |
# helper to make a really simply derivation | |
deriv = name: deps: (import <nixpkgs> {}).stdenv.mkDerivation { | |
inherit name deps; | |
buildCommand = "cat $deps > $out"; | |
}; | |
pkgs = rec { | |
foo = callPackage ({}: deriv "foo" []) {}; | |
bar = callPackage ({ foo }: deriv "bar" [ foo ]) { inherit foo; }; | |
qux = callPackage ({ foo, bar }: deriv "qux" [ foo bar ]) { inherit foo bar; }; | |
}; | |
in pkgs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment