From 5250191dc17278626b681cde04685bfe8a14de90 Mon Sep 17 00:00:00 2001 From: niten Date: Tue, 31 May 2022 13:07:35 -0700 Subject: [PATCH] Move build.clj to src/ --- build.tools.nix | 8 +++++--- flake.nix | 8 ++++---- mkClojureLib.nix | 40 ++++++++++++++++---------------------- build.clj => src/build.clj | 0 4 files changed, 26 insertions(+), 30 deletions(-) rename build.clj => src/build.clj (100%) diff --git a/build.tools.nix b/build.tools.nix index b74efeb..a49ac36 100644 --- a/build.tools.nix +++ b/build.tools.nix @@ -16,8 +16,10 @@ let ''; + pthru = o: builtins.trace o o; + java-compile = ns: - ''java -cp .:${classpath} clojure.main -e "(compile ${ns})"''; + ''java -cp .:${./src}:${classpath} clojure.main -e "(compile ${ns})"''; head-or-null = lst: if (lst == [ ]) then null else head lst; matches-ext = ext: filename: type: (builtins.match ".+[.]${ext}$" filename) != null; @@ -29,8 +31,7 @@ let (ext-files "clj" "${build-tools-src}/src/main/clojure/clojure/tools/build/tasks")); task-namespaces = map (ns: "'clojure.tools.build.tasks.${ns}") tasks; - all-namespaces = [ "'clojure.tools.build.api" ] ++ task-namespaces; - compile-code = concatStringsSep " " (map (ns: "(compile ns)") all-namespaces); + all-namespaces = task-namespaces ++ [ "'clojure.tools.build.api" ]; in stdenv.mkDerivation { name = full-name; @@ -42,6 +43,7 @@ in stdenv.mkDerivation { HOME=. ${concatStringsSep "\n" (map extract-jar dep-jars)} ${concatStringsSep "\n" (map java-compile all-namespaces)} + ${java-compile "'build"} jar cmf ${manifest} ./out.jar -C . cljs cognitect com javax mozilla plugin.xml about.html clojure cognitect_aws_http.edn data_readers.cljc licenses org ''; diff --git a/flake.nix b/flake.nix index 73554a1..1bb9dd4 100644 --- a/flake.nix +++ b/flake.nix @@ -26,11 +26,11 @@ inherit (gitignore.lib) gitignoreSource; }; in { + packages."${system}" = { inherit build-tools-jar; }; + defaultPackage."${system}" = self.packages."${system}".build-tools-jar; lib = { - mkClojureLib = pkgs.callPackage ./mkClojureLib.nix { - inherit build-tools-jar; - inherit (to-edn.lib) toEDN; - }; + mkClojureLib = + pkgs.callPackage ./mkClojureLib.nix { inherit (to-edn.lib) toEDN; }; }; devShell."${system}" = pkgs.mkShell { buildInputs = with pkgs; [ clojure clj2nix ]; }; diff --git a/mkClojureLib.nix b/mkClojureLib.nix index f3135b3..7ac7f08 100644 --- a/mkClojureLib.nix +++ b/mkClojureLib.nix @@ -1,25 +1,20 @@ -{ lib, stdenv, callPackage, clojure, jre, build-tools-jar, writeTextDir -, writeShellScript, toEDN }: -{ src, name, group, version, clj-deps, src-paths }: +{ lib, stdenv, callPackage, clojure, jre, writeTextDir, writeShellScript, toEDN +}: +{ src, name, group, version, clj-deps, src-paths, build-tools-jar, ... }: with lib; let - - pthru = o: builtins.trace o o; - - build-tools-edn = pthru (toEDN { + build-tools-deps = writeTextDir "deps.edn" (toEDN { aliases.build = { - ns-build = "'build"; - replace-deps."'io.github.clojure/tools.build"."local/root" = + ns-default = "'build"; + extra-deps."'io.github.clojure/tools.build"."local/root" = "${build-tools-jar}"; }; }); - build-tools-deps = writeTextDir "deps.edn" (pthru build-tools-edn); - classpath = clj-deps.makeClasspaths { }; - full-name = "${group}-${name}-${version}-standalone.jar"; + full-name = "${name}-${version}-standalone.jar"; target = "$TEMP/target"; @@ -28,27 +23,26 @@ let mkdir -p $HOME mkdir -p ${target} - clojure \ - -Scp .:${build-tools-jar}:${classpath} \ - -Sdeps ${builtins.trace build-tools-deps build-tools-deps} \ - -X:build \ + clojure \ + -Scp .:${build-tools-jar}:${classpath} \ + -Sdeps ${build-tools-deps} \ + -X:build \ lib-uberjar \ - :project ${group}/${name} \ - :version ${version} \ - :srcs ${concatStringsSep "," src-paths} \ - :target ${target} + :project ${group}/${name} \ + :version ${version} \ + :src-dirs ${concatStringsSep "," src-paths} \ + :target ${target} ''; in stdenv.mkDerivation { - name = name; + name = full-name; src = src; nativeBuildInputs = [ clojure jre ]; buildInputs = (map (x: x.paths) clj-deps.packages); - buildPhase = let script-call = "${build-script}"; - in builtins.trace script-call script-call; + buildPhase = builtins.trace "${build-script}" "${build-script}"; installPhase = '' mv ${target}/${name}-${version}-standalone.jar $out diff --git a/build.clj b/src/build.clj similarity index 100% rename from build.clj rename to src/build.clj