aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fetch.nix41
-rw-r--r--stdenv.nix42
2 files changed, 83 insertions, 0 deletions
diff --git a/fetch.nix b/fetch.nix
new file mode 100644
index 0000000..78cbf9a
--- /dev/null
+++ b/fetch.nix
@@ -0,0 +1,41 @@
+{ bash
+, coreutils
+, writeTextFile
+, unzip
+, ...
+}:
+
+let fetch = rec {
+
+ tar = builtins.fetchTarball;
+ url = builtins.fetchurl;
+
+ zip =
+ { url
+ , sha256
+ , name ? "unnamed-zipfile"
+ }@x:
+
+ builtins.trace x
+
+ derivation rec {
+ inherit name;
+
+ src = fetch.url x.url;
+
+ buildScript = writeTextFile {
+ name = "${name}.zip-downloader";
+ executable = true;
+
+ text = ''
+ ${coreutils}/bin/mkdir -p $out
+ ${unzip}/bin/unzip -d $out $src
+ '';
+ };
+
+ builder = "${bash}/bin/bash";
+ args = [ "-e" buildScript ];
+ system = builtins.currentSystem;
+ };
+
+}; in fetch
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);
+}