Initial checkin

This commit is contained in:
niten 2022-05-28 11:51:36 -07:00
commit a15b3b8494
6 changed files with 1324 additions and 0 deletions

70
build.clj Normal file
View File

@ -0,0 +1,70 @@
(ns build
(:require [clojure.tools.build.api :as b]))
(defn make-class-dir [target] (format "%s/classes" target))
(def basis (b/create-basis {:project "deps.edn"}))
(defonce timestamp
(.format (java.time.LocalDateTime/now)
java.time.format.DateTimeFormatter/BASIC_ISO_DATE))
(defonce default-target "./target")
(defonce default-srcs ["src"])
(defn make-jar-filename [target project version]
(format "%s/%s-%s.jar"
target (name project) version))
(defn make-uber-filename [target project version]
(format "%s/%s-%s-standalone.jar"
target (name project) version))
(defn clean [{:keys [target] :or {target default-target} :as params}]
(println (format "removing build target folder \"%s\"" target))
(b/delete {:path target})
params)
(defn lib-jar
[{:keys [project version target srcs]
:or {version timestamp
target default-target
srcs default-srcs}
:as params}]
(let [project-sym (symbol project)
target-jar (make-jar-filename target project version)
class-dir (make-class-dir target)]
(clean params)
(b/copy-dir {:src-dirs srcs})
(b/compile-clj {:basis basis
:src-dirs srcs
:class-dir class-dir})
(b/write-pom {:class-dir class-dir
:lib project-sym
:version version
:basis basis
:src-dirs srcs})
(b/jar {:class-dir class-dir
:jar-file target-jar})
(println (format "jar file created at: %s" target-jar)))
params)
(defn lib-uberjar
[{:keys [project version target srcs]
:or {version timestamp
target default-target
srcs default-srcs}
:as params}]
(let [project-sym (symbol project)
target-uber (jar-filename target project version)
class-dir (make-class-dir target)]
(clean params)
(b/copy-dir {:src-dirs srcs
:target-dir class-dir})
(b/compile-clj {:basis basis
:src-dirs srcs
:class-dir class-dir})
(b/uber {:class-dir class-dir
:uber-file target-uber
:basis basis})
(println (format "uberjar file created at: %s" target-uber)))
params)

51
build.tools.nix Normal file
View File

@ -0,0 +1,51 @@
{ lib, stdenv, build-tools-src, clojure, callPackage, writeText, gitignoreSource
, jre, ... }:
with lib;
let
base-name = "clojure-build-tools";
version = "0.8.2";
full-name = "${base-name}-${version}.jar";
cljdeps = callPackage ./deps.nix { };
classpath = cljdeps.makeClasspaths { };
dep-jars = splitString ":" classpath;
extract-jar = jar: "jar -xf ${jar}";
manifest = writeText "MANIFEST.MF" ''
Manifest-Version: 1.0
'';
java-compile = ns:
''java -cp .:${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;
strip-ext = ext: filename:
head-or-null (builtins.match "(.+)[.]${ext}$" filename);
ext-files = ext: path:
attrNames (filterAttrs (matches-ext "clj") (builtins.readDir path));
tasks = map (replaceStrings [ "_" ] [ "-" ]) (map (strip-ext "clj")
(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);
in stdenv.mkDerivation {
name = full-name;
src = gitignoreSource "${build-tools-src}/src/main/clojure";
nativeBuildInputs = [ jre ];
buildInputs = map (x: x.paths) cljdeps.packages;
buildPhase = ''
mkdir classes
HOME=.
${concatStringsSep "\n" (map extract-jar dep-jars)}
${concatStringsSep "\n" (map java-compile all-namespaces)}
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
'';
installPhase = ''
cp out.jar $out
'';
}

1008
deps.nix Normal file

File diff suppressed because it is too large Load Diff

147
flake.lock Normal file
View File

@ -0,0 +1,147 @@
{
"nodes": {
"build-tools-src": {
"flake": false,
"locked": {
"lastModified": 1651863598,
"narHash": "sha256-JK26Km60rGnguJDWpSOD9pji9u2KMh+11qOKc1D+16M=",
"owner": "clojure",
"repo": "tools.build",
"rev": "a9d0804ce8014088a7388e762034e9013922cacb",
"type": "github"
},
"original": {
"owner": "clojure",
"repo": "tools.build",
"type": "github"
}
},
"clj2nix": {
"inputs": {
"flake-compat": "flake-compat",
"nixpkgs": "nixpkgs",
"utils": "utils"
},
"locked": {
"lastModified": 1637900288,
"narHash": "sha256-hQdSCIm1WpG5uK9hoe/iagyYc3Fhi8PJzfo1jFBa53g=",
"owner": "hlolli",
"repo": "clj2nix",
"rev": "3d0a38c954c8e0926f57de1d80d357df05fc2f94",
"type": "github"
},
"original": {
"owner": "hlolli",
"repo": "clj2nix",
"type": "github"
}
},
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1627913399,
"narHash": "sha256-hY8g6H2KFL8ownSiFeMOjwPC8P0ueXpCVEbxgda3pko=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "12c64ca55c1014cdc1b16ed5a804aa8576601ff2",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"gitignore": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1646480205,
"narHash": "sha256-kekOlTlu45vuK2L9nq8iVN17V3sB0WWPqTTW3a2SQG0=",
"owner": "hercules-ci",
"repo": "gitignore.nix",
"rev": "bff2832ec341cf30acb3a4d3e2e7f1f7b590116a",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "gitignore.nix",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1637881340,
"narHash": "sha256-/meU5CTm8GnaETZrJa0UqBQvk9T/jKp1+MLIQQ7FTTo=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "d460f48ddb884f7270b7f7bfcbf8a7b91140caa5",
"type": "github"
},
"original": {
"owner": "NixOS",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1645296114,
"narHash": "sha256-y53N7TyIkXsjMpOG7RhvqJFGDacLs9HlyHeSTBioqYU=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "530a53dcbc9437363471167a5e4762c5fcfa34a1",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "nixos-21.05",
"type": "indirect"
}
},
"root": {
"inputs": {
"build-tools-src": "build-tools-src",
"clj2nix": "clj2nix",
"gitignore": "gitignore",
"nixpkgs": "nixpkgs_2",
"utils": "utils_2"
}
},
"utils": {
"locked": {
"lastModified": 1637014545,
"narHash": "sha256-26IZAc5yzlD9FlDT54io1oqG/bBoyka+FJk5guaX4x4=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "bba5dcc8e0b20ab664967ad83d24d64cb64ec4f4",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"utils_2": {
"locked": {
"lastModified": 1652776076,
"narHash": "sha256-gzTw/v1vj4dOVbpBSJX4J0DwUR6LIyXo7/SuuTJp1kM=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "04c1b180862888302ddfb2e3ad9eaa63afc60cf8",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

43
flake.nix Normal file
View File

@ -0,0 +1,43 @@
{
description = "clojure/tools.build packaged for NixOS.";
inputs = {
nixpkgs.url = "nixpkgs/nixos-21.05";
utils.url = "github:numtide/flake-utils";
clj2nix.url = "github:hlolli/clj2nix";
build-tools-src = {
url = "github:clojure/tools.build?tag=v0.8.2";
flake = false;
};
gitignore = {
url = "github:hercules-ci/gitignore.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, utils, clj2nix, build-tools-src, gitignore, ... }:
utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages."${system}";
clojure-build-tools = pkgs.callPackage ./build.tools.nix {
inherit build-tools-src;
inherit (gitignore.lib) gitignoreSource;
};
update-deps = pkgs.callPackage ./update-deps.nix {
inherit build-tools-src;
inherit clj2nix;
};
in {
packages = utils.lib.flattenTree { inherit clojure-build-tools; };
defaultPackage = self.packages."${system}".clojure-build-tools;
overlay = final: prev: { inherit clojure-build-tools; };
devShell = pkgs.mkShell {
buildInputs = with pkgs; [
clojure
jre
clj2nix.packages."${system}".clj2nix
update-deps
];
};
});
}

5
update-deps.nix Normal file
View File

@ -0,0 +1,5 @@
{ writeShellScriptBin, build-tools-src, clj2nix, ... }:
writeShellScriptBin "update-build-tools-deps.sh" ''
${clj2nix}/bin/clj2nix ${build-tools-src}/deps.edn deps.nix
''