From e2060290b1bdbc86f768864e7ccd30abfde70793 Mon Sep 17 00:00:00 2001 From: Naman Agarwal Date: Mon, 16 Oct 2023 00:26:33 +0530 Subject: [PATCH 1/4] dioxus-cli program --- README.md | 1 + programs/dioxus-cli.nix | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 programs/dioxus-cli.nix diff --git a/README.md b/README.md index 838e7c6..a6abff8 100644 --- a/README.md +++ b/README.md @@ -181,6 +181,7 @@ This repo contains a top-level `default.nix` that returns the library helper fun * deno * dhall * dprint +* dioxus-cli * elm-format * erlfmt * fnlfmt diff --git a/programs/dioxus-cli.nix b/programs/dioxus-cli.nix new file mode 100644 index 0000000..94c323f --- /dev/null +++ b/programs/dioxus-cli.nix @@ -0,0 +1,18 @@ +{ lib, pkgs, config, ... }: +let + cfg = config.programs.dioxusfmt; +in + { + options.programs.dioxus-cli = { + enable = lib.mkEnableOption "dioxus-cli"; + package = lib.mkPackageOptions pkgs "dioxus-cli" {}; + }; + + config = lib.mkIf cfg.enable { + settings.formatter.dioxus-cli = { + command = "${cfg.package}/bin/dioxus"; + options = [ "fmt" ]; + includes = [ ".rs" ]; + }; + }; + } From 53dcf3f642bfbfa2b480ff86b6d221456514c599 Mon Sep 17 00:00:00 2001 From: Naman Agarwal Date: Wed, 25 Oct 2023 21:12:32 +0530 Subject: [PATCH 2/4] fixes --- examples.sh | 2 +- examples/formatter-dioxus-cli.toml | 6 ++++++ flake.lock | 6 +++--- programs/dioxus-cli.nix | 4 ++-- run_docker.sh | 1 + 5 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 examples/formatter-dioxus-cli.toml create mode 100755 run_docker.sh diff --git a/examples.sh b/examples.sh index 77c4a98..04c4cf0 100755 --- a/examples.sh +++ b/examples.sh @@ -8,7 +8,7 @@ cd "$(dirname "$0")" system=$(nix eval --raw --impure --expr 'builtins.currentSystem') # Generate the examples from the config -nix build ".#checks.$system.examples.passthru.examples" +nix build ".#checks.$system.examples.passthru.examples" --impure # Copy rm -f ./examples/* || true diff --git a/examples/formatter-dioxus-cli.toml b/examples/formatter-dioxus-cli.toml new file mode 100644 index 0000000..6a975b7 --- /dev/null +++ b/examples/formatter-dioxus-cli.toml @@ -0,0 +1,6 @@ +# Example generated by ../examples.sh +[formatter.dioxus-cli] +command = "dioxus" +excludes = [] +includes = [".rs"] +options = ["fmt"] diff --git a/flake.lock b/flake.lock index b58ecab..07517c6 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1695644571, - "narHash": "sha256-asS9dCCdlt1lPq0DLwkVBbVoEKuEuz+Zi3DG7pR/RxA=", + "lastModified": 1697723726, + "narHash": "sha256-SaTWPkI8a5xSHX/rrKzUe+/uVNy6zCGMXgoeMb7T9rg=", "owner": "nixos", "repo": "nixpkgs", - "rev": "6500b4580c2a1f3d0f980d32d285739d8e156d92", + "rev": "7c9cc5a6e5d38010801741ac830a3f8fd667a7a0", "type": "github" }, "original": { diff --git a/programs/dioxus-cli.nix b/programs/dioxus-cli.nix index 94c323f..75ecae1 100644 --- a/programs/dioxus-cli.nix +++ b/programs/dioxus-cli.nix @@ -1,11 +1,11 @@ { lib, pkgs, config, ... }: let - cfg = config.programs.dioxusfmt; + cfg = config.programs.dioxus-cli; in { options.programs.dioxus-cli = { enable = lib.mkEnableOption "dioxus-cli"; - package = lib.mkPackageOptions pkgs "dioxus-cli" {}; + package = lib.mkPackageOption pkgs "dioxus-cli" {}; }; config = lib.mkIf cfg.enable { diff --git a/run_docker.sh b/run_docker.sh new file mode 100755 index 0000000..a90afc8 --- /dev/null +++ b/run_docker.sh @@ -0,0 +1 @@ +docker run -d -it --name treefmt --mount type=bind,source="$(pwd)",target=/app ubuntu From ee245eca7ef3f89cde35d101f640feca9800f56c Mon Sep 17 00:00:00 2001 From: Naman Agarwal Date: Sun, 26 Nov 2023 20:01:14 +0530 Subject: [PATCH 3/4] change prgram name --- examples/formatter-dioxus-cli.toml | 4 ++-- programs/dioxus-cli.nix | 18 ------------------ programs/dioxus.nix | 30 ++++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 20 deletions(-) delete mode 100644 programs/dioxus-cli.nix create mode 100644 programs/dioxus.nix diff --git a/examples/formatter-dioxus-cli.toml b/examples/formatter-dioxus-cli.toml index 6a975b7..9253469 100644 --- a/examples/formatter-dioxus-cli.toml +++ b/examples/formatter-dioxus-cli.toml @@ -1,6 +1,6 @@ # Example generated by ../examples.sh [formatter.dioxus-cli] -command = "dioxus" +command = "dx" excludes = [] -includes = [".rs"] +includes = ["*.rs"] options = ["fmt"] diff --git a/programs/dioxus-cli.nix b/programs/dioxus-cli.nix deleted file mode 100644 index 75ecae1..0000000 --- a/programs/dioxus-cli.nix +++ /dev/null @@ -1,18 +0,0 @@ -{ lib, pkgs, config, ... }: -let - cfg = config.programs.dioxus-cli; -in - { - options.programs.dioxus-cli = { - enable = lib.mkEnableOption "dioxus-cli"; - package = lib.mkPackageOption pkgs "dioxus-cli" {}; - }; - - config = lib.mkIf cfg.enable { - settings.formatter.dioxus-cli = { - command = "${cfg.package}/bin/dioxus"; - options = [ "fmt" ]; - includes = [ ".rs" ]; - }; - }; - } diff --git a/programs/dioxus.nix b/programs/dioxus.nix new file mode 100644 index 0000000..e1b0123 --- /dev/null +++ b/programs/dioxus.nix @@ -0,0 +1,30 @@ +{ lib, pkgs, config, ... }: +let + cfg = config.programs.dioxus; +in + { + options.programs.dioxus = { + enable = lib.mkEnableOption "dioxus"; + package = lib.mkPackageOption pkgs "dioxus-cli" {}; + }; + + config = lib.mkIf cfg.enable { + settings.formatter.dioxus = { + command = pkgs.writeShellApplication { + name = "dioxus-fmt"; + runtimeInputs = [ + cfg.package + ]; + text = '' + set -x + for file in "$@"; do + echo "$file" + dioxus fmt "$file" + done + set +x + ''; + }; + includes = [ "*.rs" ]; + }; + }; + } From 555e603c072f301fd6e0a129acf9758e46c98c7f Mon Sep 17 00:00:00 2001 From: Naman Agarwal Date: Mon, 27 Nov 2023 22:03:34 +0530 Subject: [PATCH 4/4] finalize --- README.md | 4 +- examples.sh | 2 +- ...-dioxus-cli.toml => formatter-dioxus.toml} | 4 +- programs/dioxus.nix | 43 +++++++++---------- run_docker.sh | 1 - 5 files changed, 25 insertions(+), 29 deletions(-) rename examples/{formatter-dioxus-cli.toml => formatter-dioxus.toml} (72%) delete mode 100755 run_docker.sh diff --git a/README.md b/README.md index e2cdf91..3c5fda6 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ This flake exposes a [flake-parts](https://flake.parts/) module as well. To use For an example, see [haskell-template](https://github.com/srid/haskell-template)'s `flake.nix`. -See [this page](https://zero-to-flakes.com/treefmt-nix) for a detailed walkthrough. +See [this page](https://haskell.flake.page/treefmt) for details. ## Configuration While dealing with `treefmt` outside of `nix`, the formatter configuration is specified in a `toml` format. On the contrary, with `nix`, you write in with a nix syntax like this: @@ -180,8 +180,8 @@ This repo contains a top-level `default.nix` that returns the library helper fun * deadnix * deno * dhall +* dioxus * dprint -* dioxus-cli * elm-format * erlfmt * fnlfmt diff --git a/examples.sh b/examples.sh index 04c4cf0..77c4a98 100755 --- a/examples.sh +++ b/examples.sh @@ -8,7 +8,7 @@ cd "$(dirname "$0")" system=$(nix eval --raw --impure --expr 'builtins.currentSystem') # Generate the examples from the config -nix build ".#checks.$system.examples.passthru.examples" --impure +nix build ".#checks.$system.examples.passthru.examples" # Copy rm -f ./examples/* || true diff --git a/examples/formatter-dioxus-cli.toml b/examples/formatter-dioxus.toml similarity index 72% rename from examples/formatter-dioxus-cli.toml rename to examples/formatter-dioxus.toml index 9253469..2ab88a6 100644 --- a/examples/formatter-dioxus-cli.toml +++ b/examples/formatter-dioxus.toml @@ -1,6 +1,6 @@ # Example generated by ../examples.sh [formatter.dioxus-cli] -command = "dx" +command = "dioxus-fmt" excludes = [] includes = ["*.rs"] -options = ["fmt"] +options = [] diff --git a/programs/dioxus.nix b/programs/dioxus.nix index e1b0123..a2d4800 100644 --- a/programs/dioxus.nix +++ b/programs/dioxus.nix @@ -2,29 +2,26 @@ let cfg = config.programs.dioxus; in - { - options.programs.dioxus = { - enable = lib.mkEnableOption "dioxus"; - package = lib.mkPackageOption pkgs "dioxus-cli" {}; - }; +{ + options.programs.dioxus = { + enable = lib.mkEnableOption "dioxus"; + package = lib.mkPackageOption pkgs "dioxus-cli" { }; + }; - config = lib.mkIf cfg.enable { - settings.formatter.dioxus = { - command = pkgs.writeShellApplication { - name = "dioxus-fmt"; - runtimeInputs = [ - cfg.package - ]; - text = '' - set -x - for file in "$@"; do - echo "$file" - dioxus fmt "$file" - done - set +x - ''; - }; - includes = [ "*.rs" ]; + config = lib.mkIf cfg.enable { + settings.formatter.dioxus = { + command = pkgs.writeShellApplication { + name = "dioxus-fmt"; + runtimeInputs = [ + cfg.package + ]; + text = '' + for file in "$@"; do + dx fmt -f "$file" + done + ''; }; + includes = [ "*.rs" ]; }; - } + }; +} diff --git a/run_docker.sh b/run_docker.sh deleted file mode 100755 index a90afc8..0000000 --- a/run_docker.sh +++ /dev/null @@ -1 +0,0 @@ -docker run -d -it --name treefmt --mount type=bind,source="$(pwd)",target=/app ubuntu