flake.nix 4.24 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
{
  description = "Gargantext PureScript fronetnd";

  inputs.flake-utils.url = "github:numtide/flake-utils";

  # bun-1.1
  inputs.nixpkgs.url = "nixpkgs/860e65d27036476edfb85dd847d982277880b143";

  # bun-1.0
  #inputs.nixpkgs.url = "nixpkgs/23.11";

  inputs.purescript-overlay = {
    url = "github:thomashoneyman/purescript-overlay";
    inputs.nixpkgs.follows = "nixpkgs";
  };
  
  outputs = { self, nixpkgs, flake-utils, purescript-overlay }:
    flake-utils.lib.eachDefaultSystem (system:
      #let pkgs = nixpkgs.legacyPackages.${system};
      let
        pkgs = import nixpkgs {
          inherit system;
          overlays = [ purescript-overlay.overlays.default ];
        };

        dependencies = with pkgs; [
          purescript
28
          #spago-unstable
29
          nodejs
30
          nodePackages.npm
31 32 33 34 35 36 37
        ];
    
      serve = pkgs.writeShellScriptBin "serve" ''
        #!/usr/bin/env bash
        set -e
    
        #yarn server
Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
38
        npm run server
39 40 41 42 43 44 45 46
    
      '';
    
      build-watch = pkgs.writeShellScriptBin "build-watch" ''
        #!/usr/bin/env bash
        set -e
    
        echo "Build watch"
Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
47
        npm spago build -w --then browserify
48 49 50 51 52 53
      '';
    
      build-zephyr = pkgs.writeShellScriptBin "build-zephyr" ''
        #!/usr/bin/env bash
        set -e
    
Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
54
        npm spago build --purs-args '--codegen corefn,js'
55 56 57 58 59 60 61 62
        zephyr -f Main.main
        browserify-zephyr
      '';
    
      minify-bundle = pkgs.writeShellScriptBin "minify-bundle" ''
        #!/usr/bin/env bash
        set -e
    
Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
63
        npm run minify
64 65 66 67 68 69 70 71 72 73 74 75 76
      '';
    
      in
        {
          packages = {
            compile = pkgs.writeShellApplication {
              name = "compile";
              runtimeInputs = dependencies;
              text = ''
              #!${pkgs.stdenv.shell}
              set -e

              echo "Installing JS Dependencies"
77 78 79 80
              #${pkgs.nodePackages.npm}/bin/npm install
              # https://docs.npmjs.com/cli/v9/commands/npm-ci
              ${pkgs.nodePackages.npm}/bin/npm ci
              #${pkgs.nodePackages.npm}/bin/npm install --dev
81 82
          
              echo "Compiling"
83
              ${pkgs.nodePackages.npm}/bin/npm run build
84 85 86 87 88 89 90 91 92 93 94 95
              '';
            };
            build = pkgs.writeShellApplication {
              name = "build";
              runtimeInputs = dependencies;
              text = ''
              #!${pkgs.stdenv.shell}
              set -e

              ${self.packages.${system}.compile}/bin/compile

              echo "Bundling"
96
              ${pkgs.nodePackages.npm}/bin/npm run bundle              
97 98 99 100 101 102 103 104 105 106 107 108
              '';
            };
            test-ps = pkgs.writeShellApplication {
              name = "test-ps";
              runtimeInputs = dependencies;
              text = ''
              #!${pkgs.stdenv.shell}
              set -e
          
              ${self.packages.${system}.compile}/bin/compile
          
              echo "Testing"
109
              ${pkgs.nodePackages.npm}/bin/npm run test
110 111 112 113 114 115 116 117
            '';
            };    
            repl = pkgs.writeShellApplication {
              name = "repl";
              runtimeInputs = dependencies;
              text = ''
              #!${pkgs.stdenv.shell}
          
118
              ${pkgs.nodePackages.npm}/bin/npm run repl
119 120 121 122 123 124 125 126 127 128 129
            '';
            };
            
            build-css = pkgs.writeShellApplication {
              name = "build-css";
              runtimeInputs = dependencies;
              text = ''
              #!${pkgs.stdenv.shell}
              set -e
          
              #yarn css
130
              ${pkgs.nodePackages.npm}/bin/npm run css
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
            '';
            };
          };
          
          devShells.default = pkgs.mkShell {
            name = "purescript-gargantext";
            #inputsFrom = builtins.attrValues self.packages.${system};
            buildInputs = with pkgs; (dependencies ++ [
              # scripts
              self.packages.${system}.build
              self.packages.${system}.compile
              self.packages.${system}.test-ps
              self.packages.${system}.repl
              
              self.packages.${system}.build-css
              build-watch
              build-zephyr
              minify-bundle
              serve
            ]);
          };
        }
    );
}