12 # See https://nixos.org/manual/nixpkgs/unstable#dlang for more detailed usage information
15 # A lockfile generated by `dub-to-nix` from the source of the package.
16 # Can be either a path to the file, or an attrset already parsed with `lib.importJSON`.
18 # The build type to pass to `dub build` as a value for the `--build=` flag.
19 dubBuildType ? "release",
20 # The flags to pass to `dub build` and `dub test`.
22 # The flags to pass to `dub build`.
24 # The flags to pass to `dub test`.
26 # The D compiler to be used by `dub`.
39 inherit pname version;
41 name = "dub-${pname}-${version}.zip";
42 url = "mirror://dub/${pname}/${version}.zip";
55 inherit pname version;
63 lockJson = if lib.isPath dubLock then lib.importJSON dubLock else dubLock;
64 depsRaw = lib.mapAttrsToList (pname: args: { inherit pname; } // args) lockJson.dependencies;
66 dubDeps = map makeDubDep (lib.filter (args: !(args ? repository)) depsRaw);
67 gitDeps = map makeGitDep (lib.filter (args: args ? repository) depsRaw);
69 # a directory with multiple single element registries
70 # one big directory with all .zip files leads to version parsing errors
71 # when the name of a package is a prefix of the name of another package
72 dubRegistryBase = linkFarm "dub-registry-base" (
74 name = "${dep.pname}/${dep.pname}-${dep.version}.zip";
79 combinedFlags = "--skip-registry=all --compiler=${lib.getExe compiler} ${toString dubFlags}";
80 combinedBuildFlags = "${combinedFlags} --build=${dubBuildType} ${toString dubBuildFlags}";
81 combinedTestFlags = "${combinedFlags} ${toString dubTestFlags}";
84 builtins.removeAttrs args [ "dubLock" ]
86 strictDeps = args.strictDeps or true;
88 nativeBuildInputs = args.nativeBuildInputs or [ ] ++ [
95 args.configurePhase or ''
98 export DUB_HOME="$NIX_BUILD_TOP/.dub"
101 # register dub dependencies
102 ${lib.concatMapStringsSep "\n" (dep: ''
103 dub fetch ${dep.pname}@${dep.version} --cache=user --skip-registry=standard --registry=file://${dubRegistryBase}/${dep.pname}
106 # register git dependencies
107 ${lib.concatMapStringsSep "\n" (dep: ''
108 mkdir -p "$DUB_HOME/packages/${dep.pname}/${dep.version}"
109 cp -r --no-preserve=all ${dep.src} "$DUB_HOME/packages/${dep.pname}/${dep.version}/${dep.pname}"
112 runHook postConfigure
116 args.buildPhase or ''
119 dub build ${combinedBuildFlags}
124 doCheck = args.doCheck or false;
127 args.checkPhase or ''
130 dub test ${combinedTestFlags}
136 ${args.preFixup or ""}
138 find "$out" -type f -exec remove-references-to -t ${compiler} '{}' +
141 disallowedReferences = [ compiler ];
144 platforms = dub.meta.platforms;
145 } // args.meta or { };