summaryrefslogtreecommitdiffhomepage
path: root/dlang/flake.nix
blob: 554b8e00e4a161ddf7a44237077e7876ce0378b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
{
  description = "ssp-reader: a reader for the .ssp document abstraction, in D";

  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";

  outputs = { self, nixpkgs }:
    let
      system = "x86_64-linux"; # adjust for aarch64-linux / darwin
      pkgs = import nixpkgs { inherit system; };

      name = "ssp-reader";

      /* The reader has no dependencies beyond phobos, so there is nothing
         to vendor and nothing to fetch: --skip-registry=all keeps dub from
         reaching for a registry it does not need, which is also what lets
         this build in a sandbox without network.
      */
      mkReader = { compiler, compilerBin }: pkgs.stdenv.mkDerivation {
        pname = name;
        version = "2.0.0";
        src = self;
        nativeBuildInputs = [ pkgs.dub compiler ];
        buildPhase = ''
          runHook preBuild
          export HOME=$TMPDIR
          dub build \
            --cache=local \
            --compiler=$(type -P ${compilerBin}) \
            --build=release \
            --skip-registry=all
          runHook postBuild
        '';
        installPhase = ''
          runHook preInstall
          mkdir -p $out/bin
          install -m755 bin/${name} $out/bin/${name}
          runHook postInstall
        '';
        meta = {
          description = "reads a .ssp document abstraction and says what is in it";
          mainProgram = name;
        };
      };
    in {
      packages.${system} = {
        default = self.packages.${system}.ssp-reader-ldc;

        ssp-reader-ldc = mkReader {
          compiler = pkgs.ldc;
          compilerBin = "ldmd2";
        };

        /* dmd is given gcc14: GCC 15 introduced nullptr in its headers and
           dmd's ImportC parser does not yet handle it. The same override
           sisudoc-spine carries, for the same reason.
        */
        ssp-reader-dmd = mkReader {
          compiler = pkgs.dmd.override { stdenv = pkgs.gcc14Stdenv; };
          compilerBin = "dmd";
        };
      };

      devShells.${system}.default = pkgs.mkShell {
        packages = [ pkgs.ldc pkgs.dub pkgs.dtools ];
      };
    };
}