shell.nix 3.48 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
    spago build
24
    echo "Bundling"
25
    #pulp browserify --skip-compile -t dist/bundle.js --src-path output
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 43 44 45
  serve = pkgs.writeShellScriptBin "serve" ''
    #!/usr/bin/env bash
    set -e

    yarn server

  '';

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

    echo "Build watch"
51
    spago build -w --then browserify
52 53
  '';

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

    spago build --purs-args '--codegen corefn,js'
    zephyr -f Main.main
60
    browserify-zephyr
61 62
  '';

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

67
    pulp browserify --skip-compile -t dist/bundle.js --src-path output
68
  '';
Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
69

70 71 72 73
  browserify-zephyr = pkgs.writeShellScriptBin "browserify-zephyr" ''
    #!/usr/bin/env bash
    set -e

74 75
    pulp browserify --skip-compile -t dist/bundle.js -o dce-output
    #purs bundle -o dist/bundle.js -m Main dce-output/**/*.js
76 77
  '';

78 79 80 81 82 83 84
  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
85 86 87
  repl = pkgs.writeShellScriptBin "repl" ''
    #!/usr/bin/env bash

88
    spago repl
Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
89
  '';
90 91 92 93 94 95

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

    echo "Compiling"
96 97 98
    yarn
    spago build
    #build-purs
99
    echo "Testing"
100
    spago test
101 102
    # pulp browserify --skip-compile -t dist/bundle.js --src-path output
    # pulp test --src-path output --test-path output
103
    #NODE_PATH=output node -e "require('Test.Main').main();"
104
  '';
105 106 107
in
pkgs.mkShell {
  buildInputs = [
108
    easy-ps.purs-0_14_7
109
    easy-ps.psc-package
110
    easy-ps.dhall-json-simple
111
    easy-ps.zephyr
112
    browserify
113
    browserify-zephyr
114
    build-css
115
    build-purs
116
    build-watch
117
    build-zephyr
118
    build
119
    minify-bundle
120
    pkgs.closurecompiler
121
    pkgs.minify
122
    pkgs.nodejs
123
    pkgs.python  # needed for msgpack etc
Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
124
    repl
125
    serve
126
    pkgs.pulp
127
    pkgs.spago
128
    pkgs.yarn
129
    test-ps
130
  ];
131 132 133 134

  shellHook = ''
    export PURS_IDE_SOURCES='${toString purs-project.unquotedSourceGlobs}'
  '';
135 136 137 138 139 140
}

## 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
141 142
# 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
143 144 145 146 147 148
#
# 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
#
149 150
# 1. run `nix/generate-packages-json.nix` to generate packages.json
# 2. run `nix/generate-purs-packages.nix` to generate purs-packages.nix