···11+# D (Dlang) {#dlang}
22+33+Nixpkgs provides multiple D compilers such as `ldc`, `dmd` and `gdc`.
44+These can be used like any other package during build time.
55+66+However, Nixpkgs provides a build helper for compiling packages using the `dub` package manager.
77+88+Here's an example:
99+```nix
1010+{
1111+ lib,
1212+ buildDubPackage,
1313+ fetchFromGitHub,
1414+ ncurses,
1515+ zlib,
1616+}:
1717+1818+buildDubPackage rec {
1919+ pname = "btdu";
2020+ version = "0.5.1";
2121+2222+ src = fetchFromGitHub {
2323+ owner = "CyberShadow";
2424+ repo = "btdu";
2525+ rev = "v${version}";
2626+ hash = "sha256-3sSZq+5UJH02IO0Y1yL3BLHDb4lk8k6awb5ZysBQciE=";
2727+ };
2828+2929+ # generated by dub-to-nix, see below
3030+ dubLock = ./dub-lock.json;
3131+3232+ buildInputs = [
3333+ ncurses
3434+ zlib
3535+ ];
3636+3737+ installPhase = ''
3838+ runHook preInstall
3939+ install -Dm755 btdu -t $out/bin
4040+ runHook postInstall
4141+ '';
4242+}
4343+```
4444+4545+Note that you need to define `installPhase` because `dub` doesn't know where files should go in `$out`.
4646+4747+Also note that running `dub test` is disabled by default. You can enable it by setting `doCheck = true`.
4848+4949+## Lockfiles {#dub-lockfiles}
5050+Nixpkgs has its own lockfile format for `dub` dependencies, because `dub`'s official "lockfile" format (`dub.selections.json`) is not hash based.
5151+5252+A lockfile can be generated using the `dub-to-nix` helper package.
5353+* Firstly, install `dub-to-nix` into your shell session by running `nix-shell -p dub-to-nix`
5454+* Then navigate to the root of the source of the program you want to package
5555+* Finally, run `dub-to-nix` and it will print the lockfile to stdout. You could pipe stdout into a text file or just copy the output manually into a file.
5656+5757+## `buildDubPackage` parameters {#builddubpackage-parameters}
5858+5959+The `buildDubPackage` function takes an attrset of parameters that are passed on to `stdenv.mkDerivation`.
6060+6161+The following parameters are specific to `buildDubPackage`:
6262+6363+* `dubLock`: A lockfile generated by `dub-to-nix` from the source of the package. Can be either a path to the file, or an attrset already parsed with `lib.importJSON`.
6464+ The latter useful if the package uses `dub` dependencies not already in the lockfile. (e.g. if the package calls `dub run some-dub-package` manually)
6565+* `dubBuildType ? "release"`: The build type to pass to `dub build` as a value for the `--build=` flag.
6666+* `dubFlags ? []`: The flags to pass to `dub build` and `dub test`.
6767+* `dubBuildFlags ? []`: The flags to pass to `dub build`.
6868+* `dubTestFlags ? []`: The flags to pass to `dub test`.
6969+* `compiler ? ldc`: The D compiler to be used by `dub`.
···402402 The `nimPackages` and `nim2Packages` sets have been removed.
403403 See https://nixos.org/manual/nixpkgs/unstable#nim for more information.
404404405405+- Programs written in [D](https://dlang.org/) using the `dub` build system and package manager can now be built using `buildDubPackage` utilizing lockfiles provided by the new `dub-to-nix` helper program.
406406+ See the [D section](https://nixos.org/manual/nixpkgs/unstable#dlang) in the manual for more information.
407407+405408- [Portunus](https://github.com/majewsky/portunus) has been updated to major version 2.
406409 This version of Portunus supports strong password hashes, but the legacy hash SHA-256 is also still supported to ensure a smooth migration of existing user accounts.
407410 After upgrading, follow the instructions on the [upstream release notes](https://github.com/majewsky/portunus/releases/tag/v2.0.0) to upgrade all user accounts to strong password hashes.
+7
pkgs/build-support/dlang/README.md
···11+# Build support for D
22+33+Build utilities for the D language can be found in this directory.
44+55+### Current maintainers
66+- @TomaSajt
77+- @jtbx
···11+#!/usr/bin/env python3
22+33+import sys
44+import json
55+import os
66+import subprocess
77+88+def eprint(text: str):
99+ print(text, file=sys.stderr)
1010+1111+if not os.path.exists("dub.selections.json"):
1212+ eprint("The file `dub.selections.json` does not exist in the current working directory")
1313+ eprint("run `dub upgrade --annotate` to generate it")
1414+ sys.exit(1)
1515+1616+with open("dub.selections.json") as f:
1717+ selectionsJson = json.load(f)
1818+1919+versionDict: dict[str, str] = selectionsJson["versions"]
2020+2121+for pname in versionDict:
2222+ version = versionDict[pname]
2323+ if version.startswith("~"):
2424+ eprint(f'Package "{pname}" has a branch-type version "{version}", which doesn\'t point to a fixed version')
2525+ eprint("You can resolve it by manually changing the required version to a fixed one inside `dub.selections.json`")
2626+ eprint("When packaging, you might need to create a patch for `dub.sdl` or `dub.json` to accept the changed version")
2727+ sys.exit(1)
2828+2929+lockedDependenciesDict: dict[str, dict[str, str]] = {}
3030+3131+for pname in versionDict:
3232+ version = versionDict[pname]
3333+ eprint(f"Fetching {pname}@{version}")
3434+ url = f"https://code.dlang.org/packages/{pname}/{version}.zip"
3535+ command = ["nix-prefetch-url", "--type", "sha256", url]
3636+ sha256 = subprocess.run(command, check=True, text=True, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL).stdout.rstrip()
3737+ lockedDependenciesDict[pname] = {"version": version, "sha256": sha256}
3838+3939+print(json.dumps({"dependencies": lockedDependenciesDict}, indent=2))
+5
pkgs/build-support/fetchurl/mirrors.nix
···312312 "https://backpan.perl.org/" # for old releases
313313 ];
314314315315+ # D DUB
316316+ dub = [
317317+ "https://code.dlang.org/packages/"
318318+ ];
319319+315320 # Haskell Hackage
316321 hackage = [
317322 "https://hackage.haskell.org/package/"