From 2a170f1ed744b2e80973fe58c8a68885fd1510bb Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Thu, 9 Jan 2020 00:46:20 +0000 Subject: fix(buildLisp): Perform a topological sort of dependencies This ensures that dependencies are loaded in the correct order in larger dependency graphs. --- nix/buildLisp/default.nix | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'nix/buildLisp') diff --git a/nix/buildLisp/default.nix b/nix/buildLisp/default.nix index e8d235df7c32..15dddfbbab93 100644 --- a/nix/buildLisp/default.nix +++ b/nix/buildLisp/default.nix @@ -61,15 +61,14 @@ let )) ''; + # 'dependsOn' determines whether Lisp library 'b' depends on 'a'. + dependsOn = a: b: builtins.elem a b.lispDeps; + # 'allDeps' flattens the list of dependencies (and their - # dependencies) into one list of unique deps. - # - # TODO(tazjin): Ordering needs to be stable (first occurences from - # innermost to outer), I don't know if this works accidentally or is - # guaranteed by these lib functions. - allDeps = deps: lib.reverseList ( - lib.unique (lib.flatten (deps ++ (map (d: d.lispDeps) deps))) - ); + # dependencies) into one ordered list of unique deps. + allDeps = deps: (lib.toposort dependsOn (lib.unique ( + lib.flatten (deps ++ (map (d: d.lispDeps) deps)) + ))).result; # 'genDumpLisp' generates a Lisp file that instructs SBCL to dump # the currently loaded image as an executable to $out/bin/$name. -- cgit 1.4.1