aboutsummaryrefslogtreecommitdiff
path: root/vendor/gen-vendor.py
diff options
context:
space:
mode:
authorAria Shrimpton <me@aria.rip>2024-01-25 17:52:12 +0000
committerAria Shrimpton <me@aria.rip>2024-01-25 17:52:12 +0000
commitb2a4a3d3c2632fba360962b76abf1cdb02b6f4b3 (patch)
tree7b357a24ee3e7ca08fc28bca22b6f702faa59624 /vendor/gen-vendor.py
parent3ad6406b1aa22f242c6695aa533e4325c682e76d (diff)
racket env in nix
Diffstat (limited to 'vendor/gen-vendor.py')
-rwxr-xr-xvendor/gen-vendor.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/vendor/gen-vendor.py b/vendor/gen-vendor.py
new file mode 100755
index 0000000..a38da61
--- /dev/null
+++ b/vendor/gen-vendor.py
@@ -0,0 +1,68 @@
+#!/usr/bin/env python
+import subprocess
+from os.path import exists
+import re
+
+# tee the output of the given command
+def run(cmd):
+ proc = subprocess.Popen(cmd,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE, encoding='utf-8')
+
+ outp = ""
+ while proc.poll() is None:
+ line = proc.stdout.readline()
+ if line:
+ print(line.strip())
+ outp += line
+ return outp
+
+pkgs = run(["raco", "pkg", "show", "-a", "--scope" ,"user"]).split("\n")
+catalog_pkg_names = [l.split(" ")[0].replace("*", "") for l in pkgs if "catalog" in l]
+
+print("Found %d packages" % len(catalog_pkg_names))
+
+infos = []
+for pkg in catalog_pkg_names:
+ info = run(["raco", "pkg", "catalog-show", pkg])
+ m = re.search(r'Source: (.*)', info)
+ url = m.group(1)
+ fname = url.split("/")[-1]
+ if not exists(fname):
+ run(["curl", "-OL", url])
+ infos.append((pkg, url, run(["nix", "hash", "file", fname]).strip()))
+
+# fetch files and install packages
+configurePhase = "mkdir -p $out\n" + "\n".join([
+ "raco pkg install --scope-dir $out -t dir -n %s --no-setup --deps force ${fetchurl { url = \"%s\"; hash = \"%s\"; }}" % (name, url, hash)
+ for (name, url, hash) in infos
+])
+
+# do building
+buildPhase = "raco pkg install --scope-dir $out --skip-installed " + " ".join(catalog_pkg_names)
+
+with open("./default.nix", "w") as f:
+ f.write("""
+{pkgs ? import <nixpkgs> {}, ...}: let
+ inherit (pkgs) fetchurl;
+ collection = pkgs.stdenv.mkDerivation {
+ name = "raco-catalog";
+ buildInputs = [pkgs.racket-minimal];
+ dontUnpack = true;
+
+ configurePhase = ''
+ %s
+ '';
+ buildPhase = "%s";
+ }; in
+ pkgs.stdenv.mkDerivation {
+ name = "racket-wrapped";
+ installPhase = ''
+ mkdir -p $out/bin
+ ln -s $out/pkgs ${collection};
+ mkWrapper ${pkgs.racket-minimal}/bin/racket \
+ $out/bin/racket \
+ --set PLTADDONDIR $out/pkgs;
+ '';
+ }
+ """ % (configurePhase, buildPhase))