shell.nix 3.57 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 24
    #spago build
    #echo "Bundling"
25
    #pulp browserify --skip-compile -t dist/bundle.js --src-path output
26 27 28 29
    #browserify

    # 0.15
    spago bundle-app --main Main --to dist/bundle.js
30 31
  '';

32 33 34 35 36 37 38 39 40

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

    yarn css

  '';

41 42 43 44 45 46 47 48
  serve = pkgs.writeShellScriptBin "serve" ''
    #!/usr/bin/env bash
    set -e

    yarn server

  '';

49 50 51 52 53
  build-watch = pkgs.writeShellScriptBin "build-watch" ''
    #!/usr/bin/env bash
    set -e

    echo "Build watch"
54
    spago build -w --then browserify
55 56
  '';

57 58 59 60 61 62
  build-zephyr = pkgs.writeShellScriptBin "build-zephyr" ''
    #!/usr/bin/env bash
    set -e

    spago build --purs-args '--codegen corefn,js'
    zephyr -f Main.main
63
    browserify-zephyr
64 65
  '';

66 67 68 69
  browserify = pkgs.writeShellScriptBin "browserify" ''
    #!/usr/bin/env bash
    set -e

70
    pulp browserify --skip-compile -t dist/bundle.js --src-path output
71
  '';
Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
72

73 74 75 76
  browserify-zephyr = pkgs.writeShellScriptBin "browserify-zephyr" ''
    #!/usr/bin/env bash
    set -e

77 78
    pulp browserify --skip-compile -t dist/bundle.js -o dce-output
    #purs bundle -o dist/bundle.js -m Main dce-output/**/*.js
79 80
  '';

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

91
    spago repl
Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
92
  '';
93 94 95 96 97 98

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

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

  shellHook = ''
    export PURS_IDE_SOURCES='${toString purs-project.unquotedSourceGlobs}'
  '';
139 140 141 142 143 144
}

## 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
145 146
# 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
147 148 149 150 151 152
#
# 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
#
153 154
# 1. run `nix/generate-packages-json.nix` to generate packages.json
# 2. run `nix/generate-purs-packages.nix` to generate purs-packages.nix