Skip to content

Commit c4ce7c3

Browse files
committedFeb 3, 2025·
dev/format: setup treefmt
1 parent e047aae commit c4ce7c3

File tree

9 files changed

+99
-16
lines changed

9 files changed

+99
-16
lines changed
 

‎.github/workflows/build.yml

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ on:
33
push:
44
branches: [main]
55
pull_request:
6-
76
jobs:
87
kit:
98
name: Svelte Kit

‎.github/workflows/static.yml

-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ on:
66
push:
77
branches:
88
- main
9-
109
jobs:
1110
format:
1211
name: Format JS
@@ -50,7 +49,6 @@ jobs:
5049
working-directory: service # doesn't work without this
5150
- run: bun install --frozen-lockfile
5251
- run: bun check
53-
5452
nix-checks:
5553
name: Nix checks
5654
runs-on: ubuntu-latest

‎.github/workflows/test.yml

-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ on:
77
push:
88
branches:
99
- main
10-
1110
# env:
1211
# DATABASE_URL: ${{ secrets.DATABASE_URL }}
13-
1412
jobs:
1513
build:
1614
name: "Tests (todo)"

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ wip: 開発中です。
1111
a. Nix を使える場合
1212

1313
1. [Nix と nix-direnv をインストールします。](./docs/install-nix.md)
14-
2. `direnv allow` と実行します。
14+
1. `direnv allow` と実行します。
1515

1616
b. Nix を使えない場合
1717

‎docs/install-nix.md

+8-6
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
## Nix のインストール
44

5-
Nix 本体をインストールします。
6-
[公式から提供されているインストーラー](https://nixos.org/download/) でもいいですが、
7-
[DeterminateSystems が提供するインストーラー](https://github.com/DeterminateSystems/nix-installer) も色々便利らしいです。
5+
Nix 本体をインストールします。 [公式から提供されているインストーラー](https://nixos.org/download/) でもいいですが、
6+
[DeterminateSystems が提供するインストーラー](https://github.com/DeterminateSystems/nix-installer)
7+
も色々便利らしいです。
88

99
各ドキュメントを読めば難しいことはない、というかシェルスク一行のはずです。
1010

@@ -28,9 +28,10 @@ NixOS は入れてないと思うので、 Standalone で入れましょう。
2828

2929
## Nix-Direnv のインストール
3030

31-
Home Manager をインストールしたら、 `~/.config/home-manager/home.nix` が作成されていることと思います。
32-
そこに、`direnv``nix-direnv` の設定を追加しましょう。 <https://github.com/nix-community/nix-direnv?tab=readme-ov-file#via-home-manager>
33-
最終的には、`home.nix` はこんな感じになると思います。
31+
Home Manager をインストールしたら、 `~/.config/home-manager/home.nix` が作成されていることと思います。 そこに、`direnv`
32+
`nix-direnv` の設定を追加しましょう。
33+
<https://github.com/nix-community/nix-direnv?tab=readme-ov-file#via-home-manager> 最終的には、`home.nix`
34+
はこんな感じになると思います。
3435

3536
```nix
3637
{ pkgs, ... }: {
@@ -62,4 +63,5 @@ Nix 経由で direnv がインストールできたことを確認するため
6263
$ readlink $(which direnv)
6364
/nix/store/id5qc6k2rh5micxhsxjard2ypp503zw0-direnv-2.35.0/bin/direnv
6465
```
66+
6567
上のように、`/nix/store` 以下にファイルがあると表示されれば成功です。

‎flake.lock

+22-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎flake.nix

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,24 @@
44
inputs = {
55
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
66
flake-utils.url = "github:numtide/flake-utils";
7+
treefmt-nix.url = "github:numtide/treefmt-nix";
8+
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
79
};
810

911
outputs = {
1012
nixpkgs,
1113
flake-utils,
12-
...
14+
treefmt-nix,
15+
self,
1316
}:
1417
flake-utils.lib.eachDefaultSystem (
1518
system: let
1619
pkgs = nixpkgs.legacyPackages.${system};
20+
treefmt = (treefmt-nix.lib.evalModule pkgs ./treefmt.nix).config.build;
1721
in {
18-
formatter = pkgs.alejandra;
22+
formatter = treefmt.wrapper;
1923
devShells.default = pkgs.callPackage ./shell.nix {};
24+
checks.format = treefmt.check self;
2025
}
2126
);
2227
}

‎justfile

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,35 @@ default:
22
just --list
33

44
i: install
5+
56
install:
67
cd web; bun install --frozen-lockfile
78
cd service; bun install --frozen-lockfile
89

910
b: build
11+
1012
build: build-svelte build-worker
13+
1114
build-svelte:
1215
bun run build
16+
1317
build-worker:
1418
cd worker; bunx tsc
1519

1620
format:
1721
deno fmt --check .
22+
1823
format-fix:
1924
deno fmt .
25+
2026
lint:
2127
biome lint .
28+
2229
lint-fix:
2330
biome lint --fix .
2431

2532
check: format lint
2633
cd web; bun check
2734
cd service; bun check
28-
fix: format-fix lint-fix
2935

36+
fix: format-fix lint-fix

‎treefmt.nix

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
let
2+
deno-includes = [
3+
"*.css"
4+
"*.html"
5+
"*.js"
6+
"*.json"
7+
"*.jsonc"
8+
"*.jsx"
9+
"*.less"
10+
"*.markdown"
11+
"*.md"
12+
"*.sass"
13+
"*.scss"
14+
"*.ts"
15+
"*.tsx"
16+
"*.yaml"
17+
"*.yml"
18+
"*.svelte"
19+
];
20+
global-excludes = [
21+
"node_modules"
22+
".gitignore"
23+
".npmrc"
24+
".ignore"
25+
".envrc"
26+
".env.example"
27+
"*.png"
28+
"*.svg"
29+
"*.webp"
30+
"robots.txt"
31+
];
32+
in {
33+
# <https://github.com/numtide/treefmt-nix>
34+
35+
settings.global.excludes = builtins.concatMap (name: [name ("**/" + name)]) global-excludes;
36+
programs = {
37+
# config DSL
38+
taplo.enable = true;
39+
yamlfmt.enable = true;
40+
just.enable = true;
41+
mdformat.enable = true;
42+
43+
# JS
44+
deno.enable = true;
45+
deno.includes = deno-includes;
46+
biome.enable = true;
47+
48+
# Nix
49+
alejandra.enable = true;
50+
statix.enable = true;
51+
deadnix.enable = true;
52+
};
53+
}

0 commit comments

Comments
 (0)
Please sign in to comment.