Files
nix/README.md
T

117 lines
5.4 KiB
Markdown

# nix
my [nixos](https://nixos.org/) configuration, structured with [den](https://github.com/vic/den) and [flake-parts](https://github.com/hercules-ci/flake-parts).
## structure
```nix/flake.nix#L1-2
outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } (inputs.import-tree ./modules);
```
modules are automatically discovered via [import-tree](https://github.com/vic/import-tree) and composed using `den.aspects`.
```
modules/
├── system/ # OS fundamentals (base, desktop, audio, graphics, network, theme, janitor, ...)
├── services/ # self-hosted services (searxng, gitea, copyparty, cloudflared, ...)
├── software/<cat>/ # user software; each folder is one aspect: every file (one per software) adds to den.aspects.software.<cat>
├── software/<cat>.nix # single-file categories are flattened to one file
├── roles.nix # den.aspects.desktop / den.aspects.server bundles
├── hosts/
│ ├── default.nix # den.default (every host)
│ ├── common.nix # shared host attrs (domain, bug user), den.homes, schema
│ └── <host>.nix # den.hosts entity + den.aspects.<host>
└── users/ # user accounts
```
aspects are nested by path, e.g. `den.aspects.software.browsers`, `den.aspects.system.network.dns`.
- **den.default** (`hosts/default.nix`) is applied to every host automatically — no need to include it. It also reaches standalone `den.homes`, so host-only aspects (catppuccin, janitor) are wrapped in a `({ host, ... }: ...)` include.
- **host attrs** (`hosts/common.nix` shared, `hosts/<host>.nix` per host): `domain`, `users`, optional `cloudflared = { uuid; protocol; }`. Read them in aspects via `{ host, ... }`.
- **unfree** is allowed per aspect: `includes = [ (den.batteries.unfree [ "steam" ]) ];`.
### adding an app
drop a file in `modules/software/<cat>/` (or edit `modules/software/<cat>.nix`; turn it into a folder once it holds 2+ files) contributing to `den.aspects.software.<cat>` (new category: also add it to `roles.nix`).
### adding a flake input
`flake.nix` is generated by [flake-file](https://github.com/vic/flake-file) — don't edit it. declare the input in the module that uses it:
```nix
{ inputs, ... }: {
flake-file.inputs.foo = {
url = "github:owner/foo";
inputs.nixpkgs.follows = "nixpkgs";
};
den.aspects.software.cli.nixos.imports = [ inputs.foo.nixosModules.default ];
}
```
then run `nix run .#write-flake` (and `nix flake lock`). core inputs (den, flake-parts, nixpkgs, home-manager, ...) live in `modules/den.nix`.
### adding a hosted service
declare a `tunnel` quirk on the aspect; `services.cloudflared` collects them into ingress rules for `<subdomain>.<host.domain>`:
```nix
den.aspects.services.foo = let port = 8080; in {
tunnel = { subdomain = "foo"; inherit port; }; # or a list of them
nixos.services.foo = { enable = true; inherit port; };
};
```
then include `services.foo` (and `services.cloudflared`) in the host, which needs `cloudflared.uuid` set in `modules/hosts/<host>.nix`.
---
## hosts
| Host | Role | GPU | Switch Command |
|------|------|-----|----------------|
| `nix` | desktop | nvidia | `nh os switch ~/nix --impure -H nix` |
| `styx` | laptop | amd | `nh os switch ~/nix --impure -H styx` |
| `box` | homeserver | — | `nh os switch ~/nix --impure -H box` |
---
## self-hosted services
all services on `box` are proxied through cloudflared tunnels to `*.bug.tools`.
| Service | URL | Description |
|---------|-----|-------------|
| [searxng](https://github.com/searxng/searxng) | [search.bug.tools](https://search.bug.tools) | Privacy-respecting metasearch engine |
| [copyparty](https://github.com/9001/copyparty) | [files.bug.tools](https://files.bug.tools) | File server / uploader |
| [gitea](https://gitea.io/) | [git.bug.tools](https://git.bug.tools) | Self-hosted Git with org mirrors |
| [glances](https://github.com/nicolargo/glances) | [monitor.bug.tools](https://monitor.bug.tools) | System monitoring |
| [nixos-mailserver](https://gitlab.com/simple-nixos-mailserver/nixos-mailserver) | [mail.bug.tools](https://mail.bug.tools) | Email server |
| [invidious](https://github.com/iv-org/invidious) | [tube.bug.tools](https://tube.bug.tools) | YouTube frontend *(disabled)* |
| [matrix](https://matrix.org/) | [matrix.bug.tools](https://matrix.bug.tools) | Matrix homeserver *(disabled)* |
| [sish](https://docs.ssi.sh/) | [tuns.bug.tools](https://tuns.bug.tools) | SSH tunnels *(disabled)* |
| vscode-server | — | Remote VS Code access |
---
## flake inputs
| Input | Purpose |
|-------|---------|
| [nixpkgs](https://github.com/nixos/nixpkgs) (unstable) | Package set |
| [home-manager](https://github.com/nix-community/home-manager) | User environment management |
| [flake-parts](https://github.com/hercules-ci/flake-parts) | Flake structure |
| [den](https://github.com/vic/den) | Dendritic aspect system |
| [import-tree](https://github.com/vic/import-tree) | Auto module discovery |
| [stylix](https://github.com/nix-community/stylix) | System-wide theming |
| [catppuccin/nix](https://github.com/catppuccin/nix) | Catppuccin theme modules |
| [nixcord](https://github.com/FlameFlag/nixcord) | Declarative Vesktop/Discord |
| [nix-flatpak](https://github.com/gmodena/nix-flatpak) | Declarative Flatpak |
| [copyparty](https://github.com/9001/copyparty) | File server |
---
## TODO
fix matrix server
fix invidious instance
configure cosmic with home