From e3624e86aeda7eaf4f16560f50602639ea60fffe Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Wed, 4 Dec 2024 23:26:20 -0500 Subject: nix build, dub, take account of nixpkgs build changes --- flake.lock | 6 +-- flake.nix | 17 ++++---- nix-overlays/dub/default.nix | 87 +--------------------------------------- nix-overlays/dub/package.nix | 91 ++++++++++++++++++++++++++++++++++++++++++ org/dlang-nix-flakes.org | 95 ++++++++++++++++++++++++++------------------ 5 files changed, 160 insertions(+), 136 deletions(-) create mode 100644 nix-overlays/dub/package.nix diff --git a/flake.lock b/flake.lock index ad0a993..f827f43 100644 --- a/flake.lock +++ b/flake.lock @@ -20,11 +20,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1733097829, - "narHash": "sha256-9hbb1rqGelllb4kVUCZ307G2k3/UhmA8PPGBoyuWaSw=", + "lastModified": 1733229606, + "narHash": "sha256-FLYY5M0rpa5C2QAE3CKLYAM6TwbKicdRK6qNrSHlNrE=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "2c15aa59df0017ca140d9ba302412298ab4bf22a", + "rev": "566e53c2ad750c84f6d31f9ccb9d00f823165550", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 5ad88af..2d9f360 100644 --- a/flake.nix +++ b/flake.nix @@ -60,17 +60,16 @@ inherit shell; inherit devEnv; buildInputs = [sqlite]; - nativeBuildInputs = [dub ldc gnumake]; # [ dub dmd ]; [ dub ldc ]; [ dub gdc ]; + nativeBuildInputs = [gnumake dub ldc]; + preBuild = '' + export DCn=ldmd2 + export DC=$(type -P $DCn || echo "") + if [ "$DC" == "" ]; then exit "Error: could not find D compiler"; fi + ''; buildPhase = '' runHook preBuild - for DC_ in dmd ldmd2 ldc2 gdc gdmd; do - echo "- check for D compiler $DC_" - DC=$(type -P $DC_ || echo "") - if [ ! "$DC" == "" ]; then break; fi - done - if [ "$DC" == "" ]; then exit "Error: could not find D compiler"; fi - echo "$DC_ used as D compiler to build $pname" - dub build --cache=local --compiler=$DC --build=$DC_ --combined --skip-registry=all + echo "$DCn used as D compiler to build $pname" + dub build --cache=local --compiler=$DC --build=$DCn --combined --skip-registry=all runHook postBuild ''; inherit checkPhase; diff --git a/nix-overlays/dub/default.nix b/nix-overlays/dub/default.nix index 0eec437..8375c13 100644 --- a/nix-overlays/dub/default.nix +++ b/nix-overlays/dub/default.nix @@ -1,86 +1 @@ -{ lib, stdenv, fetchFromGitHub, curl, libevent, rsync, ldc, dcompiler ? ldc }: - -assert dcompiler != null; - -stdenv.mkDerivation rec { - pname = "dub"; - version = "1.38.1"; - - enableParallelBuilding = true; - - src = fetchFromGitHub { - owner = "dlang"; - repo = "dub"; - rev = "v${version}"; - sha256 = "sha256-8Lr/0sx4SKwU1aNOxZArta0RXpDM+EWl29ZsPDdPWFo="; - }; - - #postUnpack = '' - # patchShebangs . - #''; - - dubvar = "\\$DUB"; - postPatch = '' - patchShebangs test - - # Can be removed with https://github.com/dlang/dub/pull/1368 - substituteInPlace test/fetchzip.sh \ - --replace "dub remove" "\"${dubvar}\" remove" - ''; - - nativeBuildInputs = [ dcompiler libevent rsync ]; - buildInputs = [ curl ]; - - buildPhase = '' - for DC_ in dmd ldmd2 gdmd; do - echo "... check for D compiler $DC_ ..." - export DC=$(type -P $DC_ || echo "") - if [ ! "$DC" == "" ]; then - break - fi - done - if [ "$DC" == "" ]; then - exit "Error: could not find D compiler" - fi - echo "$DC_ found and used as D compiler in buildPhase for $pname" - $DC ./build.d - ./build - ''; - - doCheck = !stdenv.isDarwin; - - checkPhase = '' - export DUB=$NIX_BUILD_TOP/source/bin/dub - export PATH=$PATH:$NIX_BUILD_TOP/source/bin/ - #export DC=${dcompiler.out}/bin/${if dcompiler.pname=="ldc" then "ldc2" else dcompiler.pname} - if [ "$DC" == "" ]; then - exit "Error: could not find D compiler" - fi - echo "DC out --> $DC" - export HOME=$TMP - - rm -rf test/issue502-root-import - rm -rf test/dpath-variable - #rm test/dpath-variable.sh - rm -rf test/git-dependency - rm -rf test/use-c-sources # added to build v1.33.0 - rm -rf test/pr2642-cache-db # added to build v1.34.0 - rm -rf test/pr2644-describe-artifact-path # added to build v1.36.0 - rm -rf test/pr2647-build-deep # added to build v1.36.0 - - ./test/run-unittest.sh - ''; - - installPhase = '' - mkdir -p $out/bin - cp bin/dub $out/bin - ''; - - meta = with lib; { - description = "Package and build manager for D applications and libraries"; - homepage = "https://code.dlang.org/"; - license = licenses.mit; - maintainers = with maintainers; [ jtbx ]; - platforms = [ "x86_64-linux" "i686-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; - }; -} +import ./package.nix diff --git a/nix-overlays/dub/package.nix b/nix-overlays/dub/package.nix new file mode 100644 index 0000000..f13adec --- /dev/null +++ b/nix-overlays/dub/package.nix @@ -0,0 +1,91 @@ +{ lib +, stdenv +, fetchFromGitHub +, curl +, ldc +, dcompiler ? ldc +, libevent +, rsync +}: + +assert dcompiler != null; + +stdenv.mkDerivation (finalAttrs: { + pname = "dub"; + version = "1.38.1"; + + enableParallelBuilding = true; + + src = fetchFromGitHub { + owner = "dlang"; + repo = "dub"; + rev = "v${finalAttrs.version}"; + hash = "sha256-8Lr/0sx4SKwU1aNOxZArta0RXpDM+EWl29ZsPDdPWFo="; + }; + + postPatch = '' + patchShebangs test + ''; + + nativeBuildInputs = [ dcompiler libevent rsync ]; + buildInputs = [ curl ]; + + preBuild = '' + for DCn in dmd ldmd2 gdmd; do + echo "... check for D compiler $DCn ..." + export DC=$(type -P $DCn || echo "") + if [ ! "$DC" == "" ]; then + break + fi + done + if [ "$DC" == "" ]; then + exit "Error: could not find D compiler" + fi + echo "$DCn found and used as D compiler in buildPhase for $pname" + ''; + + buildPhase = '' + runHook preBuild + $DC -run ./build.d + runHook postBuild + ''; + + doCheck = !stdenv.hostPlatform.isDarwin; + + checkPhase = '' + runHook preCheck + export DUB=$NIX_BUILD_TOP/source/bin/dub + export PATH=$PATH:$NIX_BUILD_TOP/source/bin/ + if [ "$DC" == "" ]; then + exit "Error: could not find D compiler" + fi + echo "DC out --> $DC" + export HOME=$TMP + + rm -rf test/issue502-root-import + rm -r test/dpath-variable # requires execution of dpath-variable.sh + rm -rf test/git-dependency + rm -rf test/use-c-sources # added to build v1.33.0 + rm -rf test/pr2642-cache-db # added to build v1.34.0 + rm -rf test/pr2644-describe-artifact-path # added to build v1.36.0 + rm -rf test/pr2647-build-deep # added to build v1.36.0 + + ./test/run-unittest.sh + runHook postCheck + ''; + + installPhase = '' + runHook preInstall + install -Dm755 bin/dub $out/bin/dub + runHook postInstall + ''; + + meta = with lib; { + description = "Package and build manager for D programs and libraries"; + homepage = "https://code.dlang.org/"; + license = licenses.mit; + mainProgram = "dub"; + maintainers = with maintainers; [ jtbx ]; + platforms = [ "x86_64-linux" "i686-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; + }; +}) diff --git a/org/dlang-nix-flakes.org b/org/dlang-nix-flakes.org index 9e12692..7211649 100644 --- a/org/dlang-nix-flakes.org +++ b/org/dlang-nix-flakes.org @@ -464,17 +464,16 @@ direnv fetchurl https://raw.githubusercontent.com/nix-community/nix-direnv/${Nix inherit shell; inherit devEnv; buildInputs = [sqlite]; - nativeBuildInputs = [dub ldc gnumake]; # [ dub dmd ]; [ dub ldc ]; [ dub gdc ]; + nativeBuildInputs = [gnumake dub ldc]; + preBuild = '' + export DCn=ldmd2 + export DC=$(type -P $DCn || echo "") + if [ "$DC" == "" ]; then exit "Error: could not find D compiler"; fi + ''; buildPhase = '' runHook preBuild - for DC_ in dmd ldmd2 ldc2 gdc gdmd; do - echo "- check for D compiler $DC_" - DC=$(type -P $DC_ || echo "") - if [ ! "$DC" == "" ]; then break; fi - done - if [ "$DC" == "" ]; then exit "Error: could not find D compiler"; fi - echo "$DC_ used as D compiler to build $pname" - dub build --cache=local --compiler=$DC --build=$DC_ --combined --skip-registry=all + echo "$DCn used as D compiler to build $pname" + dub build --cache=local --compiler=$DC --build=$DCn --combined --skip-registry=all runHook postBuild ''; inherit checkPhase; @@ -580,7 +579,6 @@ direnv fetchurl https://raw.githubusercontent.com/nix-community/nix-direnv/${Nix #+HEADER: :tangle "../shell.nix" #+HEADER: :tangle-mode (identity #o755) #+HEADER: :shebang "#!/usr/bin/env -S nix-shell --pure\n#!nix-shell -i bash" -#+HEADER: :noweb yes #+BEGIN_SRC nix {pkgs-nix ? import {}}: with pkgs-nix; @@ -1596,11 +1594,24 @@ sha256-kTHRaAKG7cAGb4IE/NGHWaZ8t7ZceKj03l6E8wLzJzs= #+HEADER: :tangle "../nix-overlays/dub/default.nix" #+BEGIN_SRC nix -{ lib, stdenv, fetchFromGitHub, curl, libevent, rsync, ldc, dcompiler ? ldc }: +import ./package.nix +#+END_SRC + +#+HEADER: :tangle "../nix-overlays/dub/package.nix" +#+BEGIN_SRC nix +{ lib +, stdenv +, fetchFromGitHub +, curl +, <> +, dcompiler ? <> +, libevent +, rsync +}: assert dcompiler != null; -stdenv.mkDerivation rec { +stdenv.mkDerivation (finalAttrs: { pname = "dub"; version = "<>"; @@ -1609,30 +1620,21 @@ stdenv.mkDerivation rec { src = fetchFromGitHub { owner = "dlang"; repo = "dub"; - rev = "v${version}"; - sha256 = "<>"; + rev = "v${finalAttrs.version}"; + hash = "<>"; }; - #postUnpack = '' - # patchShebangs . - #''; - - dubvar = "\\$DUB"; postPatch = '' patchShebangs test - - # Can be removed with https://github.com/dlang/dub/pull/1368 - substituteInPlace test/fetchzip.sh \ - --replace "dub remove" "\"${dubvar}\" remove" ''; nativeBuildInputs = [ dcompiler libevent rsync ]; buildInputs = [ curl ]; - buildPhase = '' - for DC_ in dmd ldmd2 gdmd; do - echo "... check for D compiler $DC_ ..." - export DC=$(type -P $DC_ || echo "") + preBuild = '' + for DCn in dmd ldmd2 gdmd; do + echo "... check for D compiler $DCn ..." + export DC=$(type -P $DCn || echo "") if [ ! "$DC" == "" ]; then break fi @@ -1640,17 +1642,21 @@ stdenv.mkDerivation rec { if [ "$DC" == "" ]; then exit "Error: could not find D compiler" fi - echo "$DC_ found and used as D compiler in buildPhase for $pname" - $DC ./build.d - ./build + echo "$DCn found and used as D compiler in buildPhase for $pname" ''; - doCheck = !stdenv.isDarwin; + buildPhase = '' + runHook preBuild + $DC -run ./build.d + runHook postBuild + ''; + + doCheck = !stdenv.hostPlatform.isDarwin; checkPhase = '' + runHook preCheck export DUB=$NIX_BUILD_TOP/source/bin/dub export PATH=$PATH:$NIX_BUILD_TOP/source/bin/ - #export DC=${dcompiler.out}/bin/${if dcompiler.pname=="ldc" then "ldc2" else dcompiler.pname} if [ "$DC" == "" ]; then exit "Error: could not find D compiler" fi @@ -1658,8 +1664,7 @@ stdenv.mkDerivation rec { export HOME=$TMP rm -rf test/issue502-root-import - rm -rf test/dpath-variable - #rm test/dpath-variable.sh + rm -r test/dpath-variable # requires execution of dpath-variable.sh rm -rf test/git-dependency rm -rf test/use-c-sources # added to build v1.33.0 rm -rf test/pr2642-cache-db # added to build v1.34.0 @@ -1667,21 +1672,35 @@ stdenv.mkDerivation rec { rm -rf test/pr2647-build-deep # added to build v1.36.0 ./test/run-unittest.sh + runHook postCheck ''; installPhase = '' - mkdir -p $out/bin - cp bin/dub $out/bin + runHook preInstall + install -Dm755 bin/dub $out/bin/dub + runHook postInstall ''; meta = with lib; { - description = "Package and build manager for D applications and libraries"; + description = "Package and build manager for D programs and libraries"; homepage = "https://code.dlang.org/"; license = licenses.mit; + mainProgram = "dub"; maintainers = with maintainers; [ jtbx ]; platforms = [ "x86_64-linux" "i686-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; }; -} +}) +#+END_SRC + +*** dcompiler SET + +#+NAME: dcompiler +#+BEGIN_SRC nix +ldc +#+END_SRC + +#+BEGIN_SRC nix +dmd #+END_SRC *** versions SET -- cgit v1.2.3