From 6c85a7b8ee2bd135a5c7f9abd99f5f2d75599717 Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Fri, 22 Oct 2021 13:04:45 +0100 Subject: Add beginnings of stdenv --- stdenv.nix | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 stdenv.nix (limited to 'stdenv.nix') diff --git a/stdenv.nix b/stdenv.nix new file mode 100644 index 0000000..607ed76 --- /dev/null +++ b/stdenv.nix @@ -0,0 +1,42 @@ +{ bash +, writeTextFile +, ... +}: + +rec { + + mkDerivations = x: derivations (spread (removeAttrs x [ "variations" ]) x.variations); + + spread = x: ys: map (y: x // y) ys; + + addDefaults = + let + opt = x: a: if builtins.hasAttr a x then builtins.getAttr a x else ""; + + res = x: defaults x // x; + + buildScript = x: writeTextFile { + name = "build_script.sh"; + executable = true; + text = '' + ${opt (res x) "unpack"} + ${opt (res x) "build"} + ${opt (res x) "check"} + ${opt (res x) "install"} + ${opt (res x) "checkInstall"} + ''; + }; + + defaults = x: { + name = "${x.pname}-${x.version}"; + system = builtins.currentSystem; + builder = "${bash}/bin/bash"; + args = [ "-e" (buildScript x) ]; + }; + in res; + + derivations = map (x: derivation (addDefaults x)); + + attrMap = f: builtins.foldl' (x: y: x // f y) {}; + attrMap' = f: xs: builtins.listToAttrs (map f xs); +} -- cgit v1.2.1