Fix building on NixOS

This commit is contained in:
Chris Josten 2022-09-15 20:29:06 +02:00
parent 9a5aeb1526
commit bdb7615044
4 changed files with 46 additions and 27 deletions

View File

@ -11,5 +11,6 @@
"license": "AGPLv3",
"name": "mijnblog",
"targetType": "executable",
"stringImportPaths": ["views", "translations"]
"stringImportPaths": ["views", "translations"],
"versions": ["DeimosOpenSSL_3_0"]
}

View File

@ -75,25 +75,25 @@
fetch = {
type = "git";
url = "https://github.com/vibe-d/vibe-core.git";
rev = "v1.22.3";
sha256 = "198s86ym28nnlyif47fa03ldif7w0qbx7bndgav0n79bdw9mw7i7";
rev = "v1.22.4";
sha256 = "0cblfy9dyjkz9wyjsi1mq50w09zy1nbvw3y9v9qrzfhp401zccmx";
fetchSubmodules = false;
date = "2022-04-01T21:24:37+02:00";
date = "2022-05-26T23:00:01+02:00";
deepClone = false;
leaveDotGit = false;
path = "/nix/store/y46jzkaqgjgix4df0gws12pvpxlvkx1s-vibe-core";
path = "/nix/store/7i0n7jf5pl9l4ab294fvjsyx552ph3jg-vibe-core";
};
} {
fetch = {
type = "git";
url = "https://github.com/vibe-d/vibe.d.git";
rev = "v0.9.4";
sha256 = "0kjnrlz30gvb08v79d7x5laapk13fxyj1cfr31wx0px3xrnjpzfq";
rev = "v0.9.5";
sha256 = "1cf8psyfxh7053wwcjm3jm9avyph6dkx7c4fahi0gr1lrflpvpcb";
fetchSubmodules = false;
date = "2021-09-30T14:24:53+02:00";
date = "2022-07-18T17:27:21+02:00";
deepClone = false;
leaveDotGit = false;
path = "/nix/store/3x9z474xs6d65w1my3s7kbr45z938rnc-vibe.d";
path = "/nix/store/dx5wdsw6rrwxrhg1vqx1a1p7jq89rz5g-vibe.d";
};
} {
fetch = {
@ -123,13 +123,13 @@
fetch = {
type = "git";
url = "https://github.com/rejectedsoftware/diet-ng.git";
rev = "v1.8.0";
sha256 = "0ghddla911x815dxcqw3zfvd0276hijw5vkgn5g338asxsz5rxnk";
rev = "v1.8.1";
sha256 = "11hrbvsxhipvcz9m1qlq92iaw0h35pzdy5rf7z8c4vx3hwjrnhni";
fetchSubmodules = false;
date = "2021-07-27T22:07:54+02:00";
date = "2022-04-22T11:38:43+02:00";
deepClone = false;
leaveDotGit = false;
path = "/nix/store/wql4k19cxpdz9sj504hw3sl2rg0vixkw-diet-ng";
path = "/nix/store/xziliy9ah3s3ah8mslnxsw47n4w6wkca-diet-ng";
};
} {
fetch = {
@ -147,13 +147,13 @@
fetch = {
type = "git";
url = "https://github.com/D-Programming-Deimos/openssl.git";
rev = "v1.1.6+1.0.1g";
sha256 = "0ramqjyq4v7xpqwf4nf4ddmsg6yk2fbzn2d1yj4b6dla3q5lv9i3";
rev = "v3.2.2";
sha256 = "1j9cnajkz5s7xk8q1sz4gw69w0dazyz57rjvjncnk5ivl3md7mv2";
fetchSubmodules = false;
date = "2017-11-05T20:15:26+01:00";
date = "2022-07-04T11:40:58+00:00";
deepClone = false;
leaveDotGit = false;
path = "/nix/store/jbfb5in6gzqs2byn1hdc1625yh8sx6j2-openssl";
path = "/nix/store/fdqbs027s89plzmwsjvcg1sr2jajiphv-openssl";
};
} {
fetch = {

View File

@ -9,4 +9,8 @@ mkDubDerivation {
version = "0.0.2";
buildInputs = [ pkgs.openssl ];
propagatedBuildInputs = [ pkgs.nix-prefetch-git ];
extraDubFlags = "--override-config openssl/library-manual-version";
preBuild = ''
export DC=${pkgs.dmd}/bin/dmd
'';
}

View File

@ -1,8 +1,9 @@
{ pkgs ? import <nixpkgs> {},
lib ? pkgs.lib,
stdenv ? pkgs.stdenv,
rdmd ? pkgs.rdmd,
lib ? pkgs.lib,
dtools ? pkgs.dtools or pkgs.rdmd,
dmd ? pkgs.dmd,
dcompiler ? dmd,
dub ? pkgs.dub }:
with stdenv;
@ -21,7 +22,7 @@ let
fromDub = dubDep: mkDerivation rec {
name = "${src.name}-${version}";
version = rev-to-version dubDep.fetch.rev;
nativeBuildInputs = [ rdmd dmd dub ];
nativeBuildInputs = [ dcompiler dtools dub ];
src = dep2src dubDep;
buildPhase = ''
@ -47,10 +48,18 @@ let
targetOf = package: "${package.targetPath or "."}/${package.targetName or package.name}";
# Remove reference to build tools and library sources
disallowedReferences = deps: [ dmd rdmd dub ] ++ builtins.map dep2src deps;
disallowedReferences = deps: [ dcompiler dtools dub ] ++ builtins.map dep2src deps;
removeExpr = refs: ''remove-references-to ${lib.concatMapStrings (ref: " -t ${ref}") refs}'';
# Like split, but only keep the matches
matches = regex: str: builtins.filter lib.isList (builtins.split regex str);
# Very primitive parsing of SDL files, but suffices for name, description, homepage, etc.
importSDL = path: builtins.foldl' (a: l: a // {"${lib.elemAt l 1}"=lib.elemAt l 2;}) {} (matches "(^|\n)([a-z]+) \"([^\"]+)\"" (builtins.readFile path));
importPackage = sdl: json: if builtins.pathExists sdl then importSDL sdl else lib.importJSON json;
in {
inherit fromDub;
@ -58,20 +67,23 @@ in {
src,
nativeBuildInputs ? [],
dubJSON ? src + "/dub.json",
dubSDL ? src + "/dub.sdl",
buildType ? "release",
extraDubFlags ? "",
selections ? src + "/dub.selections.nix",
deps ? import selections,
package ? importPackage dubSDL dubJSON,
passthru ? {},
package ? lib.importJSON dubJSON,
...
} @ attrs: stdenv.mkDerivation (attrs // {
} @ attrs: stdenv.mkDerivation ((removeAttrs attrs ["package" "deps" "selections" "dubJSON" "dubSDL"]) // {
pname = package.name;
nativeBuildInputs = [ rdmd dmd dub pkgs.removeReferencesTo ] ++ nativeBuildInputs;
nativeBuildInputs = [ dcompiler dtools dub pkgs.removeReferencesTo ] ++ nativeBuildInputs;
disallowedReferences = disallowedReferences deps;
passthru = passthru // {
inherit dub dmd rdmd pkgs;
inherit dub dcompiler dtools pkgs;
};
src = lib.cleanSourceWith {
@ -88,7 +100,7 @@ in {
export HOME=$PWD
${lib.concatMapStringsSep "\n" dub-add-local deps}
dub build -b release --combined --skip-registry=all
dub build -b ${buildType} --combined --skip-registry=all ${extraDubFlags}
runHook postBuild
'';
@ -98,7 +110,7 @@ in {
export HOME=$PWD
${lib.concatMapStringsSep "\n" dub-add-local deps}
dub test --combined --skip-registry=all
dub test --combined --skip-registry=all ${extraDubFlags}
runHook postCheck
'';
@ -114,6 +126,8 @@ in {
meta = lib.optionalAttrs (package ? description) {
description = package.description;
} // lib.optionalAttrs (package ? homepage) {
homepage = package.homepage;
} // attrs.meta or {};
} // lib.optionalAttrs (!(attrs ? version)) {
# Use name from dub.json, unless pname and version are specified