3 Nixpkgs provides multiple D compilers such as `ldc`, `dmd` and `gdc`.
4 These can be used like any other package during build time.
6 However, Nixpkgs provides a build helper for compiling packages using the `dub` package manager.
22 src = fetchFromGitHub {
23 owner = "CyberShadow";
26 hash = "sha256-3sSZq+5UJH02IO0Y1yL3BLHDb4lk8k6awb5ZysBQciE=";
29 # generated by dub-to-nix, see below
30 dubLock = ./dub-lock.json;
39 install -Dm755 btdu -t $out/bin
45 Note that you need to define `installPhase` because `dub` doesn't know where files should go in `$out`.
47 Also note that running `dub test` is disabled by default. You can enable it by setting `doCheck = true`.
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.
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.
57 ## `buildDubPackage` parameters {#builddubpackage-parameters}
59 The `buildDubPackage` function takes an attrset of parameters that are passed on to `stdenv.mkDerivation`.
61 The following parameters are specific to `buildDubPackage`:
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`.