shell.nix 3.23 KB
Newer Older
1
{ pkgs ? import ./nix/pinned.nix {} }:
2
let
3
  easy-ps = import ./nix/easy-ps.nix { inherit pkgs; };
4 5 6

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

7
  purs-project = import ./nix/purs-project.nix { inherit pkgs; };
8 9 10

  build-purs = pkgs.writeShellScriptBin "build-purs" ''
    #!/usr/bin/env bash
11
    purs compile ${toString purs-project.sourceGlobs} "src/**/*.purs" "test/**/*.purs"
12
  '';
13 14 15

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

18 19 20
    echo "Installing JS Dependencies"
    yarn

21
    echo "Compiling"
22
    #build-purs
23
    echo "Bundling"
24 25
    #pulp browserify --skip-compile -t dist/bundle.js --src-path output
    spago build
26 27 28
    browserify
  '';

29 30 31 32 33 34 35 36 37

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

    yarn css

  '';

38 39 40 41 42
  build-watch = pkgs.writeShellScriptBin "build-watch" ''
    #!/usr/bin/env bash
    set -e

    echo "Build watch"
43
    spago build -w --then browserify
44 45
  '';

46 47 48 49 50 51
  build-zephyr = pkgs.writeShellScriptBin "build-zephyr" ''
    #!/usr/bin/env bash
    set -e

    spago build --purs-args '--codegen corefn,js'
    zephyr -f Main.main
52
    browserify-zephyr
53 54
  '';

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

59
    pulp browserify --skip-compile -t dist/bundle.js --src-path output
60
  '';
Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
61

62 63 64 65 66 67 68
  browserify-zephyr = pkgs.writeShellScriptBin "browserify-zephyr" ''
    #!/usr/bin/env bash
    set -e

    pulp browserify --skip-compile -t dist/bundle.js --src-path dce-output
  '';

69 70 71 72 73 74 75
  minify-bundle = pkgs.writeShellScriptBin "minify-bundle" ''
    #!/usr/bin/env bash
    set -e

    minify dist/bundle.js > dist/bundle.min.js
  '';

Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
76 77 78
  repl = pkgs.writeShellScriptBin "repl" ''
    #!/usr/bin/env bash

79
    spago repl
Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
80
  '';
81 82 83 84 85 86 87 88

  test-ps = pkgs.writeShellScriptBin "test-ps" ''
    #!/usr/bin/env bash
    set -e

    echo "Compiling"
    build-purs
    echo "Testing"
89 90
    # pulp browserify --skip-compile -t dist/bundle.js --src-path output
    # pulp test --src-path output --test-path output
91
    NODE_PATH=output node -e "require('Test.Main').main();"
92
  '';
93 94 95
in
pkgs.mkShell {
  buildInputs = [
96
    easy-ps.purs-0_14_4
97
    easy-ps.psc-package
98
    easy-ps.dhall-json-simple
99
    easy-ps.zephyr
100
    browserify
101
    browserify-zephyr
102
    build-css
103
    build-purs
104
    build-watch
105
    build-zephyr
106
    build
107
    minify-bundle
108
    pkgs.closurecompiler
109
    pkgs.minify
110
    pkgs.nodejs
Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
111
    repl
112
    pkgs.pulp
113
    pkgs.spago
114
    pkgs.yarn
115
    test-ps
116
  ];
117 118 119 120

  shellHook = ''
    export PURS_IDE_SOURCES='${toString purs-project.unquotedSourceGlobs}'
  '';
121 122 123 124 125 126
}

## 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
127 128
# 3a. run `build-purs` to build using nix store dependencies, and make sure to update your purescript ide tooling as necesssary
# 3b. or simply use `psc-package` as you might want to anyway
129 130 131 132 133 134
#
# 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
#
135 136
# 1. run `nix/generate-packages-json.nix` to generate packages.json
# 2. run `nix/generate-purs-packages.nix` to generate purs-packages.nix