/ flake.nix
flake.nix
  1  # SPDX-FileCopyrightText: 2024 Mass Labs
  2  #
  3  # SPDX-License-Identifier: Unlicense
  4  {
  5    description = "MassMarket Typescript Packages";
  6    inputs = {
  7      nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
  8      systems.url = "github:nix-systems/default";
  9      flake-parts.url = "github:hercules-ci/flake-parts";
 10      flake-root.url = "github:srid/flake-root";
 11      pre-commit-hooks = {
 12        url = "github:cachix/git-hooks.nix";
 13        inputs.nixpkgs.follows = "nixpkgs";
 14      };
 15  
 16      relay.url = "github:masslbs/relay";
 17      contracts.follows = "relay/contracts";
 18      schema.follows = "relay/schema";
 19      # in case we need to test new vectors, etc. we can override the input like this:
 20      # schema.url = "github:masslbs/network-schema/myBranch
 21    };
 22  
 23    outputs = inputs @ {
 24      nixpkgs,
 25      flake-parts,
 26      schema,
 27      contracts,
 28      pre-commit-hooks,
 29      relay,
 30      self,
 31      systems,
 32      ...
 33    }:
 34      flake-parts.lib.mkFlake {inherit inputs;} {
 35        systems = import systems;
 36        imports = [
 37          inputs.pre-commit-hooks.flakeModule
 38          inputs.flake-root.flakeModule
 39        ];
 40        perSystem = {
 41          config,
 42          pkgs,
 43          system,
 44          ...
 45        }: {
 46          pre-commit = {
 47            check.enable = true;
 48            settings = {
 49              src = ./.;
 50              hooks = {
 51                alejandra.enable = true;
 52                typos = {
 53                  # this tell typos not to check excluded files even if pre-commit tell typos to check them
 54                  args = ["--force-exclude"];
 55                  enable = true;
 56                  settings = {
 57                    configPath = "./typos.toml";
 58                  };
 59                };
 60                #TODO: tries to download modules on nix flake check
 61                denolint = {
 62                  enable = true;
 63                  settings.configPath = "./deno.json";
 64                };
 65                denofmt = {
 66                  enable = true;
 67                  settings.configPath = "./deno.json";
 68                };
 69              };
 70            };
 71          };
 72          devShells.default = pkgs.mkShell {
 73            inputsFrom = [config.flake-root.devShell]; # Provides $FLAKE_ROOT in dev shell
 74            MASS_TEST_VECTORS = "${schema.packages.${system}.default}";
 75            NETWORK_SCHEMA_PATH = "${schema}";
 76            MASS_CONTRACTS_PATH = "${contracts.packages.${system}.default}";
 77  
 78            shellHook = ''
 79              ${config.pre-commit.settings.installationScript}
 80              export IPFS_PATH=$FLAKE_ROOT/data/ipfs
 81              pushd $FLAKE_ROOT
 82              # only runs when the contracts have changed
 83              touch .last-input
 84              if [[ "$(< .last-input)" != "${contracts}" ]]; then
 85                echo ${contracts} > .last-input
 86                deno task -r -f contracts build
 87              fi
 88              popd
 89            '';
 90  
 91            buildInputs = with pkgs;
 92              [
 93                relay.packages.${system}.local-testnet
 94                nodejs # needed for protobuf generation
 95                reuse
 96                # Language servers
 97                typos-lsp # code spell checker
 98                nixd
 99              ]
100              # deno is automatically pulled in here
101              ++ config.pre-commit.settings.enabledPackages;
102          };
103        };
104      };
105  }