Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/generate-matrix/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ runs:
uses: actions/upload-artifact@v4
with:
name: matrix-${{ inputs.is-initial == 'true' && 'pre' || 'post' }}.json
path: matrix-${{ inputs.is-initial == 'true' && 'pre' || 'post' }}.json
path: .result/matrix-${{ inputs.is-initial == 'true' && 'pre' || 'post' }}.json

- name: Update GitHub Comment
uses: marocchino/[email protected]
with:
path: comment.md
path: .result/comment.md
11 changes: 8 additions & 3 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
inherit (lock.nodes.flake-compat.locked) owner repo rev narHash;
inherit (lock.nodes.flake-compat.locked)
owner
repo
rev
narHash
;
flake-compat = fetchTarball {
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
sha256 = narHash;
};
thisFlake = import flake-compat {src = ./.;};
thisFlake = import flake-compat { src = ./.; };
in
thisFlake.defaultNix
thisFlake.defaultNix
68 changes: 41 additions & 27 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
description = "Nix packages for D projects";

nixConfig = {
extra-substituters = ["https://dlang-community.cachix.org"];
extra-trusted-public-keys = ["dlang-community.cachix.org-1:eAX1RqX4PjTDPCAp/TvcZP+DYBco2nJBackkAJ2BsDQ="];
extra-substituters = [ "https://dlang-community.cachix.org" ];
extra-trusted-public-keys = [
"dlang-community.cachix.org-1:eAX1RqX4PjTDPCAp/TvcZP+DYBco2nJBackkAJ2BsDQ="
];
};

inputs = {
Expand All @@ -17,33 +19,45 @@
};
};

outputs = inputs @ {
self,
nixpkgs,
flake-parts,
...
}:
flake-parts.lib.mkFlake {inherit inputs;} {
systems = ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"];
imports = [./pkgs ./lib/mk-gh-actions-matrix.nix];
outputs =
inputs@{
self,
nixpkgs,
flake-parts,
...
}:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
imports = [
./pkgs
./lib
];

perSystem = {pkgs, ...}: {
devShells.default = import ./shells/default.nix {inherit pkgs;};
devShells.ci = import ./shells/ci.nix {inherit pkgs;};
};
perSystem =
{ pkgs, ... }:
{
devShells.default = import ./shells/default.nix { inherit pkgs; };
devShells.ci = import ./shells/ci.nix { inherit pkgs; };
};

flake.templates = let
lib = nixpkgs.lib;
allTemplates = lib.pipe (builtins.readDir ./templates) [
(lib.filterAttrs (k: v: v == "directory"))
(builtins.mapAttrs (k: v: rec {
path = ./templates + "/${k}";
description = lib.removeSuffix "\n" (
builtins.readFile (path + "/description.txt")
);
}))
];
in
flake.templates =
let
lib = nixpkgs.lib;
allTemplates = lib.pipe (builtins.readDir ./templates) [
(lib.filterAttrs (k: v: v == "directory"))
(builtins.mapAttrs (
k: v: rec {
path = ./templates + "/${k}";
description = lib.removeSuffix "\n" (builtins.readFile (path + "/description.txt"));
}
))
];
in
allTemplates;
};
}
16 changes: 9 additions & 7 deletions lib/build-status.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{lib, ...}: {
getBuildStatus = package: version: system: let
data = import ./../pkgs/${package}/build-status.nix {inherit lib;};
in
data.${version}.${system}
or {
{ lib, ... }:
{
getBuildStatus =
package: version: system:
let
data = import ./../pkgs/${package}/build-status.nix { inherit lib; };
in
data.${version}.${system} or {
# If not build status is found, we assume that the package builds
# successfully with no workarounds.
build = true;
check = true;
skippedTests = [];
skippedTests = [ ];
};
}
138 changes: 138 additions & 0 deletions lib/dc.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
{ lib }:
let
inherit (import ./version-utils.nix { }) versionBetween;
in
rec {
/**
Mapping from $DC to $DMD name

# Type

```
dcToDmdMapping :: AttrSet String
```
*/
dcToDmdMapping = {
"dmd" = "dmd";
"ldc" = "ldmd2";
"gdc" = "gdmd";
};

/**
Removes the "-binary" suffix (if any) from the package name.

# Type

```
normalizedName :: String -> String
```

# Examples:

```nix
normalizedName "dmd"
=> "dmd"

normalizedName "dmd-binary"
=> "dmd"

normalizedName "ldc-binary"
=> "ldc"
```
*/
normalizedName = name: lib.strings.removeSuffix "-binary" name;

/**
Given an LDC version, returns the approximate DMD frontend version.

# Type

```
ldcToDmdVersion :: String -> String
```

# Examples:

```nix
ldcToDmdVersion "1.23.0"
=> "2.093.1"

ldcToDmdVersion "1.1.0"
=> "2.071.1"

ldcToDmdVersion "1.38.0"
=> "2.108.1"
```
*/
ldcToDmdVersion =
ldcVersion:
let
minor = 70 + (lib.toInt (lib.versions.minor ldcVersion));
mid = if minor < 100 then "0" + toString minor else toString minor;
in
"2.${mid}.1";

/**
Given a D compiler derivation, returns the information needed to
generate a DMD frontend wrapper.

# Type

```
getDCInfo :: Derivation -> { name, dmdWrapperName, dmdWrapper, frontendVersion }
```

# Examples:

```nix
getDCInfo {
pname = "dmd";
version = "2.093.1";
# ...
}
=> {
name = "dmd";
dmdWrapperName = "dmd";
dmdWrapper = "/nix/store/...-dmd/bin/dmd";
frontendVersion = "2.093.1";
}

getDCInfo {
pname = "ldc";
version = "1.23.0";
# ...
}
=> {
name = "ldc";
dmdWrapperName = "ldmd2";
dmdWrapper = "/nix/store/...-ldc/bin/ldmd2";
frontendVersion = "2.093.1";
}
```
*/
getDCInfo =
dCompilerDrv@{ pname, version, ... }:
let
name = normalizedName pname;
dmdWrapperName = dcToDmdMapping."${name}";
dmdWrapper = "${dCompilerDrv}/bin/${dmdWrapperName}";
frontendVersion =
if name == "dmd" then
version
else if name == "ldc" then
ldcToDmdVersion version
else
throw "Unsupported compiler '${name}'";
in
{
inherit
name
dmdWrapperName
dmdWrapper
frontendVersion
;

frontendVersionBetween =
minVersion: maxVersion: versionBetween minVersion maxVersion frontendVersion;
};
}
9 changes: 9 additions & 0 deletions lib/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{ self, lib, ... }:
{
flake.lib = {
build-status = import ./build-status.nix { inherit lib; };
dc = import ./dc.nix { inherit lib; };
inherit (import ./mk-gh-actions-matrix.nix { inherit self lib; }) allowedToFailMap;
versionUtils = import ./version-utils.nix { };
};
}
101 changes: 46 additions & 55 deletions lib/mk-gh-actions-matrix.nix
Original file line number Diff line number Diff line change
@@ -1,61 +1,52 @@
{
lib,
self,
...
}: {
flake = {
lib = rec {
# See https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#standard-github-hosted-runners-for-public-repositories
# See https://www.flyci.net/#pricing
nixSystemToGHPlatform = {
# GH-hosted runners:
"x86_64-linux" = "ubuntu-latest";
# "x86_64-darwin" = "macos-13"; - macos-13 is a 4 x86_64 vCPU / 14GB RAM
# "x86_64-darwin" = "macos-14"; # - macos-14 is a 3 aarch64 vCPU / 7GB RAM (but it seems faster than the macos-13 one)
# "aarch64-darwin" = "macos-14";
{ lib, self, ... }:
rec {
# See https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#standard-github-hosted-runners-for-public-repositories
# See https://www.flyci.net/#pricing
nixSystemToGHPlatform = {
# GH-hosted runners:
"x86_64-linux" = "ubuntu-latest";
# "x86_64-darwin" = "macos-13"; - macos-13 is a 4 x86_64 vCPU / 14GB RAM
# "x86_64-darwin" = "macos-14"; # - macos-14 is a 3 aarch64 vCPU / 7GB RAM (but it seems faster than the macos-13 one)
# "aarch64-darwin" = "macos-14";

# FlyCI-hosted runners:
"x86_64-darwin" = "flyci-macos-large-latest-m1";
"aarch64-darwin" = "flyci-macos-large-latest-m1";
};
# FlyCI-hosted runners:
"x86_64-darwin" = "flyci-macos-large-latest-m1";
"aarch64-darwin" = "flyci-macos-large-latest-m1";
};

inherit (import ./build-status.nix {inherit lib;}) getBuildStatus;
inherit (import ./build-status.nix { inherit lib; }) getBuildStatus;

allowedToFailMap = lib.pipe (mkGHActionsMatrix.include) [
(builtins.groupBy (p: p.package))
(builtins.mapAttrs (
n: v:
builtins.mapAttrs (
s: ps:
(builtins.head ps).allowedToFail
)
(builtins.groupBy (p: p.system) v)
))
];
allowedToFailMap = lib.pipe (mkGHActionsMatrix.include) [
(builtins.groupBy (p: p.package))
(builtins.mapAttrs (
n: v: builtins.mapAttrs (s: ps: (builtins.head ps).allowedToFail) (builtins.groupBy (p: p.system) v)
))
];

mkGHActionsMatrix = {
include = lib.pipe (builtins.attrNames nixSystemToGHPlatform) [
(builtins.concatMap
(
system: let
platform = nixSystemToGHPlatform.${system};
in
map (package: let
p = self.packages.${system}.${package};
in {
os = platform;
allowedToFail = !(p.passthru.buildStatus or (throw "${package} does not expose build status")).build;
inherit system package;
attrPath = "packages.${system}.${lib.strings.escapeNixIdentifier package}";
})
(builtins.attrNames self.packages.${system})
))
(builtins.sort (a: b:
if (a.package == b.package)
then a.os == "ubuntu-latest"
else a.package < b.package))
];
};
};
mkGHActionsMatrix = {
include = lib.pipe (builtins.attrNames nixSystemToGHPlatform) [
(builtins.concatMap (
system:
let
platform = nixSystemToGHPlatform.${system};
in
map (
package:
let
p = self.packages.${system}.${package};
in
{
os = platform;
allowedToFail =
!(p.passthru.buildStatus or (throw "${package} does not expose build status")).build;
inherit system package;
attrPath = "packages.${system}.${lib.strings.escapeNixIdentifier package}";
}
) (builtins.attrNames self.packages.${system})
))
(builtins.sort (
a: b: if (a.package == b.package) then a.os == "ubuntu-latest" else a.package < b.package
))
];
};
}
Loading