shell.nix 3.95 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
    yarn
100
    #spago build
101
    #build-purs
102
    echo "Testing"
103 104
    spago -v -x test.dhall test --main Test.Main
    # spago -x test.dhall bundle-app --main Test.Main --to dist/test-bundle.js --platform node
105 106
    # pulp browserify --skip-compile -t dist/bundle.js --src-path output
    # pulp test --src-path output --test-path output
107
    #NODE_PATH=output node -e "require('Test.Main').main();"
108
  '';
109 110 111 112

  # TODO: Remove this when nixpkgs is updated to newer version (23.05
  # has nodejs 20.2.1 and we need >= 20.3.1 for crypto to work)
  #nodejs_20_3_1 = pkgs.callPackage ./nix/nodejs-v20.nix {};
113 114 115
in
pkgs.mkShell {
  buildInputs = [
116
    easy-ps.purs-0_15_7
117
    easy-ps.psc-package
118
    easy-ps.dhall-json-simple
119
    easy-ps.zephyr
120
    browserify
121
    browserify-zephyr
122
    build-css
123
    build-purs
124
    build-watch
125
    build-zephyr
126
    build
127
    minify-bundle
128 129
    #pkgs.closurecompiler
    pkgs.esbuild
130
    pkgs.minify
131
    pkgs.nodejs
132
    #pkgs.nodePackages.purescript-language-server
133
    #pkgs.python  # needed for msgpack etc
134
    #nodejs_20_3_1
Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
135
    repl
136
    serve
137
    pkgs.pulp
138
    pkgs.spago
139
    pkgs.yarn
140
    test-ps
141
  ];
142 143 144 145

  shellHook = ''
    export PURS_IDE_SOURCES='${toString purs-project.unquotedSourceGlobs}'
  '';
146 147 148 149 150 151
}

## 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
152 153
# 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
154 155 156 157 158 159
#
# 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
#
160 161
# 1. run `nix/generate-packages-json.nix` to generate packages.json
# 2. run `nix/generate-purs-packages.nix` to generate purs-packages.nix