Skip to content

Commit

Permalink
update nix files to use gradle2nix v2
Browse files Browse the repository at this point in the history
  • Loading branch information
rgoulter committed May 30, 2024
1 parent 5fb7d55 commit 2b920b2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 103 deletions.
118 changes: 21 additions & 97 deletions c-worksheet-instrumentor.nix
Original file line number Diff line number Diff line change
@@ -1,110 +1,34 @@
{ lib
, stdenv
, makeWrapper
, substituteAll
, gradle_8
, jdk
, clang
, gcc
, coreutils
, findutils
, gnused
, perl
{
lib,
buildGradlePackage,
jdk,
coreutils,
findutils,
gnused,
gcc,
}:

stdenv.mkDerivation (finalAttrs: {
buildGradlePackage rec {
pname = "c-worksheet-instrumentor";
version = lib.strings.removeSuffix "\n" (builtins.readFile ./version);

src = builtins.path { path = ./.; name = finalAttrs.pname; };

patches = [
# use `deps` maven repo so that gradle can build offline.
(substituteAll {
src = ./use-fod-maven-repo.patch;
inherit (finalAttrs) deps;
})
];

# helper build to pre-download deps into fixed-output derivation
deps = stdenv.mkDerivation {
name = "${finalAttrs.pname}-${finalAttrs.version}-deps";
inherit (finalAttrs) src;

nativeBuildInputs = [
clang
gradle_8
perl
];

buildPhase = ''
runHook preBuild
export GRADLE_USER_HOME=$(mktemp -d)
gradle --no-daemon --console=plain build
runHook postBuild
'';

# perl code mavenizes pathes (com.example.foo/foo/1.0.0/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/foo-1.0.0.jar -> com/example/foo/foo/1.0.0/foo-1.0.0.jar)
installPhase = ''
runHook preInstall
find $GRADLE_USER_HOME/caches/modules-2 -type f -regex '.*\.\(jar\|pom\|module\)' \
| perl -pe 's#(.*/([^/]+)/([^/]+)/([^/]+)/[0-9a-f]{30,40}/([^/\s]+))$# ($x = $2) =~ tr|\.|/|; "install -Dm444 $1 \$out/$x/$3/$4/$5" #e' \
| sh
runHook postInstall
'';

# Remember to update FOD outputHash whenever build.gradle dependencies change
outputHashAlgo = "sha256";
outputHashMode = "recursive";
outputHash = "sha256-xw7DoUKkGYsGxVHxgl3qhWjQRanHvGDyP2jVt3ynjGw=";
lockFile = ./gradle.lock;
src = builtins.path {
path = ./.;
name = pname;
};

nativeBuildInputs = [
makeWrapper
clang
gradle_8
];

buildPhase = ''
runHook preBuild
export GRADLE_USER_HOME=$(mktemp -d)
gradle --offline --no-daemon --console=plain build
runHook postBuild
'';

doCheck = true;
checkPhase = ''
runHook preCheck
gradle --offline --no-daemon --console=plain testIntegration
runHook postCheck
'';

installPhase = let
gradleDistScriptDeps = [ coreutils findutils gnused ];
gradleFlags = ["build" "testIntegration" "installDist"];
installPhase = let
gradleDistScriptDeps = [coreutils findutils gnused];
in ''
runHook preInstall
gradle --offline --no-daemon installDist
mkdir -p $out
cp -r build/install/${pname}/* $out
mkdir -p $out/
cp -r build/install/${finalAttrs.pname}/* $out/
rm $out/bin/*.bat
wrapProgram $out/bin/c-worksheet-instrumentor \
--set JAVA_HOME ${jdk.home} \
--suffix PATH : ${lib.makeBinPath (gradleDistScriptDeps ++ [ gcc ])}
--suffix PATH : ${lib.makeBinPath (gradleDistScriptDeps ++ [gcc])}
wrapProgram $out/bin/c-worksheetify-server \
--set JAVA_HOME ${jdk.home} \
--suffix PATH : ${lib.makeBinPath (gradleDistScriptDeps ++ [ gcc ])}
runHook postInstall
--suffix PATH : ${lib.makeBinPath (gradleDistScriptDeps ++ [gcc])}
'';
})
}
8 changes: 5 additions & 3 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{ pkgs ? import <nixpkgs> {} }:

pkgs.callPackage ./c-worksheet-instrumentor.nix { }
{pkgs ? import <nixpkgs> {}}: let
# my fork
gradle2nix = import (fetchTarball "https://github.com/rgoulter/gradle2nix/archive/v2--always-set-gradle-user-home.tar.gz") {};
in
pkgs.callPackage ./c-worksheet-instrumentor.nix {inherit (gradle2nix) buildGradlePackage;}
5 changes: 2 additions & 3 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{ pkgs ? import <nixpkgs> {} }:

{pkgs ? import <nixpkgs> {}}:
pkgs.mkShell {
inputsFrom = [(pkgs.callPackage ./c-worksheet-instrumentor.nix {})];
inputsFrom = [(pkgs.callPackage ./default.nix {})];
packages = [
pkgs.metals
pkgs.scalafix
Expand Down

0 comments on commit 2b920b2

Please sign in to comment.