diff --git a/pkgs/default.nix b/pkgs/default.nix index 4fff6e60..de8c0264 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -1,4 +1,11 @@ -{inputs, ...}: { +{ + inputs, + lib, + ... +}: let + inherit (builtins) attrNames listToAttrs map mapAttrs; + inherit (lib) nameValuePair pipe optionalAttrs; +in { imports = [inputs.flake-parts.flakeModules.easyOverlay]; perSystem = { @@ -6,12 +13,59 @@ pkgs, ... }: let - inherit (pkgs) callPackage lib darwin hostPlatform; + inherit (pkgs) callPackage hostPlatform; darwinPkgs = { - inherit (darwin.apple_sdk.frameworks) Foundation; + inherit (pkgs.darwin.apple_sdk.frameworks) Foundation; + }; + + genPkgVersions = pkgName: let + mod = ./. + "/${pkgName}/version-catalog.nix"; + inherit + (import mod) + supportedVersions + getSourceVersion + getBinaryVersion + ; + getVersion = type: + if type == "source" + then getSourceVersion + else getBinaryVersion; + in { + flattened = type: let + nameSuffix = + if type == "binary" + then "-binary" + else ""; + in + pipe (attrNames supportedVersions."${type}") [ + ( + map ( + version: + nameValuePair + "${pkgName}${nameSuffix}-${version}" + (callPackage (getVersion type version) darwinPkgs) + ) + ) + listToAttrs + ]; + + hierarchical = { + "${pkgName}" = pipe ["source" "binary"] [ + (map (type: + nameValuePair type ( + mapAttrs + (version: _: (callPackage (getVersion type version) darwinPkgs)) + supportedVersions."${type}" + ))) + listToAttrs + ]; + }; }; in { overlayAttrs = self'.packages; + legacyPackages = + {} + // (genPkgVersions "dmd").hierarchical; packages = { ldc-binary = callPackage ./ldc/bootstrap.nix {}; @@ -19,9 +73,13 @@ dub = callPackage ./dub {}; } - // lib.optionalAttrs hostPlatform.isx86 { - dmd-binary = callPackage ./dmd/bootstrap.nix {}; - dmd = callPackage ./dmd darwinPkgs; - }; + // optionalAttrs hostPlatform.isx86 ( + { + dmd-bootstrap = self'.packages."dmd-binary-2.098.0"; + dmd = self'.packages."dmd-2.100.2"; + } + // (genPkgVersions "dmd").flattened "binary" + // (genPkgVersions "dmd").flattened "source" + ); }; } diff --git a/pkgs/dmd/2.098.nix b/pkgs/dmd/2.098.nix deleted file mode 100644 index b2752b86..00000000 --- a/pkgs/dmd/2.098.nix +++ /dev/null @@ -1,7 +0,0 @@ -import ./generic.nix { - version = "2.098.1"; - dmdSha256 = "0xf2l1yqncbmyggdn6pqc82f93cnnzg9mgkkq63l41f89y4man7b"; - druntimeSha256 = "1vd1b4vj1f5d5rr6ixfsr27m81z27yv6f4j1i6dsn7l9c73dppqw"; - phobosSha256 = "1l0z08xrab5hhnblkamlzbl1ia3szbliy1qx9f5khz0nsj9vgihq"; - toolsSha256 = "sha256-+pH7X9YRh0yG0iZoDkC6X50uscb4WKXmk2V+74cMSW8="; -} diff --git a/pkgs/dmd/2.100.nix b/pkgs/dmd/2.100.nix deleted file mode 100644 index d3978a4b..00000000 --- a/pkgs/dmd/2.100.nix +++ /dev/null @@ -1,7 +0,0 @@ -import ./generic.nix { - version = "2.100.2"; - dmdSha256 = "sha256-o4+G3ARXIGObYHtHooYZKr+Al6kHpiwpMIog3i4BlDM="; - druntimeSha256 = "sha256-qXvY1ECN4mPwOGgOE1FWwvxoRvlSww3tGLWgBdhzAKo="; - phobosSha256 = "sha256-kTHRaAKG7cAGb4IE/NGHWaZ8t7ZceKj03l6E8wLzJzs="; - toolsSha256 = "sha256-2yzdkarbsf0kOXzLaS6bvBFoiYbDulnEHTozmHX3Oc4="; -} diff --git a/pkgs/dmd/2.102.nix b/pkgs/dmd/2.102.nix deleted file mode 100644 index 65a10baf..00000000 --- a/pkgs/dmd/2.102.nix +++ /dev/null @@ -1,6 +0,0 @@ -import ./generic.nix { - version = "2.102.2"; - dmdSha256 = "sha256-der9nb31hJ+K1aJZdzIgs8+eRgVVsH97QnYEnVbKUws="; - phobosSha256 = "sha256-SracmUm2aY/LDCyDqYuVS39pCbwO8UCL3TSB0CVHpHE="; - toolsSha256 = "sha256-XM4gUxcarQCOBR8W/o0iWAI54PyLDkH6CsDce22Cnu4="; -} diff --git a/pkgs/dmd/binary.nix b/pkgs/dmd/binary.nix index 4a2ce4cf..11b65c47 100644 --- a/pkgs/dmd/binary.nix +++ b/pkgs/dmd/binary.nix @@ -1,4 +1,7 @@ { + version, + hashes, +}: { lib, stdenv, fetchurl, @@ -7,8 +10,7 @@ autoPatchelfHook, fixDarwinDylibNames, gccForLibs, - version, - hashes, + ... }: let inherit (stdenv) hostPlatform; OS = diff --git a/pkgs/dmd/bootstrap.nix b/pkgs/dmd/bootstrap.nix index 0fc6fb01..36695f96 100644 --- a/pkgs/dmd/bootstrap.nix +++ b/pkgs/dmd/bootstrap.nix @@ -1,5 +1,4 @@ -{callPackage}: -callPackage ./binary.nix { +import ./binary.nix { version = "2.098.0"; hashes = { # COMPILER=dmd VERSION=2.098.0 ./scripts/fetch-binary diff --git a/pkgs/dmd/generic.nix b/pkgs/dmd/generic.nix index 31c414e1..35f2fb6d 100644 --- a/pkgs/dmd/generic.nix +++ b/pkgs/dmd/generic.nix @@ -81,15 +81,20 @@ then "druntime" else "dmd/druntime"; - commonBuildFlags = [ - "-fposix.mak" - "SHELL=${bash}/bin/bash" - "DMD=$(NIX_BUILD_TOP)/dmd/${buildPath}/dmd" - "CC=${if stdenv.isDarwin then stdenv.cc else gcc11}/bin/cc" - "HOST_DMD=${HOST_DMD}" - "PIC=1" - "BUILD=${buildMode}" - ] + commonBuildFlags = + [ + "-fposix.mak" + "SHELL=${bash}/bin/bash" + "DMD=$(NIX_BUILD_TOP)/dmd/${buildPath}/dmd" + "CC=${ + if stdenv.isDarwin + then stdenv.cc + else gcc11 + }/bin/cc" + "HOST_DMD=${HOST_DMD}" + "PIC=1" + "BUILD=${buildMode}" + ] # There is an "ifdef ENABLE_COVERAGE" rule in Phobos posix.max causing # coverage to be enabled even if it's set to 0. For consistency we leave # any false values unset. @@ -107,37 +112,39 @@ in enableParallelBuilding = true; - srcs = [ - (fetchFromGitHub { - owner = "dlang"; - repo = "dmd"; - rev = "v${version}"; - sha256 = dmdSha256; - name = "dmd"; - }) - (fetchFromGitHub { - owner = "dlang"; - repo = "phobos"; - rev = "v${version}"; - sha256 = phobosSha256; - name = "phobos"; - }) - (fetchFromGitHub { - owner = "dlang"; - repo = "tools"; - rev = "v${version}"; - sha256 = toolsSha256; - name = "tools"; - }) - ] ++ lib.optionals druntimeRepo [ - (fetchFromGitHub { - owner = "dlang"; - repo = "druntime"; - rev = "v${version}"; - sha256 = druntimeSha256; - name = "druntime"; - }) - ]; + srcs = + [ + (fetchFromGitHub { + owner = "dlang"; + repo = "dmd"; + rev = "v${version}"; + sha256 = dmdSha256; + name = "dmd"; + }) + (fetchFromGitHub { + owner = "dlang"; + repo = "phobos"; + rev = "v${version}"; + sha256 = phobosSha256; + name = "phobos"; + }) + (fetchFromGitHub { + owner = "dlang"; + repo = "tools"; + rev = "v${version}"; + sha256 = toolsSha256; + name = "tools"; + }) + ] + ++ lib.optionals druntimeRepo [ + (fetchFromGitHub { + owner = "dlang"; + repo = "druntime"; + rev = "v${version}"; + sha256 = druntimeSha256; + name = "druntime"; + }) + ]; sourceRoot = "."; @@ -247,7 +254,8 @@ in export MAKEFLAGS="-j$buildJobs" make -C dmd $buildFlags - ${lib.optionalString druntimeRepo + ${ + lib.optionalString druntimeRepo "make -C druntime $buildFlags" } make -C phobos $buildFlags DFLAGS="${phobosDflags}" @@ -282,8 +290,8 @@ in make -C dmd test $checkFlags ${lib.optionalString druntimeRepo '' - NIX_ENFORCE_PURITY= \ - make -C druntime unittest $checkFlags + NIX_ENFORCE_PURITY= \ + make -C druntime unittest $checkFlags ''} NIX_ENFORCE_PURITY= \ diff --git a/pkgs/dmd/supported-source-versions.json b/pkgs/dmd/supported-source-versions.json new file mode 100644 index 00000000..7e002586 --- /dev/null +++ b/pkgs/dmd/supported-source-versions.json @@ -0,0 +1,19 @@ +{ + "2.098.1": { + "dmd": "sha256-61hViU/IBUKHwXO+mt63lo3kBGL4Gtve83Uxi32gwnU=", + "druntime": "sha256-HN/bxmGJHqubiUESZ7Y/4gdUj8ja9WhyLq24IDdZoe0=", + "phobos": "sha256-GMa3k9QWfDiLSx0HH+n6eqgY6Pq0qkmXhbAslTsCH9A=", + "tools": "sha256-+pH7X9YRh0yG0iZoDkC6X50uscb4WKXmk2V+74cMSW8=" + }, + "2.100.2": { + "dmd": "sha256-o4+G3ARXIGObYHtHooYZKr+Al6kHpiwpMIog3i4BlDM=", + "druntime": "sha256-qXvY1ECN4mPwOGgOE1FWwvxoRvlSww3tGLWgBdhzAKo=", + "phobos": "sha256-kTHRaAKG7cAGb4IE/NGHWaZ8t7ZceKj03l6E8wLzJzs=", + "tools": "sha256-2yzdkarbsf0kOXzLaS6bvBFoiYbDulnEHTozmHX3Oc4=" + }, + "2.102.2": { + "dmd": "sha256-der9nb31hJ+K1aJZdzIgs8+eRgVVsH97QnYEnVbKUws=", + "phobos": "sha256-SracmUm2aY/LDCyDqYuVS39pCbwO8UCL3TSB0CVHpHE=", + "tools": "sha256-XM4gUxcarQCOBR8W/o0iWAI54PyLDkH6CsDce22Cnu4=" + } +} diff --git a/pkgs/dmd/version-catalog.nix b/pkgs/dmd/version-catalog.nix new file mode 100644 index 00000000..326193d0 --- /dev/null +++ b/pkgs/dmd/version-catalog.nix @@ -0,0 +1,38 @@ +rec { + supportedVersions = { + source = builtins.fromJSON ( + builtins.readFile ./supported-source-versions.json + ); + + binary = builtins.fromJSON ( + builtins.readFile ./supported-binary-versions.json + ); + }; + + getSourceVersion = version: + assert builtins.hasAttr version supportedVersions.source; let + componentHashes = supportedVersions.source."${version}"; + in + import ./generic.nix ({ + inherit version; + dmdSha256 = componentHashes.dmd; + phobosSha256 = componentHashes.phobos; + toolsSha256 = componentHashes.tools; + } + // ( + if componentHashes ? "druntime" + then { + druntimeSha256 = componentHashes.druntime; + } + else {} + )); + + getBinaryVersion = version: + assert builtins.hasAttr version supportedVersions.binary; let + componentHashes = supportedVersions.binary."${version}"; + in + import ./binary.nix { + inherit version; + hashes = componentHashes; + }; +} diff --git a/pkgs/ldc/binary.nix b/pkgs/ldc/binary.nix index 13700c5f..0f9b3d92 100644 --- a/pkgs/ldc/binary.nix +++ b/pkgs/ldc/binary.nix @@ -68,6 +68,6 @@ in maintainers = with maintainers; [ThomasMader lionello]; # FIXME: change to the following after the CI verifies it: # platforms = builtins.attrNames systemToArchivePlatform; - platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"]; + platforms = ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"]; }; }