diff --git a/default.nix b/default.nix index 2493deea..8dfe7162 100644 --- a/default.nix +++ b/default.nix @@ -68,7 +68,7 @@ let craneLibWasm = craneLib.overrideToolchain rustWithWasmTarget; in { - passtru = { + passthru = { inherit craneLibWasm; }; diff --git a/flake.lock b/flake.lock index b196a67f..0e645f9a 100644 --- a/flake.lock +++ b/flake.lock @@ -90,10 +90,9 @@ "inputs": { "advisory-db": "advisory-db", "crane": "crane", - "flake-utils": "flake-utils", "nixpkgs": "nixpkgs", "rust-overlay": "rust-overlay", - "tree-sitter-nickel-input": "tree-sitter-nickel-input" + "tree-sitter-nickel": "tree-sitter-nickel" } }, "rust-overlay": { @@ -129,11 +128,9 @@ "type": "github" } }, - "tree-sitter-nickel-input": { + "tree-sitter-nickel": { "inputs": { - "flake-utils": [ - "flake-utils" - ], + "flake-utils": "flake-utils", "nixpkgs": [ "nixpkgs" ] diff --git a/flake.nix b/flake.nix index 5f64abc8..f3493874 100644 --- a/flake.nix +++ b/flake.nix @@ -25,21 +25,52 @@ flake = false; }; - flake-utils.url = "github:numtide/flake-utils"; - - tree-sitter-nickel-input = { + tree-sitter-nickel = { url = "github:nickel-lang/tree-sitter-nickel"; inputs.nixpkgs.follows = "nixpkgs"; - inputs.flake-utils.follows = "flake-utils"; }; }; - outputs = inputs: - with inputs; - flake-utils.lib.eachDefaultSystem ( - system: - let - wasm-bindgen-cli-overlay = final: prev: + outputs = { self, nixpkgs, ... }@inputs: + let + supportedSystems = nixpkgs.lib.systems.flakeExposed; + + pkgsFor = nixpkgs.lib.genAttrs supportedSystems (system: rec { + pkgs = import nixpkgs { + inherit system; + overlays = [ + self.overlays.tree-sitter-grammars + self.overlays.wasm-bindgen-cli + inputs.rust-overlay.overlays.default + ]; + }; + + topiaryPkgs = pkgs.callPackage ./default.nix { + inherit (inputs) advisory-db crane rust-overlay; + inherit (pkgs.tree-sitter-grammars) tree-sitter-nickel; + craneLib = inputs.crane.mkLib pkgs; + }; + + binPkgs = pkgs.callPackage ./bin/default.nix { }; + }); + + forAllSystems = fn: nixpkgs.lib.genAttrs supportedSystems (system: fn rec { + inherit system; + inherit (pkgsFor.${system}) pkgs topiaryPkgs binPkgs; + inherit (pkgs) lib; + craneLib = inputs.crane.mkLib pkgs; + }); + in + { + overlays = { + tree-sitter-grammars = final: prev: { + # Nickel *should* have an overlay like this already + tree-sitter-grammars = prev.tree-sitter-grammars // { + tree-sitter-nickel = inputs.tree-sitter-nickel.packages.${prev.system}.default; + }; + }; + + wasm-bindgen-cli = final: prev: let cargoLock = builtins.fromTOML (builtins.readFile ./Cargo.lock); wasmBindgenCargoVersions = builtins.map ({ version, ... }: version) (builtins.filter ({ name, ... }: name == "wasm-bindgen") cargoLock.package); @@ -52,74 +83,63 @@ cargoHash = "sha256-3vxVI0BhNz/9m59b+P2YEIrwGwlp7K3pyPKt4VqQuHE="; }; }; - - pkgs = import nixpkgs { - inherit system; - overlays = [ rust-overlay.overlays.default wasm-bindgen-cli-overlay ]; - }; - - craneLib = crane.mkLib pkgs; - - tree-sitter-nickel = tree-sitter-nickel-input.packages.${system}.default; - - topiaryPkgs = pkgs.callPackage ./default.nix { - inherit advisory-db crane rust-overlay craneLib tree-sitter-nickel; - }; - binPkgs = pkgs.callPackage ./bin/default.nix { }; - in - { - packages = rec { - inherit (topiaryPkgs) - topiary-playground - topiary-queries - client-app; - - topiary-cli = topiaryPkgs.topiary-cli { }; - topiary-cli-nix = topiaryPkgs.topiary-cli { nixSupport = true; }; - - inherit (binPkgs) - # FIXME: Broken - # generate-coverage - playground - update-wasm-app - update-wasm-grammars - verify-documented-usage; - - default = topiary-cli; - }; - - checks = { - inherit (topiaryPkgs) clippy clippy-wasm fmt topiary-core topiary-playground audit benchmark; - topiary-cli = topiaryPkgs.topiary-cli { }; - - ## Check that the `lib.pre-commit-hook` output builds/evaluates - ## correctly. `deepSeq e1 e2` evaluates `e1` strictly in depth before - ## returning `e2`. We use this trick because checks need to be - ## derivations, which `lib.pre-commit-hook` is not. - pre-commit-hook = builtins.deepSeq self.lib.${system}.pre-commit-hook pkgs.hello; - }; - - devShells = - let - checksLight = { + }; + + packages = forAllSystems ({ system, pkgs, topiaryPkgs, binPkgs, ... }: { + inherit (topiaryPkgs) + topiary-playground + topiary-queries + client-app; + + topiary-cli = topiaryPkgs.topiary-cli { }; + topiary-cli-nix = topiaryPkgs.topiary-cli { nixSupport = true; }; + + inherit (binPkgs) + # FIXME: Broken + # generate-coverage + playground + update-wasm-app + update-wasm-grammars + verify-documented-usage; + + default = self.packages.${system}.topiary-cli; + }); + + checks = forAllSystems ({ system, pkgs, topiaryPkgs, ... }: { + inherit (topiaryPkgs) clippy clippy-wasm fmt topiary-core topiary-playground audit benchmark; + topiary-cli = self.packages.${system}.topiary-cli; + + ## Check that the `lib.pre-commit-hook` output builds/evaluates + ## correctly. `deepSeq e1 e2` evaluates `e1` strictly in depth before + ## returning `e2`. We use this trick because checks need to be + ## derivations, which `lib.pre-commit-hook` is not. + pre-commit-hook = builtins.deepSeq self.lib.${system}.pre-commit-hook pkgs.hello; + }); + + devShells = forAllSystems ({ system, pkgs, craneLib, topiaryPkgs, binPkgs, ... }: + { + default = pkgs.callPackage ./shell.nix { checks = self.checks.${system}; inherit craneLib; inherit binPkgs; }; + light = pkgs.callPackage ./shell.nix { + checks = /* checksLight */ { inherit (topiaryPkgs) clippy fmt topiary-core; - topiary-cli = topiaryPkgs.topiary-cli { }; + topiary-cli = self.packages.${system}.topiary-cli; }; - in - { - default = pkgs.callPackage ./shell.nix { checks = self.checks.${system}; inherit craneLib; inherit binPkgs; }; - light = pkgs.callPackage ./shell.nix { checks = checksLight; inherit craneLib; inherit binPkgs; optionals = false; }; - wasm = pkgs.callPackage ./shell.nix { checks = self.checks.${system}; craneLib = topiaryPkgs.passtru.craneLibWasm; inherit binPkgs; }; + inherit craneLib; + inherit binPkgs; + optionals = false; }; + wasm = pkgs.callPackage ./shell.nix { checks = self.checks.${system}; craneLib = topiaryPkgs.passthru.craneLibWasm; inherit binPkgs; }; + }); - ## For easy use in https://github.com/cachix/pre-commit-hooks.nix - lib.pre-commit-hook = { + ## For easy use in https://github.com/cachix/pre-commit-hooks.nix + lib = forAllSystems ({ system, lib, ... }: { + pre-commit-hook = { enable = true; name = "topiary"; description = "A general code formatter based on tree-sitter."; - entry = "${pkgs.lib.getExe (topiaryPkgs.topiary-cli {})} fmt"; + entry = "${lib.getExe self.packages.${system}.topiary-cli} fmt"; types = [ "text" ]; }; - } - ); + }); + }; }