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

5 6 7 8 9 10 11 12 13
  # sometimes bun is broken because of better-sqlite3
  fix-bun = pkgs.writeShellScriptBin "fix-bun" ''
    #!/usr/bin/env bash
    set -e

    cd ./node_modules/better-sqlite3
    bun install
  '';
  
Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
14
  compile = pkgs.writeShellScriptBin "compile" ''
15
    #!/usr/bin/env bash
16 17
    set -e

18
    echo "Installing JS Dependencies"
19 20
    #yarn
    bun install
21
    bun install --dev
22

23
    echo "Compiling"
Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
24 25 26 27 28 29 30
    bun run build
  '';
  
  build = pkgs.writeShellScriptBin "build" ''
    #!/usr/bin/env bash
    set -e

31
    # 0.15
Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
32 33
    echo "Bundling"
    bun run bundle
34 35
  '';

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

    rm -rf ./output

    # 0.15
Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
43
    echo "Bundling"
44
    bun spago bundle --module Main --outfile dist/bundle.js --purs-args "--json-errors" | jq -r '.warnings | map(select(.errorCode | test("UnusedDctorExplicitImport|UnusedDctorImport|UnusedDeclaration|UnusedExplicitImport|UnusedImport|UnusedName|UnusedTypeVar"))) | map(select(.filename | test("^.spago") | not)) | map("[\(.filename)::\(.position.startLine)] \(.message)\n \(.suggestion)") | join("\n----------\n")'
45 46
  '';

47 48 49 50 51

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

52
    #yarn css
Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
53
    bun run css
54 55
  '';

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

60
    #yarn server
Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
61
    bun run server
62 63 64

  '';

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

    echo "Build watch"
70
    bun spago build -w --then browserify
71 72
  '';

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

77
    bun spago build --purs-args '--codegen corefn,js'
78
    zephyr -f Main.main
79
    browserify-zephyr
80 81
  '';

82 83 84 85
  minify-bundle = pkgs.writeShellScriptBin "minify-bundle" ''
    #!/usr/bin/env bash
    set -e

Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
86
    bun run minify
87 88
  '';

Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
89 90 91
  repl = pkgs.writeShellScriptBin "repl" ''
    #!/usr/bin/env bash

Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
92
    bun run repl
Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
93
  '';
94 95 96 97 98

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

Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
99 100
    compile

101
    echo "Testing"
Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
102
    bun run test
103
  '';
104
  
105 106 107
  # 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 {};
108 109 110
in
pkgs.mkShell {
  buildInputs = [
Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
111
    easy-ps.purs-0_15_15
112
    easy-ps.zephyr
113 114
    pkgs.ijq
    pkgs.jq
115
    #pkgs.esbuild
116
    pkgs.nodejs
117 118
    #pkgs.yarn
    pkgs.bun
Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
119
    pkgs.sqlite
Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
120 121 122 123 124 125 126

    # scripts
    build-css
    build-suggestions
    build-watch
    build-zephyr
    build
Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
127
    compile
128
    fix-bun
Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
129 130 131
    minify-bundle
    repl
    serve
132
    test-ps
133
  ];
134

Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
135 136 137
  #shellHook = ''
  #  export PURS_IDE_SOURCES='${toString purs-project.unquotedSourceGlobs}'
  #'';
138 139 140 141 142 143
}

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