shell.nix 2.7 KB
Newer Older
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
{ pkgs ? import ./pinned.nix {} }:
let
  easy-ps = import (
    pkgs.fetchFromGitHub {
      owner = "justinwoo";
      repo = "easy-purescript-nix";
      rev = "14e7d85431e9f9838d7107d18cb79c7fa534f54e";
      sha256 = "0lmkppidmhnayv0919990ifdd61f9d23dzjzr8amz7hjgc74yxs0";
    }
  ) {
    inherit pkgs;
  };

  soba = import (
    pkgs.fetchFromGitHub {
      owner = "justinwoo";
      repo = "soba";
      rev = "2add8804bce7e7c1ab5eb1c3d8f6783e938a04d3";
      sha256 = "1qagyklcllr2sxdb315prw33af6g37762zgk2ahh3ifxpns6ifxx";
    }
  ) {
    inherit pkgs;
  };

  purs-packages = import ./purs-packages.nix { inherit pkgs; };

  cpPackage = pp:
    let
      target = ".psc-package/local/${pp.name}/${pp.version}";
    in
      ''
        mkdir -p ${target}
        cp --no-preserve=mode,ownership,timestamp -r ${pp.fetched.outPath}/* ${target}
      '';

  install-purs-packages = pkgs.writeShellScriptBin "install-purs-packages" ''
    #!/usr/bin/env bash
    ${builtins.toString (builtins.map cpPackage (builtins.attrValues purs-packages))}
    echo done installing deps.
  '';

  build-purs = pkgs.writeShellScriptBin "build-purs" ''
    #!/usr/bin/env bash
    purs compile "src/**/*.purs" ".psc-package/*/*/*/src/**/*.purs"
  '';

  storePath = x: ''"${x.fetched.outPath}/src/**/*.purs"'';

  build-purs-from-store = pkgs.writeShellScriptBin "build-purs-from-store" ''
    #!/usr/bin/env bash
    purs compile "src/**/*.purs" \
      ${builtins.toString (builtins.map storePath (builtins.attrValues purs-packages))}
  '';
54 55 56

  build = pkgs.writeShellScriptBin "build" ''
    #!/usr/bin/env bash
57 58
    set -e

59 60 61 62 63
    echo "Compiling"
    build-purs-from-store
    echo "Bundling"
    yarn pulp browserify --skip-compile -t dist/bundle.js --src-path output
  '';
Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
64 65 66 67 68 69

  repl = pkgs.writeShellScriptBin "repl" ''
    #!/usr/bin/env bash

    yarn pulp repl
  '';
70 71 72 73 74 75 76 77 78
in
pkgs.mkShell {
  buildInputs = [
    easy-ps.purs
    easy-ps.psc-package
    soba
    install-purs-packages
    build-purs
    build-purs-from-store
79
    build
Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
80
    repl
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
    pkgs.yarn
  ];
}

## how to build the project with nix dependencies:
#
# 1. start a nix shell (e.g. `nix-shell -j 20`, this uses 20 jobs to fetch deps)
# 2. run `yarn` to install npm deps
# 3. run `install-purs-packages` if you want dependencies locally, available for psc-package and for inspection
# 4. run `build-purs` to build from local sources. otherwise use `build-purs-from-store`.
#
# note that the purescript compiler uses filepaths and timestamps, so using the above two commands
# interchangeably will lead to constant rebuilding of the entire project.
#
## how to update purs-packages.nix
#
# 1. run `soba insdhall` to generate packages.json
# 2. run `soba nix` to generate a nix derivation from packages.json