GDC 11 was the last version that could bootstrap without a D compiler, and GDC don’t offer their own binaries any more. GCC 11 is now end‐of‐life and being removed (as is GCC 12, even). It’s possible that we could use another distribution’s binary packages to bootstrap this, or go via our DMD package (it’s apparently not possible to bootstrap GDC with LDC, but I’m not sure about DMD), but as nobody has worked on it in the three years since GCC 12 came out, it seems like interest is limited, and it’s more of a yak shave than I’m up for right now. A full from‐source bootstrap chain would of course be nice, but is more the realm of the minimal bootstrap work than something we’d want to keep GCC 11 around in the main package set indefinitely for.
2.4 KiB
D (Dlang)
Nixpkgs provides multiple D compilers such as ldc and dmd.
These can be used like any other package during build time.
However, Nixpkgs provides a build helper for compiling packages using the dub package manager.
Here's an example:
{
lib,
buildDubPackage,
fetchFromGitHub,
ncurses,
zlib,
}:
buildDubPackage rec {
pname = "btdu";
version = "0.5.1";
src = fetchFromGitHub {
owner = "CyberShadow";
repo = "btdu";
tag = "v${version}";
hash = "sha256-3sSZq+5UJH02IO0Y1yL3BLHDb4lk8k6awb5ZysBQciE=";
};
# generated by dub-to-nix, see below
dubLock = ./dub-lock.json;
buildInputs = [
ncurses
zlib
];
installPhase = ''
runHook preInstall
install -Dm755 btdu -t $out/bin
runHook postInstall
'';
}
Note that you need to define installPhase because dub doesn't know where files should go in $out.
Also note that running dub test is disabled by default. You can enable it by setting doCheck = true.
Lockfiles
Nixpkgs has its own lockfile format for dub dependencies, because dub's official "lockfile" format (dub.selections.json) is not hash based.
A lockfile can be generated using the dub-to-nix helper package.
- Firstly, install
dub-to-nixinto your shell session by runningnix-shell -p dub-to-nix - Then navigate to the root of the source of the program you want to package
- Finally, run
dub-to-nixand it will print the lockfile to stdout. You could pipe stdout into a text file or just copy the output manually into a file.
buildDubPackage parameters
The buildDubPackage function takes an attrset of parameters that are passed on to stdenv.mkDerivation.
The following parameters are specific to buildDubPackage:
dubLock: A lockfile generated bydub-to-nixfrom the source of the package. Can be either a path to the file, or an attrset already parsed withlib.importJSON. The latter useful if the package usesdubdependencies not already in the lockfile. (e.g. if the package callsdub run some-dub-packagemanually)dubBuildType ? "release": The build type to pass todub buildas a value for the--build=flag.dubFlags ? []: The flags to pass todub buildanddub test.dubBuildFlags ? []: The flags to pass todub build.dubTestFlags ? []: The flags to pass todub test.compiler ? ldc: The D compiler to be used bydub.