Sort lists that enumerate Nix modules, such as `imports` and the `modules` argument of `lib.nixosSystem`, in lexicographic order, and re-sort an existing unsorted list when touching it. Lists whose order changes the evaluated result are excluded. Use when adding, removing, or rewriting entries in a list of Nix modules.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Module List Order?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/ncaq-module-list-order)
---
name: module-list-order
description: Sort lists that enumerate Nix modules, such as `imports` and the `modules` argument of `lib.nixosSystem`, in lexicographic order, and re-sort an existing unsorted list when touching it. Lists whose order changes the evaluated result are excluded. Use when adding, removing, or rewriting entries in a list of Nix modules.
user-invocable: false
---
# モジュールを並べるリストは辞書順にする
`imports`のようにモジュールを並べるリストは、要素を辞書順に並べて書いてください。
要素を足すときは、関係の近い要素の隣に置くのではなく、辞書順で決まる位置に置きます。
並びが決まっていれば、要素を足す位置に迷いません。
重複や漏れも見つけやすくなります。
既存のリストが辞書順になっていなくても、
そのリストに手を入れるときに全体を並べ直します。
## 対象のリスト
- `imports`
- `lib.nixosSystem`や`home-manager.lib.homeManagerConfiguration`に渡す`modules`
- `home-manager.sharedModules`
## 並べ方
要素のソースコード上の文字列を、文字コードの順に比べます。
`LC_ALL=C sort`と同じ順序です。
`.`は`/`より文字コードが小さいので、
`../`で始まるパスは`./`で始まるパスより前に来ます。
```nix
{
imports = [
../prompt
./core
./link.nix
];
}
```
`inputs.sops-nix.nixosModules.sops`のような属性の参照は、
`./`で始まるパスより後に来ます。
## 並べ替えると結果が変わるリストは対象外
並びに意味があるリストは、辞書順にしません。
モジュールシステムは`imports`の順序に依らずに定義をマージするので、
モジュールのリストは普通は並べ替えても結果が変わりません。
ただし同じ優先度で定義されたリスト型や`lines`型のオプションの値は、
モジュールを読み込む順序に依存した順序で連結されます。
この連結の順序が動作に効くリストは、並べ替えずに残します。
overlaysのリストは、後のoverlayが前のoverlayの結果を受け取るので、順序に意味があります。
モジュールのリストと見た目が似ていても、辞書順にはしません。