diff options
author | sterni <sternenseemann@systemli.org> | 2021-08-16T20·54+0200 |
---|---|---|
committer | sterni <sternenseemann@systemli.org> | 2021-08-24T22·00+0000 |
commit | 7df7cd6257ea8c3213fab6f534c0d128a7df3ed7 (patch) | |
tree | f44039cabe98b81626215da24fac9039fc1e8677 /nix | |
parent | d7e70b1d7270548272267e9b01dc9867f94f5f74 (diff) |
feat(nix/buildLisp): pass implementation description instead of name r/2773
Instead of using a string to refer to an internal set defined in buildLisp, we just expose the relevant sets (as nix.buildLisp.sbcl, nix.buildLisp.ecl, …) and receive them as the `implementation` argument directly. This has several advantages: * It becomes easier to extend buildLisp, even for downstream users: Since you can just pass your own set, there's nothing stopping you from adding support for another implementation in a downstream derivation without having to edit the buildLisp file in any way which is great if you're using e. g. builtins.fetchGit to import it. * Users can mess with the implementation set by changing out some parts of it for customization purposes. Note that currently the sets use a lot of self-references which aren't even bound by a fix-point, so to make this work smoothly, we'd need to add some overriding mechanism. * The buildLisp code becomes quite a bit clearer. Since we're now always dealing with the implementation set, the confusing distinction between `impl`, `impl.name` and `implementation` no longer exists. `impl` is now exclusively an abbreviation of `implementation` (we could make this more consistent in the future even). Change-Id: I36d68069dd1315610b2f7159941507b465469b7c Reviewed-on: https://cl.tvl.fyi/c/depot/+/3368 Reviewed-by: tazjin <mail@tazj.in> Reviewed-by: grfn <grfn@gws.fyi> Tested-by: BuildkiteCI
Diffstat (limited to 'nix')
-rw-r--r-- | nix/buildLisp/default.nix | 62 |
1 files changed, 32 insertions, 30 deletions
diff --git a/nix/buildLisp/default.nix b/nix/buildLisp/default.nix index 4e83cc2a6b63..8f95c769166b 100644 --- a/nix/buildLisp/default.nix +++ b/nix/buildLisp/default.nix @@ -15,7 +15,7 @@ let # Internal helper definitions # - defaultImplementation = "sbcl"; + defaultImplementation = impls.sbcl; # Many Common Lisp implementations (like ECL and CCL) will occasionally drop # you into an interactive debugger even when executing something as a script. @@ -109,7 +109,7 @@ let # 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.name; + implementation = impl; }))) deps; in (lib.toposort dependsOn (lib.unique ( lib.flatten (deps' ++ (map (d: d.lispDeps) deps')) @@ -147,37 +147,37 @@ let (builtins.attrNames impls); in { passthru = (old.passthru or {}) // { - repl = impls."${implementation}".lispWith [ self ]; + 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 (name: { - inherit name; + } // builtins.listToAttrs (builtins.map (impl: { + inherit (impl) name; value = self.overrideLisp (_: { - implementation = name; + implementation = impl; }); - }) (builtins.attrNames impls)); + }) (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 ? [], impl }: + testSuite = { name, expression, srcs, deps ? [], native ? [], implementation }: let lispNativeDeps = allNative native deps; - lispDeps = allDeps impl (implFilter impl deps); - filteredSrcs = implFilter impl srcs; + lispDeps = allDeps implementation (implFilter implementation deps); + filteredSrcs = implFilter implementation srcs; in runCommandNoCC name { LD_LIBRARY_PATH = lib.makeLibraryPath lispNativeDeps; LANG = "C.UTF-8"; } '' echo "Running test suite ${name}" - ${impl.runScript} ${ - impl.genTestLisp { + ${implementation.runScript} ${ + implementation.genTestLisp { inherit name expression; srcs = filteredSrcs; deps = lispDeps; @@ -579,19 +579,17 @@ let , passthru ? {} }: let - impl = impls."${implementation}" or - (builtins.throw "Unkown Common Lisp Implementation ${implementation}"); - filteredDeps = implFilter impl deps; - filteredSrcs = implFilter impl srcs; + filteredDeps = implFilter implementation deps; + filteredSrcs = implFilter implementation srcs; lispNativeDeps = (allNative native filteredDeps); - lispDeps = allDeps impl 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 impl; + inherit implementation; } else null; in lib.fix (self: runCommandNoCC "${name}-cllib" { @@ -610,8 +608,8 @@ let mkdir $out - ${impl.runScript} ${ - impl.genCompileLisp { + ${implementation.runScript} ${ + implementation.genCompileLisp { srcs = filteredSrcs; inherit name; deps = lispDeps; @@ -633,11 +631,9 @@ let , passthru ? {} }: let - impl = impls."${implementation}" or - (builtins.throw "Unkown Common Lisp Implementation ${implementation}"); - filteredSrcs = implFilter impl srcs; - filteredDeps = implFilter impl deps; - lispDeps = allDeps impl filteredDeps; + filteredSrcs = implFilter implementation srcs; + filteredDeps = implFilter implementation deps; + lispDeps = allDeps implementation filteredDeps; libPath = lib.makeLibraryPath (allNative native lispDeps); # overriding is used internally to propagate the implementation to use selfLib = (makeOverridable library) { @@ -653,7 +649,7 @@ let filteredSrcs ++ (tests.srcs or [])); deps = filteredDeps ++ (tests.deps or []); expression = tests.expression; - inherit impl; + inherit implementation; } else null; in lib.fix (self: runCommandNoCC "${name}" { @@ -673,13 +669,13 @@ let else ""} mkdir -p $out/bin - ${impl.runScript} ${ - impl.genDumpLisp { + ${implementation.runScript} ${ + implementation.genDumpLisp { inherit name main; deps = ([ selfLib ] ++ lispDeps); } } - '' + lib.optionalString impl.wrapProgram '' + '' + lib.optionalString implementation.wrapProgram '' wrapProgram $out/bin/${name} --prefix LD_LIBRARY_PATH : "${libPath}" '')); @@ -699,7 +695,7 @@ let { implementation ? defaultImplementation , name }: - impls."${implementation}".bundled or (defaultBundled implementation) name; + implementation.bundled or (defaultBundled implementation) name; in (makeOverridable bundled') { inherit name; @@ -713,4 +709,10 @@ in { # 'sbclWith' creates an image with the specified libraries / # programs loaded in SBCL. sbclWith = impls.sbcl.lispWith; + + inherit (impls) + sbcl + ecl + ccl + ; } |