tools for building gleam projects with nix
at javascript 153 lines 4.5 kB view raw
1# SPDX-FileCopyrightText: 2025 Ruby Iris Juric <ruby@srxl.me> 2# 3# SPDX-License-Identifier: 0BSD 4 5{ 6 inputs = { 7 nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; 8 9 fenix.url = "github:nix-community/fenix"; 10 fenix.inputs.nixpkgs.follows = "nixpkgs"; 11 12 flake-compat.url = "https://git.lix.systems/lix-project/flake-compat/archive/main.tar.gz"; 13 flake-compat.flake = false; 14 15 git-hooks.url = "github:cachix/git-hooks.nix"; 16 git-hooks.inputs.nixpkgs.follows = "nixpkgs"; 17 18 treefmt-nix.url = "github:numtide/treefmt-nix"; 19 treefmt-nix.inputs.nixpkgs.follows = "nixpkgs"; 20 }; 21 22 outputs = 23 { 24 self, 25 nixpkgs, 26 fenix, 27 git-hooks, 28 treefmt-nix, 29 ... 30 }: 31 let 32 forEachSystem = 33 fn: 34 nixpkgs.lib.genAttrs [ 35 "x86_64-linux" 36 "aarch64-linux" 37 "aarch64-darwin" 38 ] (system: fn system nixpkgs.legacyPackages.${system}); 39 in 40 { 41 packages = forEachSystem ( 42 system: pkgs: { 43 gleam2nix = pkgs.callPackage ./nix/gleam2nix.nix { 44 inherit (self.packages.${system}) rust-toolchain; 45 }; 46 gleam-tool = pkgs.callPackage ./nix/gleam-tool.nix { 47 inherit (self.packages.${system}) rust-toolchain; 48 }; 49 gleamJavascriptPrelude = pkgs.callPackage ./nix/gleam-javascript-prelude.nix { }; 50 51 docs = pkgs.callPackage ./nix/docs.nix { }; 52 rust-toolchain = import ./nix/rust-toolchain.nix { 53 inherit (fenix.packages.${system}) fromToolchainFile; 54 }; 55 treefmt = 56 (treefmt-nix.lib.evalModule pkgs { 57 programs = { 58 nixfmt.enable = true; 59 nixfmt.excludes = [ "nix/Cargo.nix" ]; 60 61 prettier.enable = true; 62 prettier.excludes = [ "docs/pnpm-lock.yaml" ]; 63 64 rustfmt.enable = true; 65 rustfmt.package = self.packages.${system}.rust-toolchain; 66 67 taplo.enable = true; 68 }; 69 }).config.build.wrapper; 70 } 71 ); 72 73 lib = forEachSystem ( 74 system: pkgs: { 75 buildGleam = pkgs.callPackage ./nix/build-gleam.nix { 76 inherit (self.packages.${system}) gleam-tool gleamJavascriptPrelude; 77 }; 78 buildGleamApplication = pkgs.callPackage ./nix/build-gleam-application.nix { 79 inherit (self.lib.${system}) buildGleam; 80 inherit (self.packages.${system}) gleam-tool; 81 }; 82 } 83 ); 84 85 overlays = { 86 default = self.overlays.gleam2nix; 87 88 gleam2nix = import ./nix/overlay.nix; 89 fenix = fenix.overlays.default; 90 }; 91 92 devShells = forEachSystem ( 93 system: pkgs: { 94 default = pkgs.mkShell { 95 name = "gleam2nix-devshell"; 96 packages = with pkgs; [ 97 nix-output-monitor 98 nix-prefetch-git 99 nixd 100 nixfmt 101 102 crate2nix 103 self.packages.${system}.rust-toolchain 104 105 astro-language-server 106 pnpm 107 nodejs 108 typescript 109 typescript-language-server 110 vscode-langservers-extracted 111 112 self.packages.${system}.treefmt 113 reuse 114 ]; 115 116 env.RUST_SRC_PATH = "${self.packages.${system}.rust-toolchain}/lib/rustlib/src/rust/library"; 117 118 shellHook = self.checks.${system}.git-hooks.shellHook; 119 }; 120 } 121 ); 122 123 checks = forEachSystem ( 124 system: pkgs: { 125 git-hooks = git-hooks.lib.${system}.run { 126 src = ./.; 127 hooks = { 128 clippy.enable = true; 129 clippy.packageOverrides = { 130 cargo = self.packages.${system}.rust-toolchain; 131 clippy = self.packages.${system}.rust-toolchain; 132 }; 133 134 regen-rust-lib = { 135 enable = true; 136 name = "Regen Cargo.nix"; 137 entry = "${pkgs.lib.getExe pkgs.crate2nix} generate -o nix/Cargo.nix"; 138 files = "Cargo\\.(lock|toml)"; 139 pass_filenames = false; 140 }; 141 142 reuse.enable = true; 143 144 treefmt.enable = true; 145 treefmt.package = self.packages.${system}.treefmt; 146 }; 147 }; 148 } 149 ); 150 151 formatter = forEachSystem (system: _: self.packages.${system}.treefmt); 152 }; 153}