From ddb833bd6e3a937452645520c30ff5b377c3f24f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=B9=82=E0=B8=97=E0=B8=AA=E0=B8=95=E0=B8=B1=E0=B8=A5?= Date: Tue, 10 Dec 2024 17:02:06 +0700 Subject: [PATCH 1/4] =?UTF-8?q?typo:=20passtru=20=E2=86=92=20passthru?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- default.nix | 2 +- flake.nix | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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.nix b/flake.nix index 5f64abc8..cb3c98ea 100644 --- a/flake.nix +++ b/flake.nix @@ -109,7 +109,7 @@ { 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; }; + 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 From e474659528665ccb425d759e728421896c544470 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=B9=82=E0=B8=97=E0=B8=AA=E0=B8=95=E0=B8=B1=E0=B8=A5?= Date: Tue, 10 Dec 2024 22:48:59 +0700 Subject: [PATCH 2/4] use inputs attrset --- flake.lock | 4 ++-- flake.nix | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/flake.lock b/flake.lock index b196a67f..75c56a2f 100644 --- a/flake.lock +++ b/flake.lock @@ -93,7 +93,7 @@ "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,7 +129,7 @@ "type": "github" } }, - "tree-sitter-nickel-input": { + "tree-sitter-nickel": { "inputs": { "flake-utils": [ "flake-utils" diff --git a/flake.nix b/flake.nix index cb3c98ea..b25e3630 100644 --- a/flake.nix +++ b/flake.nix @@ -27,16 +27,15 @@ 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 ( + outputs = { self, nixpkgs, ... }@inputs: + inputs.flake-utils.lib.eachDefaultSystem ( system: let wasm-bindgen-cli-overlay = final: prev: @@ -55,15 +54,16 @@ pkgs = import nixpkgs { inherit system; - overlays = [ rust-overlay.overlays.default wasm-bindgen-cli-overlay ]; + overlays = [ inputs.rust-overlay.overlays.default wasm-bindgen-cli-overlay ]; }; - craneLib = crane.mkLib pkgs; + craneLib = inputs.crane.mkLib pkgs; - tree-sitter-nickel = tree-sitter-nickel-input.packages.${system}.default; + tree-sitter-nickel = inputs.tree-sitter-nickel.packages.${system}.default; topiaryPkgs = pkgs.callPackage ./default.nix { - inherit advisory-db crane rust-overlay craneLib tree-sitter-nickel; + inherit (inputs) advisory-db crane rust-overlay; + inherit craneLib tree-sitter-nickel; }; binPkgs = pkgs.callPackage ./bin/default.nix { }; in From 1070e5ee0ca287cfa17570893979286e18240b33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=B9=82=E0=B8=97=E0=B8=AA=E0=B8=95=E0=B8=B1=E0=B8=A5?= Date: Wed, 11 Dec 2024 21:16:39 +0700 Subject: [PATCH 3/4] use self.packages.${system}.topiary-cli (remove rec) --- flake.nix | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/flake.nix b/flake.nix index b25e3630..57228554 100644 --- a/flake.nix +++ b/flake.nix @@ -68,7 +68,7 @@ binPkgs = pkgs.callPackage ./bin/default.nix { }; in { - packages = rec { + packages = { inherit (topiaryPkgs) topiary-playground topiary-queries @@ -85,12 +85,12 @@ update-wasm-grammars verify-documented-usage; - default = topiary-cli; + default = self.packages.${system}.topiary-cli; }; checks = { inherit (topiaryPkgs) clippy clippy-wasm fmt topiary-core topiary-playground audit benchmark; - topiary-cli = topiaryPkgs.topiary-cli { }; + 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 @@ -103,7 +103,7 @@ let checksLight = { inherit (topiaryPkgs) clippy fmt topiary-core; - topiary-cli = topiaryPkgs.topiary-cli { }; + topiary-cli = self.packages.${system}.topiary-cli; }; in { @@ -117,7 +117,7 @@ enable = true; name = "topiary"; description = "A general code formatter based on tree-sitter."; - entry = "${pkgs.lib.getExe (topiaryPkgs.topiary-cli {})} fmt"; + entry = "${pkgs.lib.getExe self.packages.${system}.topiary-cli} fmt"; types = [ "text" ]; }; } From 01c4faee1be2aa723997182abed5ad85368aaa5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=B9=82=E0=B8=97=E0=B8=AA=E0=B8=95=E0=B8=B1=E0=B8=A5?= Date: Tue, 10 Dec 2024 22:00:16 +0700 Subject: [PATCH 4/4] remove nix dependency: flake-utils --- flake.lock | 5 +- flake.nix | 154 ++++++++++++++++++++++++++++++----------------------- 2 files changed, 88 insertions(+), 71 deletions(-) diff --git a/flake.lock b/flake.lock index 75c56a2f..0e645f9a 100644 --- a/flake.lock +++ b/flake.lock @@ -90,7 +90,6 @@ "inputs": { "advisory-db": "advisory-db", "crane": "crane", - "flake-utils": "flake-utils", "nixpkgs": "nixpkgs", "rust-overlay": "rust-overlay", "tree-sitter-nickel": "tree-sitter-nickel" @@ -131,9 +130,7 @@ }, "tree-sitter-nickel": { "inputs": { - "flake-utils": [ - "flake-utils" - ], + "flake-utils": "flake-utils", "nixpkgs": [ "nixpkgs" ] diff --git a/flake.nix b/flake.nix index 57228554..f3493874 100644 --- a/flake.nix +++ b/flake.nix @@ -25,101 +25,121 @@ flake = false; }; - flake-utils.url = "github:numtide/flake-utils"; - 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 - cargoLock = builtins.fromTOML (builtins.readFile ./Cargo.lock); - wasmBindgenCargoVersions = builtins.map ({ version, ... }: version) (builtins.filter ({ name, ... }: name == "wasm-bindgen") cargoLock.package); - wasmBindgenVersion = assert builtins.length wasmBindgenCargoVersions == 1; builtins.elemAt wasmBindgenCargoVersions 0; - in - { - wasm-bindgen-cli = prev.wasm-bindgen-cli.override { - version = wasmBindgenVersion; - hash = "sha256-f/RK6s12ItqKJWJlA2WtOXtwX4Y0qa8bq/JHlLTAS3c="; - cargoHash = "sha256-3vxVI0BhNz/9m59b+P2YEIrwGwlp7K3pyPKt4VqQuHE="; - }; - }; + let + supportedSystems = nixpkgs.lib.systems.flakeExposed; + pkgsFor = nixpkgs.lib.genAttrs supportedSystems (system: rec { pkgs = import nixpkgs { inherit system; - overlays = [ inputs.rust-overlay.overlays.default wasm-bindgen-cli-overlay ]; + overlays = [ + self.overlays.tree-sitter-grammars + self.overlays.wasm-bindgen-cli + inputs.rust-overlay.overlays.default + ]; }; - 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; - inherit craneLib tree-sitter-nickel; - }; - binPkgs = pkgs.callPackage ./bin/default.nix { }; - in - { - packages = { - 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; + inherit (pkgs.tree-sitter-grammars) tree-sitter-nickel; + craneLib = inputs.crane.mkLib pkgs; }; - checks = { - inherit (topiaryPkgs) clippy clippy-wasm fmt topiary-core topiary-playground audit benchmark; - topiary-cli = self.packages.${system}.topiary-cli; + binPkgs = pkgs.callPackage ./bin/default.nix { }; + }); - ## 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; + 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; + }; }; - devShells = + wasm-bindgen-cli = final: prev: let - checksLight = { + cargoLock = builtins.fromTOML (builtins.readFile ./Cargo.lock); + wasmBindgenCargoVersions = builtins.map ({ version, ... }: version) (builtins.filter ({ name, ... }: name == "wasm-bindgen") cargoLock.package); + wasmBindgenVersion = assert builtins.length wasmBindgenCargoVersions == 1; builtins.elemAt wasmBindgenCargoVersions 0; + in + { + wasm-bindgen-cli = prev.wasm-bindgen-cli.override { + version = wasmBindgenVersion; + hash = "sha256-f/RK6s12ItqKJWJlA2WtOXtwX4Y0qa8bq/JHlLTAS3c="; + cargoHash = "sha256-3vxVI0BhNz/9m59b+P2YEIrwGwlp7K3pyPKt4VqQuHE="; + }; + }; + }; + + 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 = 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 = 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 self.packages.${system}.topiary-cli} fmt"; + entry = "${lib.getExe self.packages.${system}.topiary-cli} fmt"; types = [ "text" ]; }; - } - ); + }); + }; }