diff --git a/flake.lock b/flake.lock index b452c80f..b9da2a2e 100644 --- a/flake.lock +++ b/flake.lock @@ -105,7 +105,6 @@ "inputs": { "advisory-db": "advisory-db", "crane": "crane", - "flake-utils": "flake-utils", "nix-filter": "nix-filter", "nixpkgs": "nixpkgs", "rust-overlay": "rust-overlay", @@ -147,9 +146,7 @@ }, "tree-sitter-nickel": { "inputs": { - "flake-utils": [ - "flake-utils" - ], + "flake-utils": "flake-utils", "nixpkgs": [ "nixpkgs" ] diff --git a/flake.nix b/flake.nix index e909f0fe..086aab10 100644 --- a/flake.nix +++ b/flake.nix @@ -25,21 +25,58 @@ flake = false; }; - flake-utils.url = "github:numtide/flake-utils"; nix-filter.url = "github:numtide/nix-filter"; tree-sitter-nickel = { url = "github:nickel-lang/tree-sitter-nickel"; inputs.nixpkgs.follows = "nixpkgs"; - inputs.flake-utils.follows = "flake-utils"; }; }; outputs = { self, nixpkgs, ... }@inputs: - inputs.flake-utils.lib.eachDefaultSystem ( - system: - let - wasm-bindgen-cli-overlay = final: prev: + let + supportedSystems = nixpkgs.lib.systems.flakeExposed; + + nixpkgsFor = nixpkgs.lib.genAttrs supportedSystems (system: import nixpkgs { + inherit system; + overlays = [ + self.overlays.tree-sitter-grammars + self.overlays.wasm-bindgen-cli + inputs.rust-overlay.overlays.default + ]; + }); + + topiaryPkgsFor = nixpkgs.lib.genAttrs supportedSystems (system: + let pkgs = nixpkgsFor.${system}; in + pkgs.callPackage ./default.nix { + inherit (inputs) advisory-db crane rust-overlay nix-filter; + inherit (pkgs.tree-sitter-grammars) tree-sitter-nickel; + craneLib = inputs.crane.mkLib pkgs; + }); + + binPkgsFor = nixpkgs.lib.genAttrs supportedSystems (system: + nixpkgsFor.${system}.callPackage ./bin/default.nix { } + ); + + forAllSystems = fn: nixpkgs.lib.genAttrs supportedSystems (system: fn rec { + inherit system; + pkgs = nixpkgsFor.${system}; + inherit (pkgs) lib; + craneLib = inputs.crane.mkLib pkgs; + topiaryPkgs = topiaryPkgsFor.${system}; + binPkgs = binPkgsFor.${system}; + }); + 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,24 +89,10 @@ cargoHash = "sha256-3vxVI0BhNz/9m59b+P2YEIrwGwlp7K3pyPKt4VqQuHE="; }; }; + }; - pkgs = import nixpkgs { - inherit system; - overlays = [ inputs.rust-overlay.overlays.default wasm-bindgen-cli-overlay ]; - }; - - craneLib = inputs.crane.mkLib pkgs; - - tree-sitter-nickel = inputs.tree-sitter-nickel.packages.${system}.default; - - topiaryPkgs = pkgs.callPackage ./default.nix { - inherit (inputs) advisory-db crane rust-overlay nix-filter; - inherit craneLib tree-sitter-nickel; - }; - binPkgs = pkgs.callPackage ./bin/default.nix { }; - in - { - packages = rec { + packages = forAllSystems ({ system, pkgs, topiaryPkgs, binPkgs, ... }: + { inherit (topiaryPkgs) topiary-playground topiary-queries @@ -86,41 +109,44 @@ 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 = { + 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.passthru.craneLibWasm; inherit binPkgs; }; + inherit craneLib; + inherit binPkgs; + optionals = false; }; + wasm = pkgs.callPackage ./shell.nix { checks = self.checks.${system}; craneLib = topiaryPkgsFor.${system}.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, ... }: { + pre-commit-hook = { enable = true; name = "topiary"; description = "A general code formatter based on tree-sitter."; - entry = "${topiaryPkgs.topiary-cli {}}/bin/topiary fmt"; + entry = "${self.packages.${system}.topiary-cli}/bin/topiary fmt"; types = [ "text" ]; }; - } - ); + }); + }; }