about summary refs log tree commit diff
path: root/nix/buildLisp
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-01-30T16·06+0300
committertazjin <tazjin@tvl.su>2022-01-31T16·11+0000
commitaa122cbae78ce97d60c0c98ba14df753d97e40b1 (patch)
tree12b98d85c4b18fe870feb26de70db9ba61837bd7 /nix/buildLisp
parent2d10d60fac0fd00a71b65cfdcb9fba0477b2086c (diff)
style: format entire depot with nixpkgs-fmt r/3723
This CL can be used to compare the style of nixpkgs-fmt against other
formatters (nixpkgs, alejandra).

Change-Id: I87c6abff6bcb546b02ead15ad0405f81e01b6d9e
Reviewed-on: https://cl.tvl.fyi/c/depot/+/4397
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Reviewed-by: lukegb <lukegb@tvl.fyi>
Reviewed-by: wpcarro <wpcarro@gmail.com>
Reviewed-by: Profpatsch <mail@profpatsch.de>
Reviewed-by: kanepyork <rikingcoding@gmail.com>
Reviewed-by: tazjin <tazjin@tvl.su>
Reviewed-by: cynthia <cynthia@tvl.fyi>
Reviewed-by: edef <edef@edef.eu>
Reviewed-by: eta <tvl@eta.st>
Reviewed-by: grfn <grfn@gws.fyi>
Diffstat (limited to 'nix/buildLisp')
-rw-r--r--nix/buildLisp/default.nix277
-rw-r--r--nix/buildLisp/example/default.nix19
2 files changed, 165 insertions, 131 deletions
diff --git a/nix/buildLisp/default.nix b/nix/buildLisp/default.nix
index ab23b30210..30b90d9049 100644
--- a/nix/buildLisp/default.nix
+++ b/nix/buildLisp/default.nix
@@ -4,7 +4,7 @@
 # buildLisp is designed to enforce conventions and do away with the
 # free-for-all of existing Lisp build systems.
 
-{ pkgs ? import <nixpkgs> {}, ... }:
+{ pkgs ? import <nixpkgs> { }, ... }:
 
 let
   inherit (builtins) map elemAt match filter;
@@ -70,11 +70,16 @@ let
   implFilter = impl: xs:
     let
       isFilterSet = x: builtins.isAttrs x && !(lib.isDerivation x);
-    in builtins.map (
-      x: if isFilterSet x then x.${impl.name} or x.default else x
-    ) (builtins.filter (
-      x: !(isFilterSet x) || x ? ${impl.name} || x ? default
-    ) xs);
+    in
+    builtins.map
+      (
+        x: if isFilterSet x then x.${impl.name} or x.default else x
+      )
+      (builtins.filter
+        (
+          x: !(isFilterSet x) || x ? ${impl.name} || x ? default
+        )
+        xs);
 
   # Generates lisp code which instructs the given lisp implementation to load
   # all the given dependencies.
@@ -103,17 +108,21 @@ let
   # 'allDeps' flattens the list of dependencies (and their
   # dependencies) into one ordered list of unique deps which
   # all use the given implementation.
-  allDeps = impl: deps: let
-    # The override _should_ propagate itself recursively, as every derivation
-    # would only expose its actually used dependencies. Use implementation
-    # attribute created by withExtras if present, override in all other cases
-    # (mainly bundled).
-    deps' = builtins.map (dep: dep."${impl.name}" or (dep.overrideLisp (_: {
-      implementation = impl;
-    }))) deps;
-  in (lib.toposort dependsOn (lib.unique (
-    lib.flatten (deps' ++ (map (d: d.lispDeps) deps'))
-  ))).result;
+  allDeps = impl: deps:
+    let
+      # The override _should_ propagate itself recursively, as every derivation
+      # would only expose its actually used dependencies. Use implementation
+      # attribute created by withExtras if present, override in all other cases
+      # (mainly bundled).
+      deps' = builtins.map
+        (dep: dep."${impl.name}" or (dep.overrideLisp (_: {
+          implementation = impl;
+        })))
+        deps;
+    in
+    (lib.toposort dependsOn (lib.unique (
+      lib.flatten (deps' ++ (map (d: d.lispDeps) deps'))
+    ))).result;
 
   # 'allNative' extracts all native dependencies of a dependency list
   # to ensure that library load paths are set correctly during all
@@ -138,42 +147,49 @@ let
   withExtras = f: args:
     let
       drv = (makeOverridable f) args;
-    in lib.fix (self:
-      drv.overrideLisp (old:
-        let
-          implementation = old.implementation or defaultImplementation;
-          brokenOn = old.brokenOn or [];
-          targets = lib.subtractLists (brokenOn ++ [ implementation.name ])
-            (builtins.attrNames impls);
-        in {
-          passthru = (old.passthru or {}) // {
-            repl = implementation.lispWith [ self ];
-
-            # meta is done via passthru to minimize rebuilds caused by overriding
-            meta = (old.passthru.meta or {}) // {
-              inherit targets;
-            };
-          } // builtins.listToAttrs (builtins.map (impl: {
-            inherit (impl) name;
-            value = self.overrideLisp (_: {
-              implementation = impl;
-            });
-          }) (builtins.attrValues impls));
-        }) // {
-          overrideLisp = new: withExtras f (args // new args);
-        });
+    in
+    lib.fix (self:
+      drv.overrideLisp
+        (old:
+          let
+            implementation = old.implementation or defaultImplementation;
+            brokenOn = old.brokenOn or [ ];
+            targets = lib.subtractLists (brokenOn ++ [ implementation.name ])
+              (builtins.attrNames impls);
+          in
+          {
+            passthru = (old.passthru or { }) // {
+              repl = implementation.lispWith [ self ];
+
+              # meta is done via passthru to minimize rebuilds caused by overriding
+              meta = (old.passthru.meta or { }) // {
+                inherit targets;
+              };
+            } // builtins.listToAttrs (builtins.map
+              (impl: {
+                inherit (impl) name;
+                value = self.overrideLisp (_: {
+                  implementation = impl;
+                });
+              })
+              (builtins.attrValues impls));
+          }) // {
+        overrideLisp = new: withExtras f (args // new args);
+      });
 
   # 'testSuite' builds a Common Lisp test suite that loads all of srcs and deps,
   # and then executes expression to check its result
-  testSuite = { name, expression, srcs, deps ? [], native ? [], implementation }:
+  testSuite = { name, expression, srcs, deps ? [ ], native ? [ ], implementation }:
     let
       lispDeps = allDeps implementation (implFilter implementation deps);
       lispNativeDeps = allNative native lispDeps;
       filteredSrcs = implFilter implementation srcs;
-    in runCommandNoCC name {
-      LD_LIBRARY_PATH = lib.makeLibraryPath lispNativeDeps;
-      LANG = "C.UTF-8";
-    } ''
+    in
+    runCommandNoCC name
+      {
+        LD_LIBRARY_PATH = lib.makeLibraryPath lispNativeDeps;
+        LANG = "C.UTF-8";
+      } ''
       echo "Running test suite ${name}"
 
       ${implementation.runScript} ${
@@ -452,15 +468,16 @@ let
           } $@
         '';
 
-      bundled = name: runCommandNoCC "${name}-cllib" {
-        passthru = {
-          lispName = name;
-          lispNativeDeps = [];
-          lispDeps = [];
-          lispBinary = false;
-          repl = impls.ecl.lispWith [ (impls.ecl.bundled name) ];
-        };
-      } ''
+      bundled = name: runCommandNoCC "${name}-cllib"
+        {
+          passthru = {
+            lispName = name;
+            lispNativeDeps = [ ];
+            lispDeps = [ ];
+            lispBinary = false;
+            repl = impls.ecl.lispWith [ (impls.ecl.bundled name) ];
+          };
+        } ''
         mkdir -p "$out"
         ln -s "${ecl-static}/lib/ecl-${ecl-static.version}/${name}.${impls.ecl.faslExt}" -t "$out"
         ln -s "${ecl-static}/lib/ecl-${ecl-static.version}/lib${name}.a" "$out/${name}.a"
@@ -489,7 +506,8 @@ let
 
       # See https://ccl.clozure.com/docs/ccl.html#building-definitions
       faslExt =
-        /**/ if targetPlatform.isPowerPC && targetPlatform.is32bit then "pfsl"
+        /**/
+        if targetPlatform.isPowerPC && targetPlatform.is32bit then "pfsl"
         else if targetPlatform.isPowerPC && targetPlatform.is64bit then "p64fsl"
         else if targetPlatform.isx86_64 && targetPlatform.isLinux then "lx64fsl"
         else if targetPlatform.isx86_32 && targetPlatform.isLinux then "lx32fsl"
@@ -572,7 +590,7 @@ let
             lib.optionalString (deps != [])
               "--load ${writeText "load.lisp" (impls.ccl.genLoadLisp lispDeps)}"
           } "$@"
-      '';
+        '';
     };
   };
 
@@ -586,37 +604,42 @@ let
   library =
     { name
     , implementation ? defaultImplementation
-    , brokenOn ? [] # TODO(sterni): make this a warning
+    , brokenOn ? [ ] # TODO(sterni): make this a warning
     , srcs
-    , deps ? []
-    , native ? []
+    , deps ? [ ]
+    , native ? [ ]
     , tests ? null
-    , passthru ? {}
+    , passthru ? { }
     }:
     let
       filteredDeps = implFilter implementation deps;
       filteredSrcs = implFilter implementation srcs;
       lispNativeDeps = (allNative native filteredDeps);
       lispDeps = allDeps implementation filteredDeps;
-      testDrv = if ! isNull tests
-        then testSuite {
-          name = tests.name or "${name}-test";
-          srcs = filteredSrcs ++ (tests.srcs or []);
-          deps = filteredDeps ++ (tests.deps or []);
-          expression = tests.expression;
-          inherit implementation;
-        }
+      testDrv =
+        if ! isNull tests
+        then
+          testSuite
+            {
+              name = tests.name or "${name}-test";
+              srcs = filteredSrcs ++ (tests.srcs or [ ]);
+              deps = filteredDeps ++ (tests.deps or [ ]);
+              expression = tests.expression;
+              inherit implementation;
+            }
         else null;
-    in lib.fix (self: runCommandNoCC "${name}-cllib" {
-      LD_LIBRARY_PATH = lib.makeLibraryPath lispNativeDeps;
-      LANG = "C.UTF-8";
-      passthru = passthru // {
-        inherit lispNativeDeps lispDeps;
-        lispName = name;
-        lispBinary = false;
-        tests = testDrv;
-      };
-    } ''
+    in
+    lib.fix (self: runCommandNoCC "${name}-cllib"
+      {
+        LD_LIBRARY_PATH = lib.makeLibraryPath lispNativeDeps;
+        LANG = "C.UTF-8";
+        passthru = passthru // {
+          inherit lispNativeDeps lispDeps;
+          lispName = name;
+          lispBinary = false;
+          tests = testDrv;
+        };
+      } ''
       ${if ! isNull testDrv
         then "echo 'Test ${testDrv} succeeded'"
         else "echo 'No tests run'"}
@@ -637,13 +660,13 @@ let
   program =
     { name
     , implementation ? defaultImplementation
-    , brokenOn ? [] # TODO(sterni): make this a warning
+    , brokenOn ? [ ] # TODO(sterni): make this a warning
     , main ? "${name}:main"
     , srcs
-    , deps ? []
-    , native ? []
+    , deps ? [ ]
+    , native ? [ ]
     , tests ? null
-    , passthru ? {}
+    , passthru ? { }
     }:
     let
       filteredSrcs = implFilter implementation srcs;
@@ -656,45 +679,53 @@ let
         deps = lispDeps;
         srcs = filteredSrcs;
       };
-      testDrv = if ! isNull tests
-        then testSuite {
-          name = tests.name or "${name}-test";
-          srcs =
-            ( # testSuite does run implFilter as well
-              filteredSrcs ++ (tests.srcs or []));
-          deps = filteredDeps ++ (tests.deps or []);
-          expression = tests.expression;
-          inherit implementation;
-        }
+      testDrv =
+        if ! isNull tests
+        then
+          testSuite
+            {
+              name = tests.name or "${name}-test";
+              srcs =
+                (
+                  # testSuite does run implFilter as well
+                  filteredSrcs ++ (tests.srcs or [ ])
+                );
+              deps = filteredDeps ++ (tests.deps or [ ]);
+              expression = tests.expression;
+              inherit implementation;
+            }
         else null;
-    in lib.fix (self: runCommandNoCC "${name}" {
-      nativeBuildInputs = [ makeWrapper ];
-      LD_LIBRARY_PATH = libPath;
-      LANG = "C.UTF-8";
-      passthru = passthru // {
-        lispName = name;
-        lispDeps = [ selfLib ];
-        lispNativeDeps = native;
-        lispBinary = true;
-        tests = testDrv;
-      };
-    } (''
-      ${if ! isNull testDrv
-        then "echo 'Test ${testDrv} succeeded'"
-        else ""}
-      mkdir -p $out/bin
-
-      ${implementation.runScript} ${
-        implementation.genDumpLisp {
-          inherit name main;
-          deps = ([ selfLib ] ++ lispDeps);
-        }
+    in
+    lib.fix (self: runCommandNoCC "${name}"
+      {
+        nativeBuildInputs = [ makeWrapper ];
+        LD_LIBRARY_PATH = libPath;
+        LANG = "C.UTF-8";
+        passthru = passthru // {
+          lispName = name;
+          lispDeps = [ selfLib ];
+          lispNativeDeps = native;
+          lispBinary = true;
+          tests = testDrv;
+        };
       }
-    '' + lib.optionalString implementation.wrapProgram ''
-      wrapProgram $out/bin/${name} \
-        --prefix LD_LIBRARY_PATH : "${libPath}" \
-        --add-flags "\$NIX_BUILDLISP_LISP_ARGS --"
-    ''));
+      (''
+        ${if ! isNull testDrv
+          then "echo 'Test ${testDrv} succeeded'"
+          else ""}
+        mkdir -p $out/bin
+
+        ${implementation.runScript} ${
+          implementation.genDumpLisp {
+            inherit name main;
+            deps = ([ selfLib ] ++ lispDeps);
+          }
+        }
+      '' + lib.optionalString implementation.wrapProgram ''
+        wrapProgram $out/bin/${name} \
+          --prefix LD_LIBRARY_PATH : "${libPath}" \
+          --add-flags "\$NIX_BUILDLISP_LISP_ARGS --"
+      ''));
 
   # '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
@@ -714,11 +745,13 @@ let
         }:
         implementation.bundled or (defaultBundled implementation) name;
 
-    in (makeOverridable bundled') {
+    in
+    (makeOverridable bundled') {
       inherit name;
     };
 
-in {
+in
+{
   library = withExtras library;
   program = withExtras program;
   inherit bundled;
diff --git a/nix/buildLisp/example/default.nix b/nix/buildLisp/example/default.nix
index 6a518e4964..6add2676f1 100644
--- a/nix/buildLisp/example/default.nix
+++ b/nix/buildLisp/example/default.nix
@@ -14,15 +14,16 @@ let
     ];
   };
 
-# Example Lisp program.
-#
-# This builds & writes an executable for a program using the library
-# above to disk.
-#
-# By default, buildLisp.program expects the entry point to be
-# `$name:main`. This can be overridden by configuring the `main`
-# attribute.
-in buildLisp.program {
+  # Example Lisp program.
+  #
+  # This builds & writes an executable for a program using the library
+  # above to disk.
+  #
+  # By default, buildLisp.program expects the entry point to be
+  # `$name:main`. This can be overridden by configuring the `main`
+  # attribute.
+in
+buildLisp.program {
   name = "example";
   deps = [ libExample ];