headless

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

headless

无头机器

Guide the user through setting up one headless machine over SSH. Go one step at a time: say what the step does, run it, show its result, and only then move on. Every step is safe to run again.
This version covers Macs (steps 1 to 7), Linux machines ("Linux machines" below) and Windows machines ("Windows machines" below); step 2 and the rules are shared.
All scripts live in this skill's
scripts/
folder; call them by path.
$SKILL
below means this skill's folder.
通过 SSH 指导用户设置一台无头机器。逐步进行:说明每个步骤的作用,运行该步骤并展示结果,然后才继续。每一步都可以安全地重复运行。
本版本涵盖 Mac(步骤 1 到 7)、Linux 机器(见下文“Linux 机器”)和 Windows 机器(见下文“Windows 机器”);步骤 2 和通用规则共用。
所有脚本都位于此 skill 的
scripts/
文件夹中;应按路径调用。下文
$SKILL
表示此 skill 的文件夹。

Rules that never bend

永不妥协的规则

  • Never see the password. Do not ask the user to type it to you, paste it, or put it in a file you read. Never run a command that prints a secret (
    op read
    ,
    bw get
    ,
    cat
    on the env file,
    secret-run.sh ... -- cat
    ,
    echo $...
    ). You only handle the store entry name, such as
    av:HEADLESS_MAC_PASSWORD
    . The scripts read the secret themselves and pipe it to
    sudo -S
    or SSH; it never reaches a command line or a log.
  • Never weaken sudo. Do not add a passwordless sudo rule. Every later admin step reads the password from the store again.
  • Key before key-only. Password sign-in turns off only after
    connect.sh
    has proved the user's key works.
  • Ask before anything the user did not choose, and stop and ask when a step fails in a way its message does not explain.
  • 绝不查看密码。 不要要求用户把密码输入给你、粘贴给你,或放入你读取的文件中。绝不运行会打印 secret 的命令(
    op read
    、
    bw get
    、对 env 文件执行
    cat
    、
    secret-run.sh ... -- cat
    、
    echo $...
    )。你只处理 store 的条目名称,例如
    av:HEADLESS_MAC_PASSWORD
    。脚本会自行读取 secret,并将其通过管道传给
    sudo -S
    或 SSH;secret 绝不会出现在命令行或日志中。
  • 绝不削弱 sudo。 不添加免密 sudo 规则。之后的每个管理员步骤都要再次从 store 读取密码。
  • 先配置密钥,再启用仅密钥登录。 只有在
    connect.sh
    证明用户的密钥可用之后,才关闭密码登录。
  • 对于用户未选择的任何操作,先征得同意;如果某一步以错误消息未作解释的方式失败,则停止并询问用户。

Step 1: Admin access at the Mac (the user does this)

步骤 1:Mac 上的管理员访问权限(由用户操作)

Ask the user to confirm, at the Mac itself (screen and keyboard, or screen sharing), that:
  1. It has an administrator account with a password. Note its account name (short name, such as
    admin
    ).
  2. Remote Login is on for that account: System Settings > General > Sharing > Remote Login (and "Allow full disk access for remote users" may stay off).
  3. They know its address: an IP address or a name such as
    mac-mini.local
    (System Settings > General > Sharing shows it).
  4. FileVault may stay on: with automatic sign-in, step 5 turns it off (it has to be off for that) and asks them only if macOS refuses.
Details and screenshots-free wording for each:
references/mac.md
.
请用户直接在 Mac 本机(显示器和键盘,或屏幕共享)确认:
  1. 它有一个带密码的管理员账户。记下账户名称(短名称,例如
    admin
    )。
  2. 该账户已启用远程登录:系统设置 > 通用 > 共享 > 远程登录(“允许远程用户完全磁盘访问权限”可以保持关闭)。
  3. 用户知道它的地址:IP 地址或名称,例如
    mac-mini.local
    (系统设置 > 通用 > 共享中会显示)。
  4. FileVault 可以保持开启:启用自动登录时,步骤 5 会将其关闭(自动登录要求 FileVault 处于关闭状态),并且仅在 macOS 拒绝操作时询问用户。
每个选项的详细说明和无需截图的指导措辞见
references/mac.md
。

Step 2: The password goes in a secret store (the user does this)

步骤 2:将密码保存到 secret store(由用户操作)

Ask which secret store they use, recommend one, and have them save the admin password there. Read
references/secrets.md
for each store's exact save command and the entry name format. In order of preference:
StoreEntry name you keep
Automic Vault (macOS)
av:NAME
1Password CLI
op:op://Vault/Item/password
Bitwarden CLI
bw:ITEM
Any command that prints it
cmd:COMMAND
Last resort: a private env file
env:~/.config/headless/NAME.env:HEADLESS_PASSWORD
For the env file, tell the user plainly: it is a plain-text file only their account can read; you will not open it, and they can add a rule to your settings that denies reading it (
references/secrets.md
), but a program running as them could still read it. Prefer a real store.
Also make sure the user has an SSH key on this computer (
~/.ssh/id_ed25519.pub
). If not, offer to make one with
ssh-keygen -t ed25519
(the user chooses its passphrase). The scripts sign in without prompts, so a key with a passphrase must be loaded in ssh-agent: ask the user to run
ssh-add ~/.ssh/id_ed25519
(on a Mac,
ssh-add --apple-use-keychain ~/.ssh/id_ed25519
keeps it across restarts).
询问用户使用哪个 secret store,推荐一个,并让用户自己将管理员密码保存在其中。读取
references/secrets.md
,了解每个 store 的准确保存命令和条目名称格式。按以下顺序推荐:
Store你保留的条目名称
Automic Vault(macOS)
av:NAME
1Password CLI
op:op://Vault/Item/password
Bitwarden CLI
bw:ITEM
任意用于打印密码的命令
cmd:COMMAND
最后手段:私有 env 文件
env:~/.config/headless/NAME.env:HEADLESS_PASSWORD
对于 env 文件,应明确告诉用户:这是一个只有其账户才能读取的纯文本文件;你不会打开它,用户还可以在设置中添加拒绝读取它的规则(
references/secrets.md
),但以该用户身份运行的程序仍可读取它。应优先使用真正的 store。
此外,确认用户在这台电脑上拥有 SSH 密钥(
~/.ssh/id_ed25519.pub
)。如果没有,可以提出使用
ssh-keygen -t ed25519
创建一个(由用户选择其 passphrase)。脚本会以无提示方式登录,因此带 passphrase 的密钥必须加载到 ssh-agent 中:请用户运行
ssh-add ~/.ssh/id_ed25519
(在 Mac 上,
ssh-add --apple-use-keychain ~/.ssh/id_ed25519
可让密钥在重启后继续保留)。

Step 3: The config folder

步骤 3:配置文件夹

Ask where the machine's config should live. Default:
~/headless/<machine-name>
, a git folder on this computer that is copied to the Mac on every update; the user can push it to any git host later. If they already keep a nix-darwin config elsewhere, see "Your own config" below.
Ask these choices, with the defaults in bold:
  • Machine name (host name): keep the current one, or a new one.
  • Automatic sign-in at start-up: on (needs FileVault off; step 5 turns it off). Say so: the Mac's disk is then no longer protected by the account's password.
  • Tailscale: off. Offer it; never require it (step 6). If the Mac already has the Tailscale app (
    /Applications/Tailscale.app
    ), keep this off and leave the app as it is;
    apply.sh
    refuses to start a second Tailscale.
  • Extras, each on and each can be turned off:
    neverSleep
    ,
    startAfterPowerLoss
    ,
    wakeOnLan
    ,
    powerNapOff
    ,
    spotlightOff
    ,
    siriOff
    (
    references/mac.md
    says what each does).
Then make the folder:
sh
$SKILL/scripts/mac/new-config.sh ~/headless/mini \
  --address ADDRESS --login ACCOUNT --password-ref ENTRY \
  [--ssh-key ~/.ssh/id_ed25519] [--host-name NAME] [--no-auto-login] \
  [--tailscale] [--tailscale-key-ref ENTRY] [--extra-off NAME]...
It writes
flake.nix
,
machine.nix
(the user's own additions go here),
settings.json
and
headless.env
(address, account, key and store entry; no secret). Show the user
settings.json
.
询问用户希望将机器配置存放在哪里。默认位置为:
~/headless/<machine-name>
,这是这台计算机上的一个 Git 仓库目录,每次更新时都会复制到 Mac;用户以后可以将其推送到任意 Git 托管平台。如果用户已经在其他位置维护 nix-darwin 配置,请参阅下文的“使用自己的配置”。
询问以下选项,默认值以粗体标出:
  • 机器名称(主机名):保持当前名称,或设置新名称。
  • 启动时自动登录:开启(需要关闭 FileVault;步骤 5 会将其关闭)。明确告知用户:这样 Mac 的磁盘将不再受账户密码保护。
  • Tailscale:关闭。可以向用户提供该选项,但绝不强制启用(步骤 6)。如果 Mac 已安装 Tailscale 应用(
    /Applications/Tailscale.app
    ),仍保持此选项关闭并保留现有应用;
    apply.sh
    会拒绝启动第二个 Tailscale。
  • 附加项,每项均为开启,且每项都可以单独关闭:
    neverSleep
    、
    startAfterPowerLoss
    、
    wakeOnLan
    、
    powerNapOff
    、
    spotlightOff
    、
    siriOff
    (
    references/mac.md
    说明了每项的作用)。
然后创建文件夹:
sh
$SKILL/scripts/mac/new-config.sh ~/headless/mini \
  --address ADDRESS --login ACCOUNT --password-ref ENTRY \
  [--ssh-key ~/.ssh/id_ed25519] [--host-name NAME] [--no-auto-login] \
  [--tailscale] [--tailscale-key-ref ENTRY] [--extra-off NAME]...
它会写入
flake.nix
、
machine.nix
(用户自己的添加内容放在这里)、
settings.json
和
headless.env
(包含地址、账户、密钥和 store 条目;不含 secret)。向用户展示
settings.json
。

Step 4: First sign-in

步骤 4:首次登录

sh
$SKILL/scripts/mac/connect.sh ~/headless/mini
It pins the Mac's SSH host key in the folder's
known_hosts
and prints its fingerprint; offer the user the command to compare it at the Mac. Then it signs in once with the password from the store, adds the user's public key, and checks key sign-in works. With Automic Vault the user approves the request in its window; tell them to expect it.
sh
$SKILL/scripts/mac/connect.sh ~/headless/mini
它会将 Mac 的 SSH 主机密钥固定(pin)在文件夹的
known_hosts
中,并打印其指纹;向用户提供命令,以便他们在 Mac 上进行比对。随后,它会使用 store 中的密码登录一次,添加用户的公钥,并检查密钥登录是否正常。使用 Automic Vault 时,用户需要在其窗口中批准请求;提醒用户留意此请求。

Step 5: The admin session

步骤 5:管理员会话

sh
$SKILL/scripts/mac/admin.sh ~/headless/mini
It installs Determinate Nix (pinned version, checked hash) and, when automatic sign-in is on, stores the sign-in password macOS uses at start-up (
/etc/kcpassword
, root-only, and recoverable by anyone with root on the Mac; say so). If FileVault is on and automatic sign-in is chosen, it turns FileVault off with the same password and waits until the disk has decrypted (it can take several minutes; a restart before then would stop at FileVault's unlock screen). Only when macOS refuses - the account cannot unlock FileVault, or the organization managing the Mac forbids turning it off - it stops with a line starting
ask the user:
. Pass that on: the user turns FileVault off at the Mac (or has the Mac's managers allow it), or sets
"autoLogin": false
in
settings.json
; then run
admin.sh
again.
sh
$SKILL/scripts/mac/admin.sh ~/headless/mini
它会安装 Determinate Nix(固定版本并校验哈希值);启用自动登录时,还会存储 macOS 启动时用于登录的密码(
/etc/kcpassword
,仅 root 可读,且任何拥有 root 权限的人都能恢复;应明确告知用户)。如果 FileVault 已开启且选择了自动登录,它会使用同一个密码关闭 FileVault,并等待磁盘完成解密(可能需要几分钟;在此之前重启会停在 FileVault 解锁界面)。只有当 macOS 拒绝执行时——账户无法解锁 FileVault,或管理该 Mac 的组织禁止关闭 FileVault——脚本才会停止,并输出一行以
ask the user:
开头的内容。将该内容转达给用户:用户可以在 Mac 上关闭 FileVault(或让 Mac 的管理人员允许关闭),也可以在
settings.json
中设置
"autoLogin": false
;然后再次运行
admin.sh
。

Step 6: Apply the config

步骤 6:应用配置

sh
$SKILL/scripts/mac/apply.sh ~/headless/mini
It copies the folder to the Mac, builds the system there, and switches to it with
sudo -S
(password from the store again). The first run copies
flake.lock
back into the folder. Then commit the folder:
git -C ~/headless/mini add -A && git -C ~/headless/mini commit -m "headless: set up"
.
Tailscale (only if chosen). With
"tailscale": { "enable": true }
applied:
sh
$SKILL/scripts/mac/tailscale.sh ~/headless/mini
With
TAILSCALE_KEY_REF
set (an auth key in the store) it joins at once. Otherwise it prints a sign-in link: show it to the user, ask them to open it and approve the Mac, then run
tailscale.sh ~/headless/mini --wait
. Details:
references/tailscale.md
.
sh
$SKILL/scripts/mac/apply.sh ~/headless/mini
它会将文件夹复制到 Mac,在 Mac 上构建系统,并通过
sudo -S
切换到新配置(再次从 store 读取密码)。首次运行会将
flake.lock
复制回文件夹。随后提交该文件夹:
git -C ~/headless/mini add -A && git -C ~/headless/mini commit -m "headless: set up"
。
Tailscale(仅在用户选择时)。 应用
"tailscale": { "enable": true }
后:
sh
$SKILL/scripts/mac/tailscale.sh ~/headless/mini
如果设置了
TAILSCALE_KEY_REF
(store 中的 auth key),它会立即加入。否则,它会打印登录链接:向用户展示该链接,请用户打开链接并批准这台 Mac,然后运行
tailscale.sh ~/headless/mini --wait
。详情见
references/tailscale.md
。

Step 7: Verify, restart, verify

步骤 7:验证、重启、再次验证

sh
$SKILL/scripts/mac/verify.sh ~/headless/mini
$SKILL/scripts/mac/restart.sh ~/headless/mini
$SKILL/scripts/mac/verify.sh ~/headless/mini
verify.sh
reads every setting back (one
ok
or
FAIL
line each,
n/a
for a power setting this Mac does not have) and checks that password sign-in is refused.
restart.sh
restarts the Mac, waits until it answers again with a new boot time, and, with automatic sign-in on, until the account is signed in on the screen. Tell the user before restarting.
Finish with a short summary: what is on, what is off, where the config folder is, and how to update (below).
sh
$SKILL/scripts/mac/verify.sh ~/headless/mini
$SKILL/scripts/mac/restart.sh ~/headless/mini
$SKILL/scripts/mac/verify.sh ~/headless/mini
verify.sh
会读回每一项设置(每项输出一行
ok
或
FAIL
;如果这台 Mac 没有相应的电源设置,则输出
n/a
),并检查密码登录是否已被拒绝。
restart.sh
会重启 Mac,等待它以新的启动时间再次响应;启用自动登录时,还会等待账户在屏幕上完成登录。重启前要告知用户。
最后给出简短总结:哪些功能已开启、哪些已关闭、配置文件夹位于何处,以及如何更新(见下文)。

Later: updates

后续:更新

Edit
machine.nix
or
settings.json
in the config folder, then run
apply.sh
and
verify.sh
again. The password is read from the store each time. Turning an extra off later only stops the config managing it: the Mac keeps the value the extra set (for example, Spotlight stays off) and macOS's default does not come back. Tell the user so, and change that setting at the Mac, or add it to
machine.nix
, if they want it back. To update inputs (nixpkgs, nix-darwin, this module):
nix flake update --flake ~/headless/mini
on a computer with Nix, or delete
flake.lock
and run
apply.sh
.
在配置文件夹中编辑
machine.nix
或
settings.json
,然后再次运行
apply.sh
和
verify.sh
。每次都会从 store 读取密码。以后关闭某个附加项,只会停止配置对它的管理:Mac 会保留该附加项此前设置的值(例如 Spotlight 会继续关闭),macOS 的默认值不会自动恢复。应告知用户这一点;如果用户想恢复该设置,可以在 Mac 上进行更改,或者将其添加到
machine.nix
中。 要更新输入(nixpkgs、nix-darwin、此 module),可在安装了 Nix 的计算机上运行
nix flake update --flake ~/headless/mini
,或者删除
flake.lock
后运行
apply.sh
。

Your own config

使用自己的配置

The config folder is an ordinary nix-darwin flake whose
darwinConfigurations.machine
imports
headless.darwinModules.headless
. A user with an existing nix-darwin flake can instead add this repository as an input, import the module in their own host, set
headless.*
options, and expose the host as
darwinConfigurations.machine
in a folder these scripts copy; the scripts only need
headless.env
and that output name. See
references/mac.md
for the module's options.
On NixOS it works the same way: the folder's
flake.nix
exposes
nixosConfigurations.machine
, which imports
headless.nixosModules.headless
and sets
headless.*
(
references/linux.md
lists the options). A folder with its own
flake.nix
is used as it is:
apply.sh
copies and builds it and brings nothing in from
/etc/nixos
. Keep
settings.json
(from
new-config.sh
) beside it:
apply.sh
checks it and
verify.sh
reads the machine's own record. Expose the host under its host name too if
nixos-rebuild switch
at the machine should find it without
--flake /etc/nixos#machine
.
配置文件夹是一个普通的 nix-darwin flake,其
darwinConfigurations.machine
会导入
headless.darwinModules.headless
。已有 nix-darwin flake 的用户也可以将本仓库添加为 input,在自己的 host 中导入该 module,设置
headless.*
选项,并在这些脚本所复制的文件夹中将该 host 暴露为
darwinConfigurations.machine
;脚本只需要
headless.env
和该输出名称。module 的选项见
references/mac.md
。
在 NixOS 上的工作方式相同:文件夹的
flake.nix
会暴露
nixosConfigurations.machine
,导入
headless.nixosModules.headless
并设置
headless.*
(
references/linux.md
列出了这些选项)。带有自身
flake.nix
的文件夹会按原样使用:
apply.sh
会复制并构建它,不会从
/etc/nixos
引入任何内容。请将
settings.json
(由
new-config.sh
生成)放在同一目录中:
apply.sh
会检查它,
verify.sh
会读取机器自身的记录。如果希望机器上的
nixos-rebuild switch
无需使用
--flake /etc/nixos#machine
就能找到该 host,还应以其主机名暴露该 host。

When something fails

发生失败时

  • Read the script's last
    headless:
    line; it says what failed and what to do.
    references/mac.md
    lists the common cases.
  • A changed host key stops every step on purpose. Ask the user whether the Mac was reinstalled before removing the folder's
    known_hosts
    .
  • Never work around a failed step by turning on password sign-in, adding a sudo rule, or printing the secret.
  • 读取脚本最后一行
    headless:
    ;它会说明失败原因及处理方式。常见情况见
    references/mac.md
    。
  • 主机密钥发生变化时,脚本会故意停止所有步骤。删除文件夹中的
    known_hosts
    前,先询问用户该 Mac 是否重新安装过。
  • 绝不通过启用密码登录、添加 sudo 规则或打印 secret 来绕过失败的步骤。

Linux machines

Linux 机器

The same rules hold. The scripts are in
scripts/linux/
; details, options and failure cases are in
references/linux.md
.
L1. Admin access (the user does this). Ask the user to confirm the machine runs an SSH server they can reach, has an account with a password that may use
sudo
(in the
sudo
or
wheel
group), and its address. Root is not used as the login.
L2. The password store and key: step 2 above, unchanged.
L3. The config folder. Same questions as step 3, with Linux's extras:
neverSleep
and
autoUpdates
, each on. Automatic sign-in on Linux means the account's own session (its user services) starts at boot without anyone signing in; nothing signs in on a screen.
sh
$SKILL/scripts/linux/new-config.sh ~/headless/box \
  --address ADDRESS --login ACCOUNT --password-ref ENTRY \
  [--ssh-key ~/.ssh/id_ed25519] [--host-name NAME] [--no-auto-login] \
  [--tailscale] [--tailscale-key-ref ENTRY] [--extra-off NAME]...
L4. First sign-in.
$SKILL/scripts/linux/connect.sh ~/headless/box
, as in step 4. Its last lines say which distribution the machine runs and what comes next.
L5. NixOS, or not.
  • It runs NixOS: go to L6. The first
    apply.sh
    copies the machine's own
    /etc/nixos
    into the folder (
    nixos/
    ), so its boot loader, disks and other settings stay, and the machine stays on the NixOS release it runs (such as 26.05, read from root's channel). If
    apply.sh
    cannot tell the release, it stops; ask the user which one and pass
    --nixos-branch nixos-26.05
    (or
    nixos-unstable
    ). Ask the user to check that copy holds nothing private before they push the folder anywhere. From then on each
    apply.sh
    puts the folder in
    /etc/nixos
    (the old one is kept as
    /etc/nixos.before-headless
    ), so
    nixos-rebuild switch
    and automatic updates at the machine build the same setup; an automatic update takes the newest nixpkgs of the machine's release, and once the machine boots a system built from it,
    apply.sh
    keeps that newer one and writes it into the folder's
    flake.lock
    to commit.
  • Any other distribution: offer to replace it with NixOS, using nixos-anywhere. Say plainly: this erases the whole disk, everything on it is gone, and it needs Nix on this computer, an x86_64 or aarch64 machine with 2 GB of memory and Secure Boot off. The machine keeps its address (a fixed one is written into the new setup), SSH host key and the account's password; it needs the machine reached at an IPv4 address on its wired network card, and stops, changing nothing, otherwise. If the user agrees:
    sh
    $SKILL/scripts/linux/install-nixos.sh ~/headless/box --list-disks
    $SKILL/scripts/linux/install-nixos.sh ~/headless/box --disk /dev/DISK --yes-wipe
    Show the disk list and have the user name the disk; pass
    --yes-wipe
    only after they agreed to erase that disk. It takes 5 to 20 minutes.
  • The user keeps their distribution (Debian, Ubuntu or Fedora): go to L6;
    apply.sh
    runs the distro-neutral script instead.
L6. Apply, then verify, restart, verify.
sh
$SKILL/scripts/linux/apply.sh ~/headless/box
$SKILL/scripts/linux/verify.sh ~/headless/box
$SKILL/scripts/linux/restart.sh ~/headless/box
$SKILL/scripts/linux/verify.sh ~/headless/box
On NixOS
apply.sh
builds the system on the machine and switches to it; on another distribution it runs the script, which prints one
changed:
line per change and none when run again. Commit the folder afterwards. For Tailscale, run
$SKILL/scripts/linux/tailscale.sh ~/headless/box
as in step 6.
restart.sh
restarts the machine, waits for a new boot, and with automatic sign-in on checks the session started before anyone signed in. Tell the user before restarting.
Updates: edit
settings.json
(or
machine.nix
on NixOS) and run
apply.sh
and
verify.sh
again. Other distributions install updates by themselves (
autoUpdates
). On NixOS, delete
flake.lock
and run
apply.sh
to move to newer inputs on the same release.
适用同样的规则。脚本位于
scripts/linux/
;详情、选项和失败情况见
references/linux.md
。
L1. 管理员访问权限(由用户操作)。 请用户确认机器运行着可访问的 SSH server,有一个可使用
sudo
的带密码账户(位于
sudo
或
wheel
组中),并知道其地址。不使用 root 作为登录账户。
**L2. 密码 store 和密钥:**与步骤 2 相同,不作改动。
L3. 配置文件夹。 与步骤 3 使用相同的问题,并增加 Linux 的附加项:
neverSleep
和
autoUpdates
,两项均为开启。Linux 上的自动登录是指账户自身的 session(其 user services)会在启动时运行,而无需有人在屏幕上登录。
sh
$SKILL/scripts/linux/new-config.sh ~/headless/box \
  --address ADDRESS --login ACCOUNT --password-ref ENTRY \
  [--ssh-key ~/.ssh/id_ed25519] [--host-name NAME] [--no-auto-login] \
  [--tailscale] [--tailscale-key-ref ENTRY] [--extra-off NAME]...
L4. 首次登录。
$SKILL/scripts/linux/connect.sh ~/headless/box
,与步骤 4 相同。其最后几行会说明机器运行的发行版以及后续操作。
L5. 使用 NixOS,或不使用。
  • **机器运行 NixOS:**进入 L6。首次运行
    apply.sh
    时,会将机器自身的
    /etc/nixos
    复制到文件夹中(
    nixos/
    ),从而保留其 bootloader、磁盘和其他设置,并让机器继续使用当前运行的 NixOS release(例如 26.05,该版本从 root 的 channel 读取)。如果
    apply.sh
    无法确定 release,它会停止;询问用户具体版本,并传入
    --nixos-branch nixos-26.05
    (或
    nixos-unstable
    )。请用户在将文件夹推送到任何位置前检查该副本是否包含隐私数据。从此以后,每次运行
    apply.sh
    都会将文件夹放入
    /etc/nixos
    (旧版本保留为
    /etc/nixos.before-headless
    ),因此机器上的
    nixos-rebuild switch
    和自动更新会构建相同的配置;自动更新会获取该 release 中最新的 nixpkgs,而机器启动由这些输入构建的系统后,
    apply.sh
    会保留较新的版本,并将其写入文件夹的
    flake.lock
    以供提交。
  • 其他发行版:可以使用 nixos-anywhere 提供将其替换为 NixOS的选项。明确说明:这会擦除整个磁盘,磁盘上的所有内容都会丢失;此操作要求当前计算机已安装 Nix,目标机器为 x86_64 或 aarch64 架构、内存不少于 2 GB,并关闭 Secure Boot。机器会保留其地址(新配置中会写入一个固定地址)、SSH 主机密钥和账户密码;必须能够通过有线网络卡的 IPv4 地址访问机器,否则脚本会停止且不更改任何内容。如果用户同意:
    sh
    $SKILL/scripts/linux/install-nixos.sh ~/headless/box --list-disks
    $SKILL/scripts/linux/install-nixos.sh ~/headless/box --disk /dev/DISK --yes-wipe
    展示磁盘列表,并让用户指定磁盘;只有在用户同意擦除该磁盘后,才能传入
    --yes-wipe
    。整个过程需要 5 到 20 分钟。
  • 用户保留现有发行版(Debian、Ubuntu 或 Fedora):进入 L6;
    apply.sh
    会改为运行发行版无关的脚本。
L6. 应用,然后验证、重启、再次验证。
sh
$SKILL/scripts/linux/apply.sh ~/headless/box
$SKILL/scripts/linux/verify.sh ~/headless/box
$SKILL/scripts/linux/restart.sh ~/headless/box
$SKILL/scripts/linux/verify.sh ~/headless/box
在 NixOS 上,
apply.sh
会在机器上构建系统并切换到该系统;在其他发行版上,它会运行相应脚本。脚本每项更改都会打印一行
changed:
,重复运行时不会打印任何更改。随后提交文件夹。Tailscale 的处理方式与步骤 6 相同,运行
$SKILL/scripts/linux/tailscale.sh ~/headless/box
。
restart.sh
会重启机器并等待新的启动;启用自动登录时,还会检查 session 是否在无人登录前就已启动。重启前要告知用户。
更新:编辑
settings.json
(NixOS 上则编辑
machine.nix
),然后再次运行
apply.sh
和
verify.sh
。其他发行版会自行安装更新(
autoUpdates
)。在 NixOS 上,删除
flake.lock
并运行
apply.sh
,即可在同一 release 上切换到更新的 inputs。

Windows machines

Windows 机器

The same rules hold; an SSH session of an administrator on Windows is already elevated, so there is no
sudo
and the password is only read for automatic sign-in. The scripts are in
scripts/windows/
; details, options and failure cases are in
references/windows.md
.
W1. Admin access and OpenSSH Server (the user does this). Ask the user to confirm, at the PC, that it has a local administrator account with a password (not a Microsoft account: automatic sign-in and SSH need a local one), and its address (Settings > Network & internet > Properties). The account's name may use letters, digits, dots, dashes and underscores (at most 20; case does not matter). If its name has a space or any other character, the skill cannot use it: ask the user to make another local administrator account for it, such as
headless
(
references/windows.md
). Then ask them to open Windows PowerShell as administrator (right-click Start > Terminal (Admin)) and paste these lines, which install and start OpenSSH Server:
powershell
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
Set-Service -Name sshd -StartupType Automatic
Start-Service sshd
The first line takes a few minutes. OpenSSH's firewall rule lets SSH in only on a Private network, and Windows makes a new network Public. Ask whether this network is their home or office network (Settings
Network & internet shows "Public network" or "Private network"); if it is, and it says Public, have them also paste this line, which marks the networks the PC is on now as Private:
powershell
Get-NetConnectionProfile | Set-NetConnectionProfile -NetworkCategory Private
references/windows.md
says what to do if a line fails.
W2. The password store and key: step 2 above, unchanged.
W3. The config folder. Same questions as step 3, with Windows's extras, each on:
neverSleep
,
powerButtonShutsDown
,
hideSleep
,
updatesOvernight
(
references/windows.md
says what each does). A Windows host name is at most 15 characters.
--login
takes the account name as Windows shows it, in any case; a name with a space is refused, so use the other administrator account from W1.
sh
$SKILL/scripts/windows/new-config.sh ~/headless/pc \
  --address ADDRESS --login ACCOUNT --password-ref ENTRY \
  [--ssh-key ~/.ssh/id_ed25519] [--host-name NAME] [--no-auto-login] \
  [--tailscale] [--tailscale-key-ref ENTRY] [--extra-off NAME]...
It writes
settings.json
,
headless.env
and
machine.ps1
(the user's own PowerShell additions, run after the headless settings on every apply).
W4. First sign-in.
$SKILL/scripts/windows/connect.sh ~/headless/pc
, as in step 4. The key goes in
C:\ProgramData\ssh\administrators_authorized_keys
(readable by Administrators and SYSTEM only). Its last lines say which Windows the machine runs.
W5. Apply.
$SKILL/scripts/windows/apply.sh ~/headless/pc
copies the folder to
C:\ProgramData\headless
and applies it. It prints one
changed:
line per change and none when run again. With automatic sign-in on, it pipes the password from the store and Windows keeps it as an LSA secret, never as plain text in the registry; any administrator of the PC can still read it back (say so). Commit the folder afterwards. For Tailscale, run
$SKILL/scripts/windows/tailscale.sh ~/headless/pc
as in step 6; an existing Tailscale install is kept, and
apply.sh
sets its unattended policy so it runs before anyone signs in. One that another Windows account joined with Run unattended stays that account's; one it joined without it signs out at the next restart, and
tailscale.sh
then joins it as the skill's account. To have the skill own it sooner, ask, then
tailscale.sh ~/headless/pc --uninstall
,
apply.sh
and
tailscale.sh
(
references/windows.md
).
W6. Verify, restart, verify.
sh
$SKILL/scripts/windows/verify.sh ~/headless/pc
$SKILL/scripts/windows/restart.sh ~/headless/pc
$SKILL/scripts/windows/verify.sh ~/headless/pc
A new host name takes effect at this restart.
restart.sh
waits for a new boot and, with automatic sign-in on, for the account to be signed in on the screen. Tell the user before restarting, and when verify's Tailscale line says "otherwise it signs out at the next restart", say that this restart signs it out unless that account chose Run unattended, and that
tailscale.sh
then joins it as the skill's account.
Updates: edit
settings.json
or
machine.ps1
and run
apply.sh
and
verify.sh
again. Windows installs its own updates;
updatesOvernight
keeps their restarts to the night. Turning an extra off later stops managing it and leaves the value it set.
适用同样的规则;Windows 上管理员的 SSH session 已经具有提升权限,因此没有
sudo
,密码只会在配置自动登录时读取。脚本位于
scripts/windows/
;详情、选项和失败情况见
references/windows.md
。
W1. 管理员访问权限和 OpenSSH Server(由用户操作)。 请用户直接在 PC 上确认:它有一个带密码的本地管理员账户(不能使用 Microsoft 账户:自动登录和 SSH 需要本地账户),并知道其地址(Settings > Network & internet > Properties)。账户名称可以包含字母、数字、点、短划线和下划线(最多 20 个字符;大小写无关)。如果名称中包含空格或其他字符,此 skill 将无法使用它:请用户创建另一个本地管理员账户,例如
headless
(
references/windows.md
)。
然后请用户以管理员身份打开 Windows PowerShell(右键点击 Start > Terminal (Admin)),并粘贴以下命令,以安装和启动 OpenSSH Server:
powershell
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
Set-Service -Name sshd -StartupType Automatic
Start-Service sshd
第一行需要几分钟。OpenSSH 的防火墙规则只允许通过 Private 网络连接 SSH,而 Windows 会将新网络设置为 Public。询问该网络是家庭网络还是办公室网络(Settings > Network & internet 会显示“Public network”或“Private network”);如果它显示为 Public,请用户同时粘贴以下命令,将 PC 当前所在网络标记为 Private:
powershell
Get-NetConnectionProfile | Set-NetConnectionProfile -NetworkCategory Private
如果某一行失败,应如何处理见
references/windows.md
。
**W2. 密码 store 和密钥:**与步骤 2 相同,不作改动。
W3. 配置文件夹。 与步骤 3 使用相同的问题,并增加 Windows 的附加项,每项均为开启:
neverSleep
、
powerButtonShutsDown
、
hideSleep
、
updatesOvernight
(
references/windows.md
说明了每项的作用)。Windows 主机名最多为 15 个字符。
--login
接受 Windows 中显示的账户名称,大小写任意;如果名称中包含空格,命令会被拒绝,因此应使用 W1 中创建的另一个管理员账户。
sh
$SKILL/scripts/windows/new-config.sh ~/headless/pc \
  --address ADDRESS --login ACCOUNT --password-ref ENTRY \
  [--ssh-key ~/.ssh/id_ed25519] [--host-name NAME] [--no-auto-login] \
  [--tailscale] [--tailscale-key-ref ENTRY] [--extra-off NAME]...
它会写入
settings.json
、
headless.env
和
machine.ps1
(用户自己的 PowerShell 添加内容会在每次 apply 时于 headless 设置之后运行)。
W4. 首次登录。
$SKILL/scripts/windows/connect.sh ~/headless/pc
,与步骤 4 相同。密钥会被放入
C:\ProgramData\ssh\administrators_authorized_keys
(仅 Administrators 和 SYSTEM 可读取)。其最后几行会说明机器运行的 Windows 版本。
W5. 应用。
$SKILL/scripts/windows/apply.sh ~/headless/pc
会将文件夹复制到
C:\ProgramData\headless
并应用配置。它每项更改都会打印一行
changed:
,重复运行时不会打印任何更改。启用自动登录时,它会从 store 管道传入密码,Windows 会将其保存为 LSA secret,而不会以明文形式保存在注册表中;PC 上的任何管理员仍可将其读回(应明确告知用户)。随后提交文件夹。
对于 Tailscale,与步骤 6 相同,运行
$SKILL/scripts/windows/tailscale.sh ~/headless/pc
;已有的 Tailscale 安装会被保留,
apply.sh
会设置其无人值守策略,使其在任何人登录前运行。如果某个 Windows 账户使用 Run unattended 加入,该安装会继续属于该账户;如果未使用 Run unattended 加入,则会在下次重启时退出,随后
tailscale.sh
会使用此 skill 的账户重新加入。如需让此 skill 更早接管,请先征得用户同意,然后依次运行
tailscale.sh ~/headless/pc --uninstall
、
apply.sh
和
tailscale.sh
(
references/windows.md
)。
W6. 验证、重启、再次验证。
sh
$SKILL/scripts/windows/verify.sh ~/headless/pc
$SKILL/scripts/windows/restart.sh ~/headless/pc
$SKILL/scripts/windows/verify.sh ~/headless/pc
新主机名会在此次重启时生效。
restart.sh
会等待机器完成新的启动;启用自动登录时,还会等待账户在屏幕上完成登录。重启前要告知用户。当 verify 的 Tailscale 一行提示“否则它会在下次重启时退出”时,应告知用户:此次重启会导致其退出,除非该账户选择了 Run unattended;随后
tailscale.sh
会使用此 skill 的账户重新加入。
更新:编辑
settings.json
或
machine.ps1
,然后再次运行
apply.sh
和
verify.sh
。Windows 会自行安装更新;
updatesOvernight
会将更新引起的重启安排在夜间。以后关闭某个附加项只会停止管理该设置,并保留它此前设置的值。