aboutsummaryrefslogtreecommitdiff
path: root/default.nix
blob: 1fddd9f7ab1cd04efc94259786ec875ce00fa443 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
{pkgs ? import (import ./nix/sources.nix).nixpkgs {}}:

let
  # get rid of implicit dependency on gcc & ghc
  stripLib = drv: pkgs.stdenv.mkDerivation {
    name = drv.name + "-without-lib";
    src = drv.outPath;
    buildPhase = ''
      mkdir -p $out
      cp -r $src/bin $out
    '';
    phases = [ "buildPhase" ];
  };
  defaultcards = pkgs.copyPathToStore ./cards.yaml;
  drvs = with pkgs; rec {

    # server derivation generated using cabal2nix
    uplcg-server =
      { mkDerivation, aeson, async, base, blaze-html, bytestring
      , elm-bridge, fast-logger, hashable, http-types, lens, lib, mtl
      , process, random, scotty, stm, template-haskell, text, time
      , unordered-containers, uuid, vector, vector-algorithms
      , vector-instances, vector-shuffling, wai, wai-extra
      , wai-websockets, warp, websockets, yaml }:

      mkDerivation {
        pname = "uplcg";
        version = "0.1.0";
        src = ./server;
        isLibrary = true;
        isExecutable = true;
        libraryHaskellDepends = [
          aeson async base blaze-html bytestring elm-bridge fast-logger
          hashable http-types lens mtl process random scotty stm
          template-haskell text time unordered-containers uuid vector
          vector-algorithms vector-instances vector-shuffling wai wai-extra
          wai-websockets warp websockets yaml
        ];
        executableHaskellDepends = [ base ];
        description = "Untitled PL Card Game";
        license = lib.licenses.bsd3;

        # TODO: get the actual version hash in here
        patchPhase = ''
          rm lib/Uplcg/Version.hs
          echo "module Uplcg.Version (version) where" > lib/Uplcg/Version.hs
          echo "version :: String" >> lib/Uplcg/Version.hs
          echo "version = \"nixpkgs-uplcg\"" >> lib/Uplcg/Version.hs
        '';
      };

  uplcg-client = { cards ? defaultcards, server}:
    stdenv.mkDerivation {
      name = "uplcg-client";
      src = ./client;

      buildInputs = [ elmPackages.elm ];

      buildPhase = elmPackages.fetchElmDeps {
        elmPackages = import ./client/elm-srcs.nix;
        elmVersion = "0.19.1";
        registryDat = ./client/registry.dat;
      };

      installPhase = ''
        mkdir -p $out/assets
        cp -r $src/* .
        ${server}/bin/uplcg-generate-elm-types > src/Messages.elm
        elm make src/Client.elm --optimize --output client.js
        cp client.js $out/assets
        cp style.css $out/assets
        cp ${cards} $out/assets/cards.yaml
      '';
    };
  };
in with pkgs.lib; rec {
  client = callPackageWith { inherit server; } drvs.uplcg-client {};
  server = stripLib (pkgs.haskellPackages.callPackage drvs.uplcg-server {});
}