# SPDX-FileCopyrightText: 2025 Ruby Iris Juric # # SPDX-License-Identifier: 0BSD { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; fenix.url = "github:nix-community/fenix"; fenix.inputs.nixpkgs.follows = "nixpkgs"; flake-compat.url = "https://git.lix.systems/lix-project/flake-compat/archive/main.tar.gz"; flake-compat.flake = false; git-hooks.url = "github:cachix/git-hooks.nix"; git-hooks.inputs.nixpkgs.follows = "nixpkgs"; treefmt-nix.url = "github:numtide/treefmt-nix"; treefmt-nix.inputs.nixpkgs.follows = "nixpkgs"; }; outputs = { self, nixpkgs, fenix, git-hooks, treefmt-nix, ... }: let forEachSystem = fn: nixpkgs.lib.genAttrs [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" ] (system: fn system nixpkgs.legacyPackages.${system}); in { packages = forEachSystem ( system: pkgs: { gleam2nix = pkgs.callPackage ./nix/gleam2nix.nix { inherit (self.packages.${system}) rust-toolchain; }; gleam-tool = pkgs.callPackage ./nix/gleam-tool.nix { inherit (self.packages.${system}) rust-toolchain; }; gleamJavascriptPrelude = pkgs.callPackage ./nix/gleam-javascript-prelude.nix { }; docs = pkgs.callPackage ./nix/docs.nix { }; rust-toolchain = import ./nix/rust-toolchain.nix { inherit (fenix.packages.${system}) fromToolchainFile; }; treefmt = (treefmt-nix.lib.evalModule pkgs { programs = { nixfmt.enable = true; nixfmt.excludes = [ "nix/Cargo.nix" ]; prettier.enable = true; prettier.excludes = [ "docs/pnpm-lock.yaml" ]; rustfmt.enable = true; rustfmt.package = self.packages.${system}.rust-toolchain; taplo.enable = true; }; }).config.build.wrapper; } ); lib = forEachSystem ( system: pkgs: { buildGleam = pkgs.callPackage ./nix/build-gleam.nix { inherit (self.packages.${system}) gleam-tool gleamJavascriptPrelude; }; buildGleamApplication = pkgs.callPackage ./nix/build-gleam-application.nix { inherit (self.lib.${system}) buildGleam; inherit (self.packages.${system}) gleam-tool; }; } ); overlays = { default = self.overlays.gleam2nix; gleam2nix = import ./nix/overlay.nix; fenix = fenix.overlays.default; }; devShells = forEachSystem ( system: pkgs: { default = pkgs.mkShell { name = "gleam2nix-devshell"; packages = with pkgs; [ nix-output-monitor nix-prefetch-git nixd nixfmt crate2nix self.packages.${system}.rust-toolchain astro-language-server pnpm nodejs typescript typescript-language-server vscode-langservers-extracted self.packages.${system}.treefmt reuse ]; env.RUST_SRC_PATH = "${self.packages.${system}.rust-toolchain}/lib/rustlib/src/rust/library"; shellHook = self.checks.${system}.git-hooks.shellHook; }; } ); checks = forEachSystem ( system: pkgs: { git-hooks = git-hooks.lib.${system}.run { src = ./.; hooks = { clippy.enable = true; clippy.packageOverrides = { cargo = self.packages.${system}.rust-toolchain; clippy = self.packages.${system}.rust-toolchain; }; regen-rust-lib = { enable = true; name = "Regen Cargo.nix"; entry = "${pkgs.lib.getExe pkgs.crate2nix} generate -o nix/Cargo.nix"; files = "Cargo\\.(lock|toml)"; pass_filenames = false; }; reuse.enable = true; treefmt.enable = true; treefmt.package = self.packages.${system}.treefmt; }; }; } ); formatter = forEachSystem (system: _: self.packages.${system}.treefmt); }; }