···1+# D (Dlang) {#dlang}
2+3+Nixpkgs provides multiple D compilers such as `ldc`, `dmd` and `gdc`.
4+These can be used like any other package during build time.
5+6+However, Nixpkgs provides a build helper for compiling packages using the `dub` package manager.
7+8+Here's an example:
9+```nix
10+{
11+ lib,
12+ buildDubPackage,
13+ fetchFromGitHub,
14+ ncurses,
15+ zlib,
16+}:
17+18+buildDubPackage rec {
19+ pname = "btdu";
20+ version = "0.5.1";
21+22+ src = fetchFromGitHub {
23+ owner = "CyberShadow";
24+ repo = "btdu";
25+ rev = "v${version}";
26+ hash = "sha256-3sSZq+5UJH02IO0Y1yL3BLHDb4lk8k6awb5ZysBQciE=";
27+ };
28+29+ # generated by dub-to-nix, see below
30+ dubLock = ./dub-lock.json;
31+32+ buildInputs = [
33+ ncurses
34+ zlib
35+ ];
36+37+ installPhase = ''
38+ runHook preInstall
39+ install -Dm755 btdu -t $out/bin
40+ runHook postInstall
41+ '';
42+}
43+```
44+45+Note that you need to define `installPhase` because `dub` doesn't know where files should go in `$out`.
46+47+Also note that running `dub test` is disabled by default. You can enable it by setting `doCheck = true`.
48+49+## Lockfiles {#dub-lockfiles}
50+Nixpkgs has its own lockfile format for `dub` dependencies, because `dub`'s official "lockfile" format (`dub.selections.json`) is not hash based.
51+52+A lockfile can be generated using the `dub-to-nix` helper package.
53+* Firstly, install `dub-to-nix` into your shell session by running `nix-shell -p dub-to-nix`
54+* Then navigate to the root of the source of the program you want to package
55+* 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.
56+57+## `buildDubPackage` parameters {#builddubpackage-parameters}
58+59+The `buildDubPackage` function takes an attrset of parameters that are passed on to `stdenv.mkDerivation`.
60+61+The following parameters are specific to `buildDubPackage`:
62+63+* `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`.
64+ 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)
65+* `dubBuildType ? "release"`: The build type to pass to `dub build` as a value for the `--build=` flag.
66+* `dubFlags ? []`: The flags to pass to `dub build` and `dub test`.
67+* `dubBuildFlags ? []`: The flags to pass to `dub build`.
68+* `dubTestFlags ? []`: The flags to pass to `dub test`.
69+* `compiler ? ldc`: The D compiler to be used by `dub`.
···402 The `nimPackages` and `nim2Packages` sets have been removed.
403 See https://nixos.org/manual/nixpkgs/unstable#nim for more information.
404000405- [Portunus](https://github.com/majewsky/portunus) has been updated to major version 2.
406 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.
407 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.
···402 The `nimPackages` and `nim2Packages` sets have been removed.
403 See https://nixos.org/manual/nixpkgs/unstable#nim for more information.
404405+- 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.
406+ See the [D section](https://nixos.org/manual/nixpkgs/unstable#dlang) in the manual for more information.
407+408- [Portunus](https://github.com/majewsky/portunus) has been updated to major version 2.
409 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.
410 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
···0000000
···1+# Build support for D
2+3+Build utilities for the D language can be found in this directory.
4+5+### Current maintainers
6+- @TomaSajt
7+- @jtbx
···1+#!/usr/bin/env python3
2+3+import sys
4+import json
5+import os
6+import subprocess
7+8+def eprint(text: str):
9+ print(text, file=sys.stderr)
10+11+if not os.path.exists("dub.selections.json"):
12+ eprint("The file `dub.selections.json` does not exist in the current working directory")
13+ eprint("run `dub upgrade --annotate` to generate it")
14+ sys.exit(1)
15+16+with open("dub.selections.json") as f:
17+ selectionsJson = json.load(f)
18+19+versionDict: dict[str, str] = selectionsJson["versions"]
20+21+for pname in versionDict:
22+ version = versionDict[pname]
23+ if version.startswith("~"):
24+ eprint(f'Package "{pname}" has a branch-type version "{version}", which doesn\'t point to a fixed version')
25+ eprint("You can resolve it by manually changing the required version to a fixed one inside `dub.selections.json`")
26+ eprint("When packaging, you might need to create a patch for `dub.sdl` or `dub.json` to accept the changed version")
27+ sys.exit(1)
28+29+lockedDependenciesDict: dict[str, dict[str, str]] = {}
30+31+for pname in versionDict:
32+ version = versionDict[pname]
33+ eprint(f"Fetching {pname}@{version}")
34+ url = f"https://code.dlang.org/packages/{pname}/{version}.zip"
35+ command = ["nix-prefetch-url", "--type", "sha256", url]
36+ sha256 = subprocess.run(command, check=True, text=True, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL).stdout.rstrip()
37+ lockedDependenciesDict[pname] = {"version": version, "sha256": sha256}
38+39+print(json.dumps({"dependencies": lockedDependenciesDict}, indent=2))
+5
pkgs/build-support/fetchurl/mirrors.nix
···312 "https://backpan.perl.org/" # for old releases
313 ];
31400000315 # Haskell Hackage
316 hackage = [
317 "https://hackage.haskell.org/package/"
···312 "https://backpan.perl.org/" # for old releases
313 ];
314315+ # D DUB
316+ dub = [
317+ "https://code.dlang.org/packages/"
318+ ];
319+320 # Haskell Hackage
321 hackage = [
322 "https://hackage.haskell.org/package/"