summaryrefslogtreecommitdiffhomepage
path: root/dlang/flake.nix
blob: d3923f07c60d42103f9a122a904a7d68f5853fcd (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
{
  description = "ocda-write: sample writers over the object-centric document abstraction, in D";

  inputs.nixpkgs.url = "https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.zst";

  /* The library this is built on, as a source tree rather than a flake: the
     build compiles its modules alongside these, which is what a dub path
     dependency does and avoids a second build product for a library of five
     modules.

     flake.lock pins the commit of the library this writer was built and
     checked against. To build against a working copy of it instead:

       nix build --override-input ocda-lib path:../../sisudoc-ocda-lib
  */
  inputs.ocda-lib = {
    url = "git+git://git.sisudoc.org/tools/sisudoc-ocda-lib";
    flake = false;
  };

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

      mkWrite = { compiler, compilerBin }: pkgs.stdenv.mkDerivation {
        pname = "ocda-write";
        version = "2.0.0";
        src = self;
        nativeBuildInputs = [ compiler ];
        buildInputs = [ pkgs.sqlite pkgs.zstd ];
        buildPhase = ''
          runHook preBuild
          export HOME=$TMPDIR
          ${compilerBin} -I=src -I=${ocda-lib}/dlang/src -of=ocda-write \
            ${ocda-lib}/dlang/src/ocda/*.d src/write/*.d src/main.d \
            -L-lsqlite3 -L-lzstd
          runHook postBuild
        '';
        installPhase = ''
          runHook preInstall
          mkdir -p $out/bin
          install -m755 ocda-write $out/bin/ocda-write
          runHook postInstall
        '';
        meta = {
          description = "writes a document out from either serialisation of its abstraction";
          mainProgram = "ocda-write";
        };
      };
    in {
      packages.${system} = {
        default = self.packages.${system}.ocda-write;
        ocda-write     = mkWrite { compiler = pkgs.ldc; compilerBin = "ldmd2"; };
        ocda-write-dmd = mkWrite { compiler = pkgs.dmd; compilerBin = "dmd"; };
      };

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