一键导入
hosts
Add and configure new NixOS host machines
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Add and configure new NixOS host machines
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Create and modify NixOS and Home-Manager modules
Hardens systemd services against security issues using sandboxing, capability restriction, and syscall filtering. Use when creating or modifying systemd services, writing NixOS modules with systemd.services, reviewing service security, or whenever a serviceConfig block is involved. Ensures services follow defense-in-depth principles with minimal privilege.
Write Nix code using repo conventions
Write and review Conventional Commits commit messages (v1.0.0) for semantic versioning and changelogs. Use when drafting git commit messages, PR titles, release notes, or enforcing conventional commit format like `type(scope): subject`, `BREAKING CHANGE`, footers, and `revert`.
Manages version control with Jujutsu (jj), including rebasing, conflict resolution, and Git interop. Use when tracking changes, navigating history, squashing/splitting commits, or pushing to Git remotes.
Manage background jobs, capture command output, and handle session multiplexing. Use when running long commands, capturing output from detached processes, or managing concurrent tasks in headless environments.
| name | hosts |
| description | Add and configure new NixOS host machines |
Each host needs these files in hosts/<type>/<hostname>/:
| File | Required | Purpose |
|---|---|---|
default.nix | Yes | Main config entry point |
secrets.yaml | Yes | SOPS-encrypted secrets like SSH key and passwords |
ssh_host_ed25519_key.pub | Yes | SSH public key for sops age encryption |
hardware.nix | For physical | Hardware-specific config for desktops and laptops |
Easiest way to create new host:
# Usage: new-host.sh <host-type> <host-name>
nix run .#new-host -- server mynewserver
nix run .#new-host -- desktop mynewdesktop
This script:
default.nix.sops.yaml with new host age keysecrets.yamlmkdir -p hosts/server/myserver
default.nix# hosts/server/myserver/default.nix
{ modulesPath, ... }:
{
imports = [
# For LXC containers:
"${modulesPath}/virtualisation/proxmox-lxc.nix"
# Or for physical machines:
# ./hardware.nix
];
host.device.isHeadless = true; # For servers
# Host-specific configuration
}
hardware.nix for physical machines# hosts/desktop/mydesktop/hardware.nix
{ inputs, ... }:
{
imports = [
inputs.nixos-hardware.nixosModules.common-cpu-amd
inputs.nixos-hardware.nixosModules.common-pc-ssd
];
boot.loader = {
systemd-boot.enable = true;
efi.canTouchEfiVariables = true;
};
fileSystems."/" = {
device = "/dev/disk/by-label/nixos";
fsType = "ext4";
};
}
# Generate key
ssh-keygen -t ed25519 -f /tmp/ssh_host_ed25519_key -N ""
cp /tmp/ssh_host_ed25519_key.pub hosts/server/myserver/
# Get age key from SSH key
ssh-to-age < hosts/server/myserver/ssh_host_ed25519_key.pub
# Add this to .sops.yaml
# Create secrets file
sops hosts/server/myserver/secrets.yaml
# Add: SSH_PRIVATE_KEY: <content of private key>
Hosts are auto-discovered. No manual flake registration needed. System:
hosts/ for subdirectoriesshared/ and secrets.yamlnixosConfiguration| Type | Location | Characteristics |
|---|---|---|
server | hosts/server/ | Usually headless, often LXC |
desktop | hosts/desktop/ | GUI, physical hardware |
laptop | hosts/laptop/ | GUI, battery, physical hardware |
Configurations apply in this order:
hosts/shared/global/ - all hostshosts/<type>/shared/ - all hosts of that typehosts/<type>/<hostname>/ - specific hostFor CUDA or ROCm support, add host to flake/nixos/flake-module.nix:
accelerationHosts = {
cuda = [ "nixmi" "mynewhost" ];
rocm = [ "myamdhost" ];
};
Create home/<username>/<hostname>.nix to bind user to host. System auto-detects this file and includes user Home-Manager configuration.
See also: docs/Creating-Hosts.md