如何在我的点文件中插入 configuration.nix 文件?

How to insert the configuration.nix file inside my dot files?

我正在按照此 tutorial 创建我的点文件。它成功适用于 emacs.d.

由于我使用的是 NixOS,因此我尝试对 configuration.nix 文件的符号链接创建执行完全相同的步骤。因此,我做了:

1 - 在终端上:

[pedro@system:/etc/nixos]$ sudo mv /etc/nixos/configuration.nix ~/.dotfiles/

2 - 然后:

[pedro@system:/etc/nixos]$ ln -sf ~/.dotfiles/configuration.nix configuration.nix~  

3 - 它似乎工作正常,就像我一样:

[pedro@system:/etc/nixos]$ ls -la
total 12
drwxr-xr-x  2 root root 4096 Dec  1 21:41 .
drwxr-xr-x 32 root root 4096 Dec  1 22:00 ..
lrwxrwxrwx  1 root root   39 Dec  1 21:41 configuration.nix~ -> /home/pedro/.dotfiles/configuration.nix
-rw-r--r--  1 root root  842 Nov 12 17:40 hardware-configuration.nix

在完成一些版本并保存更改后,我无法做到 nixos-rebuild switch。它抛出一个错误:

[pedro@system:/etc/nixos]$ sudo nixos-rebuild switch 
warning: Nix search path entry '/etc/nixos/configuration.nix' does not exist, ignoring
error: file 'nixos-config' was not found in the Nix search path (add it using $NIX_PATH or -I), at /nix/var/nix/profiles/per-user/root/channels/nixos/nixos/default.nix:1:60
(use '--show-trace' to show detailed location information)
building Nix...
warning: Nix search path entry '/etc/nixos/configuration.nix' does not exist, ignoring
error: file 'nixos-config' was not found in the Nix search path (add it using $NIX_PATH or -I), at /nix/var/nix/profiles/per-user/root/channels/nixos/nixos/default.nix:1:60
(use '--show-trace' to show detailed location information)
building the system configuration...
warning: Nix search path entry '/etc/nixos/configuration.nix' does not exist, ignoring
error: file 'nixos-config' was not found in the Nix search path (add it using $NIX_PATH or -I), at /nix/var/nix/profiles/per-user/root/channels/nixos/nixos/default.nix:1:60
(use '--show-trace' to show detailed location information)

configuration.nix~ 之后的 ~ 可能是这里的问题。我该如何解决这个问题?

谢谢!

你的第 2 步似乎导致了这里的问题:符号链接应该被称为 configuration.nix 而不是你已经注意到的 configuration.nix~

您可以通过 /etc/nixos 文件夹中的 运行 mv configuration.nix~ configuration.nix 修复此问题,这会将 configuration.nix~ 重命名为正确的 configuration.nix.