78 lines
2.0 KiB
Markdown
78 lines
2.0 KiB
Markdown
# A Dendritic Nix Flake
|
|
|
|
Regenerate flake and switch to it.
|
|
|
|
```shell
|
|
nix run .#write-flake
|
|
nix flake check
|
|
home-manager switch --flake .#desktop
|
|
```
|
|
|
|
```shell
|
|
nix flake show --all-systems
|
|
```
|
|
|
|
## Layout
|
|
|
|
- Everything under `./modules` gets auto-imported by `import-tree`
|
|
|
|
| Directory | Description |
|
|
| ------------- | ----------- |
|
|
| `hosts` | Provides either `homeConfigurations` or `nixosConfigurations` |
|
|
| `nix-tools` | Nix-specific tools, like factory functions for use in the flakes |
|
|
| `nixos` | `flake.modules.nixos` |
|
|
| `programs` | flakes that provide `flake.modules` attributes for specific programs |
|
|
| `services` | flakes that provide configuration for running services |
|
|
| `users` | flakes that provide configuration for individual users with the `flake.factory.user` factory |
|
|
|
|
## Mechanics
|
|
|
|
### Flake
|
|
|
|
The top-level flake is created using [flake-file](https://flake-file.oeiuwq.com/)
|
|
|
|
```shell
|
|
nix flake init -t github:vic/flake-file#default
|
|
...
|
|
nix run ".#write-flake"
|
|
```
|
|
|
|
This uses `inputs.flake-parts.lib.mkFlake` to create the flake.
|
|
|
|
The modules are automatically imported from the `./modules` using [import-tree](https://import-tree.oeiuwq.com/).
|
|
|
|
### [Home Manager](https://flake.parts/options/home-manager.html)
|
|
|
|
Uses the home-manager module of flake-parts, which is imported in `modules/home-manager/flake-parts.nix`
|
|
|
|
Looks for options:
|
|
|
|
- `flake.homeConfigurations`
|
|
- `flake.homeModules`
|
|
|
|
Show exported home configurations:
|
|
|
|
```shell
|
|
nix eval --apply builtins.attrNames .#homeConfigurations
|
|
```
|
|
|
|
### Testing
|
|
|
|
These commands would are useful for debugging
|
|
|
|
```shell
|
|
SYSTEM=lxc
|
|
|
|
# Just evaluate (fast, catches config errors)
|
|
nix eval .#nixosConfigurations.${SYSTEM}.config.system.build.toplevel
|
|
|
|
# Full build (slower, produces a bootable system)
|
|
nix build .#nixosConfigurations.${SYSTEM}.config.system.build.toplevel
|
|
```
|
|
|
|
### Remote Deploy
|
|
|
|
```shell
|
|
nixos-rebuild switch --flake .#lxc --target-host root@fded:fb16:653e:25da:be24:11ff:fea0:753f
|
|
```
|