docs(nix): clarify file placement terms
This commit is contained in:
54
docs/nix.md
54
docs/nix.md
@@ -48,6 +48,25 @@ Use:
|
||||
dotfiles.mkHost { hostName = "neogaia"; }
|
||||
```
|
||||
|
||||
## File Placement
|
||||
|
||||
### Put files in the directory that owns their role
|
||||
|
||||
Choose the file location before writing a Nix file.
|
||||
Put assembly files under `flake/`.
|
||||
Do not add library files until this repository has a library directory.
|
||||
Put modules under `modules/`.
|
||||
Put host configurations under `hosts/<name>/`.
|
||||
Put host-side guest wiring under `guests/`.
|
||||
Put registry definitions under `registry/`.
|
||||
Keep `flake.nix` focused on inputs and public output wiring.
|
||||
Do not add root-level Nix files other than `flake.nix`.
|
||||
|
||||
A module is self-contained configuration under `modules/`.
|
||||
It usually scopes to one program, service, or subsystem.
|
||||
A Nix module is any Nix language unit that declares or sets module-system options.
|
||||
Files under `hosts/`, `guests/`, and `modules/` return Nix modules.
|
||||
|
||||
## Function Arguments
|
||||
|
||||
### Use closed interfaces for assembly files and library files
|
||||
@@ -177,40 +196,7 @@ Use:
|
||||
lib.mapAttrs f attrs
|
||||
```
|
||||
|
||||
## Flake Assembly
|
||||
|
||||
### Keep assembly code under `flake/`
|
||||
|
||||
Keep flake assembly code under `flake/`.
|
||||
Keep `flake.nix` focused on inputs and public outputs.
|
||||
The `outputs` function returns each public output as an attribute.
|
||||
An external flake reads public outputs through `inputs.<name>.<output>`.
|
||||
`nix flake show` displays public outputs.
|
||||
|
||||
Avoid:
|
||||
|
||||
```nix
|
||||
# flake.nix
|
||||
let
|
||||
mkHosts = hostsDir: ...;
|
||||
in
|
||||
{
|
||||
nixosConfigurations = mkHosts (self + "/hosts");
|
||||
}
|
||||
```
|
||||
|
||||
Use:
|
||||
|
||||
```nix
|
||||
# flake.nix
|
||||
let
|
||||
inherit (nixpkgs) lib;
|
||||
flake = import ./flake { inherit lib inputs self; };
|
||||
in
|
||||
{
|
||||
nixosConfigurations = flake.mkHosts (self + "/hosts");
|
||||
}
|
||||
```
|
||||
## Flake Outputs
|
||||
|
||||
### Expose only supported flake outputs
|
||||
|
||||
|
||||
Reference in New Issue
Block a user