euph 0.3.2

A functional stack-based programming language
{
  description = "";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    flake-parts.url = "github:hercules-ci/flake-parts";
    fenix = {
      url = "github:nix-community/fenix";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    crane.url = "github:ipetkov/crane";
    treefmt-nix.url = "github:numtide/treefmt-nix";
  };

  outputs =
    inputs@{ flake-parts, ... }:
    flake-parts.lib.mkFlake { inherit inputs; } {
      systems = inputs.nixpkgs.lib.systems.flakeExposed;
      imports = [ inputs.treefmt-nix.flakeModule ];
      perSystem =
        { inputs', pkgs, ... }:

        let
          inherit (pkgs) lib;

          baseCraneLib =
            cs:
            (inputs.crane.mkLib pkgs).overrideToolchain (
              inputs'.fenix.packages.combine (
                with inputs'.fenix.packages;
                [
                  minimal.rustc
                  minimal.cargo
                  complete.clippy
                  complete.rustfmt
                  targets.wasm32-wasip2.latest.rust-std
                ]
                ++ cs
              )
            );
          craneLib = baseCraneLib [ ];
          craneLibDev = baseCraneLib (
            with inputs'.fenix.packages.complete;
            [
              rust-analyzer
              rust-src
            ]
          );

          cranePkg =
            o@{
              cargoTest ? false,
              ...
            }:
            craneLib.buildPackage (
              {
                src = lib.cleanSourceWith {
                  src = ./.;
                  filter =
                    path: type: (builtins.match ".*wit$" path != null) || (craneLib.filterCargoSources path type);
                };
                checkPhaseCargoCommand = "cargo fmt --check && cargo clippy ${
                  if cargoTest then "&& cargo test" else ""
                }";
                nativeBuildInputs = with pkgs; [ mold ];
              }
              // o
            );
        in
        {

          packages = {
            default = cranePkg {
              cargoTest = true;
            };

            wasm = cranePkg {
              CARGO_BUILD_TARGET = "wasm32-wasip2";
            };
          };

          devShells = {
            default = pkgs.mkShell {
              packages = with pkgs; [
                taplo
                yamlfmt
                actionlint
                mold
                cargo-edit
                bacon
              ];

              inputsFrom = [ (craneLibDev.devShell { }) ];
            };

            web = pkgs.mkShell {
              packages = with pkgs; [
                nodejs_latest
                pnpm
                dprint
                eslint
                vscode-langservers-extracted
                vtsls
                svelte-language-server
                emmet-language-server
                tailwindcss-language-server
                nixfmt
                statix
                deadnix
              ];
            };
          };

          treefmt = {
            projectRootFile = "flake.nix";
            programs = {
              nixfmt.enable = true;
              statix.enable = true;
              deadnix.enable = true;
              rustfmt = {
                enable = true;
                package = craneLibDev.rustfmt;
              };
              yamlfmt = {
                enable = true;
                excludes = [ "*-lock.yaml" ];
              };
              actionlint.enable = true;
              taplo.enable = true;
              dprint = {
                enable = true;
                includes = [ "web" ];
              };
            };
          };
        };
    };
}