Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
0d68f3d
feat(pkgs/dub): Add source to share, so it can later be loaded as a d…
monyarm Apr 14, 2024
e06d93a
feat(scripts/dump_dlang_pkgs.d): Download and dump dlang package data…
monyarm Apr 14, 2024
cd3957e
feat(scripts/dump_dlang_pkgs.d): Generated nix expressions
monyarm Apr 14, 2024
ab81fc7
feat(gh-actions/update-dub-deb): Run update-dub-db weekly
monyarm Apr 14, 2024
954be46
doc(buildDubPackage): Document usage.
monyarm Apr 14, 2024
19b4352
feat(build-dub-package): buildDubPackage function (supports dub.selec…
monyarm Apr 14, 2024
921cee7
feat(pkgs/dub): version 1.31.0
monyarm Apr 14, 2024
9f21a56
feat(pkgs/d-scanner): Add d-scanner package
monyarm Apr 14, 2024
a3533aa
feat(pkgs/serve-d): Add serve-d package
monyarm Apr 14, 2024
640922b
feat(pkgs/tsv-utils): Add tsv-utils package
monyarm Apr 14, 2024
f1a081c
feat(pkgs/dlangide): Added dlangide
monyarm Apr 14, 2024
7f8e7af
feat(pkgs/inochi2d): Added inochi2d
monyarm Apr 14, 2024
39bcacd
feat(pkgs/graphqld): Added graphqld
monyarm Apr 14, 2024
1ae4443
feat(pkgs/dubproxy): Added dubproxy
monyarm Apr 14, 2024
706601c
feat(pkgs/faked): Added faked
monyarm Apr 14, 2024
1895498
feat(pkgs/juliad): Added juliad
monyarm Apr 14, 2024
d08b209
feat(pkgs/libbetterc): Added libbetterc
monyarm Apr 14, 2024
baacbb3
feat(pkgs/symmetry-gelf): Added symmetry-gelf
monyarm Apr 14, 2024
7f40344
feat(pkgs/xlsxreader): Added xlsxreader
monyarm Apr 14, 2024
079751b
feat(pkgs/mir-algorithm): Added mir-algorithm
monyarm Apr 14, 2024
d77c653
feat(pkgs/mir-optim): Added mir-optim
monyarm Apr 14, 2024
9ce2cd5
feat(pkgs/dpp): Added dpp
monyarm Apr 14, 2024
cfd89b1
feat(pkgs/lubeck): Added lubeck
monyarm Apr 14, 2024
3174f18
refactor(build-dub-package): Fix capitalization on dontDubTest
monyarm Apr 14, 2024
a538bce
feat(pkgs/dust-mite): Added dust-mite
monyarm Apr 14, 2024
dc589a3
feat(pkgs/concurrency): Added concurrency
monyarm Apr 14, 2024
0c15e4a
feat(pkgs/arsd): Added arsd
monyarm Apr 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
42 changes: 42 additions & 0 deletions .github/workflows/update-dub-db.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: "Update Dub Package Database"

on:
# Enable option to manually run the action:
workflow_dispatch:

# Run every Sunday at 00:00:
schedule:
- cron: 0 0 * * 0

jobs:
main:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: cachix/install-nix-action@v25
with:
nix_path: nixpkgs=channel:nixos-unstable
github_access_token: ${{ secrets.GITHUB_TOKEN }}

- name: Run `dump_dlang_pkgs.d`
id: update-lockfile
run: COMMIT_MSG=$(./scripts/commit_flake_update.bash | tee /dev/tty))

- uses: tibdex/[email protected]
id: generate-token
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}

- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
token: ${{ steps.generate-token.outputs.token }}
title: 'Update Dub Package Database'
commit-message: ${{ env.COMMIT_MSG }}
branch: 'create-pull-request/update-dub-package-database'
delete-branch: true
branch-suffix: timestamp
add-paths: flake.lock
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ bin/

# Dotenv
.env

# Misc
pkgs/build-dub-package/packages.json
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,22 @@ one of the differences how things are usually done with and without flakes,
even when it's possible to either pin or to not pin the nixpkgs version
regardless of flake use.

## buildDubPackage

The buildDubPackage function can be used to build software which uses dub for dependency management.

Flags can be supplied to dub using dubFlags, dubTestFlags and dubBuildFlags. dubFlags are added to both build and test.

Unittests are run by default, but can be disabled by `dontDubTest = true;`.

buildDubPackage resolves dependencies using dub.selections.json. If the package repository doesn't contain a dub.selections.json file, it must be supplied through `dubSelections`.

Specific dub/ldc versions can be supplied by using override.

If any files other then the main executable need to installed, they can be supplied through the array `extraFiles`.



## Source and binary variants

DMD and LDC packages come in two variants: `binary` and `source`.
Expand Down
150 changes: 150 additions & 0 deletions pkgs/build-dub-package/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
{
lib,
stdenv,
dub,
dmd,
makeSetupHook,
jq,
bash,
gnugrep,
fetchgit,
writeScript,
}: {
name ? "${args.pname}-${args.version}",
src ? null,
sourceRoot ? null,
prePatch ? "",
patches ? [],
postPatch ? "",
nativeBuildInputs ? [],
buildInputs ? [],
# Flags to pass to all dub commands.
dubFlags ? [],
# Flags to pass to `dub test`.
dubTestFlags ? [],
# Flags to pass to `dub build`.
dubBuildFlags ? [],
# Extra files to copy to $out`.
extraFiles ? [],
# Dub selection file.
dubSelections ? "/notexist/dub.selections.json",
...
} @ args: let
dubConfigHook =
makeSetupHook
{
name = "dub-config-hook";
substitutions = {
"jq" = "${jq}/bin/jq";
"shell" = "${bash}/bin/bash";
"dub" = "${dub}/bin/dub";
};
}
(writeScript "dub-config-hook.sh" ''
#!@shell@
echo "Executing dubConfigHook"

echo "Configuring dub"

export HOME="/build"
mkdir -p $HOME/.dub
if ${gnugrep}/bin/grep "dependenc" ${src}/dub.* &> /dev/null; then
if [ -f ${src}/dub.selections.json ]; then
echo "dub.selections.json exists"
else
if [ -f "${dubSelections}" ]; then
echo "Using ${dubSelections}"
else
echo "dub.selections.json does not exist. Please supply it manually"
exit 1
fi
fi
${
let
selectionsJson =
if builtins.pathExists "${src}/dub.selections.json"
then "${src}/dub.selections.json"
else if dubSelections != "/notexist/dub.selections.json"
then dubSelections
else null;
selections =
if selectionsJson != null
then (builtins.fromJSON (builtins.readFile selectionsJson)).versions
else null;
deps =
if selections != null
then
lib.mapAttrsToList (dep: ver: let
data = import ../dub/pkgs/${dep}/default.nix;
pkg = rec {
name = dep;
version = ver;
path = fetchgit {
url = data.url;
rev = data.versions.${ver}.rev;
sha256 = data.versions.${ver}.sha256;
fetchSubmodules = false;
};
};
in
pkg)
selections
else null;

str =
if deps != null
then
(lib.concatMapStringsSep "\n" (dep: ''
dep_path="$HOME/.dub/packages/${dep.name}-${dep.version}"
mkdir -p "$dep_path"
cp -r "${dep.path}"/* "$dep_path"
@dub@ add-local "$dep_path" "${dep.version}"
'')
deps)
else "";
in
str
}
fi

echo "Finished dubConfigHook"
'');

dubBuildHook =
makeSetupHook
{
name = "dub-build-hook";
substitutions = {
"dub" = "${dub}/bin/dub";
"dmd" = "${dmd}/bin/dmd";
};
}
./dub-build-hook.sh;

dubTestHook =
makeSetupHook
{
name = "dub-test-hook";
substitutions = {
"dub" = "${dub}/bin/dub";
"dmd" = "${dmd}/bin/dmd";
};
}
./dub-test-hook.sh;

dubInstallHook =
makeSetupHook
{
name = "dub-install-hook";
}
./dub-install-hook.sh;
in
stdenv.mkDerivation (args
// {
nativeBuildInputs = nativeBuildInputs ++ [dub dmd dubConfigHook dubBuildHook dubInstallHook dubTestHook];
buildInputs = buildInputs ++ [dub dmd];

strictDeps = true;

meta = (args.meta or {}) // {platforms = args.meta.platforms or dub.meta.platforms;};
})
26 changes: 26 additions & 0 deletions pkgs/build-dub-package/dub-build-hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# shellcheck shell=bash

dubBuildHook() {
echo "Executing dubBuildHook"

runHook preBuild

export HOME="/build"
chmod -R +rw $HOME
chown -R $(whoami) $HOME
if ! @dub@ build $dubBuildFlags "${dubBuildFlagsArray[@]}" $dubFlags "${dubFlagsArray[@]}"; then
echo
echo 'ERROR: `dub build` failed'
echo

exit 1
fi

runHook postBuild

echo "Finished dubBuildHook"
}

if [ -z "${dontdubBuild-}" ] && [ -z "${buildPhase-}" ]; then
buildPhase=dubBuildHook
fi
51 changes: 51 additions & 0 deletions pkgs/build-dub-package/dub-install-hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# shellcheck shell=bash

dubInstallHook() {
echo "Executing dubInstallHook"

runHook preInstall

mkdir -p "$out/bin"
if [ -e "$pname" ]; then
bin=$pname
elif [ -e "bin/$pname" ]; then
bin="bin/$pname"
elif [ -e "$pname/$pname" ]; then
bin="$pname/$pname"
elif [ -e "bin/$pname/$pname" ]; then
bin="bin/$pname/$pname"
elif [ -e "$pname/bin/$pname" ]; then
bin="$pname/bin/$pname"
else
if ls *.a *.so *.so.* *.dylib 1>/dev/null 2>&1; then
echo "INFO: Could not find the binary to install, but found some libraries"
elif [ -z "${extraFiles-}" ]; then
echo "ERROR: Could not find the binary to install, or any libraries, and no additional files were specified"
exit 1
else
echo "WARNING: Could not find the binary to install, but additional files were specified"
fi
fi


if [ -n "${bin-}" ]; then
cp "$bin" "$out/bin"
fi

mkdir -p "$out/lib"
cp -r *.a *.so *.so.* *.dylib "$out/lib" 2>/dev/null || true

for f in $extraFiles; do
fDir=$(dirname "$f")
mkdir -p "$out/$fDir"
cp "$f" "$fDir/$f"
done

runHook postInstall

echo "Finished dubInstallHook"
}

if [ -z "${dontdubInstall-}" ] && [ -z "${installPhase-}" ]; then
installPhase=dubInstallHook
fi
27 changes: 27 additions & 0 deletions pkgs/build-dub-package/dub-test-hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# shellcheck shell=bash

dubTestHook() {
echo "Executing dubTestHook"

runHook preTest

export HOME="/build"
chmod -R +rw $HOME
chown -R $(whoami) $HOME
if ! @dub@ test $dubTestFlags "${dubTestFlagsArray[@]}" $dubFlags "${dubFlagsArray[@]}"; then
echo
echo 'ERROR: `dub test` failed'
echo

exit 1
fi

runHook postTest

echo "Finished dubTestHook"
}

if [ -z "${dontDubTest-}" ] && [ -z "${checkPhase-}" ]; then
checkPhase=dubTestHook
doCheck=true
fi
1 change: 1 addition & 0 deletions pkgs/build-dub-package/dubPkgs.json

Large diffs are not rendered by default.

Loading