在 macOS Catalina 和 Big Sur 上在没有 T2 芯片的 Mac 上的 FileVault 加密启动卷上安装 Nix 时出错

问题描述

我运行以下命令在我的 Mac 上安装 Nix:

sh <(curl -L https://nixos.org/nix/install) --daemon --darwin-use-unencrypted-nix-store-volume

我收到以下错误

error: refusing to create Nix store volume because the boot volume is
       filevault encrypted,but encryption-at-rest is not available.
       Manually create a volume for the store and re-run this script.
       See https://nixos.org/nix/manual/#sect-macos-installation

https://nixos.org/nix/manual/#sect-macos-installation 说:

如果您使用的是带有 T2 chip 的最新 Mac,您的驱动器仍会在静止状态下加密(在这种情况下,“未加密”有点用词不当)。要使用这种方法,只需安装 Nix:

sh <(curl -L https://nixos.org/nix/install) --darwin-use-unencrypted-nix-store-volume

如果您不喜欢这样的声音,您需要权衡本节中详述的其他方法和权衡。

我没有带 T2 芯片的 Mac,我该怎么办?

我找到了一些相关的 github issues,但没有直接的答案。

解决方法

我选择使用 Use a separate encrypted volume 中概述的 Philipp Haussleiter 建议:

此方法仅适用于使用 APFS 格式化的磁盘(如果您的操作系统运行的是 SSD,则应始终如此)。

您可以通过以下方式检查:

% diskutil list | grep APFS

…
0:      APFS Container Scheme -                      +250.8 GB   disk1
…

在磁盘上为 NIX 创建另一个卷:

% sudo diskutil apfs addVolume disk1 'APFS' nix
Will export new APFS Volume "nix" from APFS Container Reference disk1
Started APFS operation on disk1
Preparing to add APFS Volume to APFS Container disk1
Creating APFS Volume
Created new APFS Volume disk1s6
Mounting APFS Volume
Setting volume permissions
Disk from APFS operation: disk1s6
Finished APFS operation on disk1

您的磁盘可能未命名为 disk1s6。使用以下命令查找磁盘名称:

% diskutil list | grep nix
4:                APFS Volume nix                      7.7 GB    disk1s6

同样,您的磁盘可能没有命名为 disk1s6

加密磁盘:

您需要输入密码进行加密。你必须 记住密码短语一次 - 您可以稍后将其添加到您的钥匙串中 在。之后磁盘加密将在后台启动。

% sudo diskutil apfs encryptvolume disk1s6 -user disk
Passphrase for the new "Disk" user (672C4CFF-34C6-4407-83ED-294C1C42E161):
Repeat passphrase:
Starting background encryption with the new "Disk" crypto user on disk1s6
The new "Disk" user will be the only one who has initial access to disk1s6
The new APFS crypto user UUID will be 672C4CFF-34C6-4407-83ED-294C1C42E161
Background encryption is ongoing; see "diskutil apfs list" to see progress

设置挂载点:

MacOS Catalina 不允许直接在您的目录下创建文件夹 根路径 /。但是我们可以使用另一种方法让 MacOS 创建 文件夹给我们。为此,我们必须在文件中添加一个条目 /etc/synthetic.conf

% sudo bash -c 'echo nix >> /etc/synthetic.conf'

现在,下次系统启动时,挂载点 /nix 将是 创建。下一个任务是在启动时安装我们的卷。

设置挂载:

对于挂载配置,我们需要卷的 UUID。我们可以 通过 diskutil 工具找到它(同样,您的磁盘可能没有命名 disk1s6):

% diskutil info /dev/disk1s6 | grep UUID

我们必须用 vifs 编辑 /etc/fstab:

% sudo vifs

(vifs 的行为就像 vi,所以使用 vi 命令来编辑文件):

UUID=1D9389C1-5676-4077-88F5-8D5304A0B1A6 /nix apfs  rw

(你的 UUID 会有所不同!)

重新启动。您将收到一个 GUI 提示,输入您的加密密码, 并将其保存到钥匙串中。

Encrypted Volume Keychain Prompt After Restart

然后我跑了:

sh <(curl -L https://nixos.org/nix/install) --daemon

--darwin-use-unencrypted-nix-store-volume 选项不是必需的,因为我们现在有一个加密卷。