about summary refs log tree commit diff
path: root/nix/buildLisp
diff options
context:
space:
mode:
authorsterni <sternenseemann@systemli.org>2021-08-11T08·45+0200
committersterni <sternenseemann@systemli.org>2021-08-24T22·00+0000
commitacb5994e87fd5aa306f63196fdef9c55cc6345f4 (patch)
treef905f99864773f035e19ef801e73c069adc6e836 /nix/buildLisp
parentd344637fe29d039f1046b6ebbbc4b649d61bf0b7 (diff)
feat(nix/buildLisp): allow implementation-specifc bundled functions r/2768
By implementing a bundled function for an implementation, we can use a
custom one for a specific implementation. This is useful for
implementations like ECL where a require will be compiled as an
instruction rather than importing all new symbols into a dump, so using
the underlying static or shared object directly would be beneficial.

overrideLisp for bundled libraries now only allows overriding the name
and implementation arguments.

Change-Id: I9036b29157e8daa4d86ff87d603b044373711dbf
Reviewed-on: https://cl.tvl.fyi/c/depot/+/3301
Tested-by: BuildkiteCI
Reviewed-by: tazjin <mail@tazj.in>
Diffstat (limited to 'nix/buildLisp')
-rw-r--r--nix/buildLisp/default.nix38
1 files changed, 32 insertions, 6 deletions
diff --git a/nix/buildLisp/default.nix b/nix/buildLisp/default.nix
index b1d852fbb5..d12c1ff1d9 100644
--- a/nix/buildLisp/default.nix
+++ b/nix/buildLisp/default.nix
@@ -124,6 +124,16 @@ let
   #   Builds a script (or dumped image) which when executed loads (or has
   #   loaded) all given dependencies. When built this should create an executable
   #   at "$out/bin/${implementation}".
+  #
+  # Optional members:
+  #
+  # - bundled :: string -> library
+  #   Allows giving an implementation specific builder for a bundled library.
+  #   This function is used as a replacement for the internal defaultBundled
+  #   function and only needs to support one implementation. The returned derivation
+  #   must behave like one built by 'library' (in particular have the same files
+  #   available in "$out" and the same 'passthru' attributes), but may be built
+  #   completely differently.
   impls = lib.mapAttrs (name: v: { inherit name; } // v) {
     sbcl = {
       runScript = "${sbcl}/bin/sbcl --script";
@@ -326,12 +336,28 @@ let
       wrapProgram $out/bin/${name} --prefix LD_LIBRARY_PATH : "${libPath}"
     '');
 
-  # 'bundled' creates a "library" that calls 'require' on a built-in
-  # package, such as any of SBCL's sb-* packages.
-  bundled = name: (makeOverridable library) {
-    inherit name;
-    srcs = lib.singleton (builtins.toFile "${name}.lisp" "(require '${name})");
-  };
+  # 'bundled' creates a "library" which makes a built-in package available,
+  # such as any of SBCL's sb-* packages or ASDF. By default this is done
+  # by calling 'require', but implementations are free to provide their
+  # own specific bundled function.
+  bundled = name:
+    let
+      # TODO(sterni): allow overriding args to underlying 'library' (e. g. srcs)
+      defaultBundled = implementation: name: library {
+        inherit name implementation;
+        srcs = lib.singleton (builtins.toFile "${name}.lisp" "(require '${name})");
+      };
+
+      bundled' =
+        { implementation ? defaultImplementation
+        , name
+        }:
+        impls."${implementation}".bundled or (defaultBundled implementation) name;
+
+    in (makeOverridable bundled') {
+      inherit name;
+    };
+
 in {
   library = makeOverridable library;
   program = makeOverridable program;