Hi everyone,
I’m trying to deploy NixOS configurations from my macOS machine to a remote x86_64-linux server using nixos-rebuild-ng. I’m running into an issue where evaluation happens locally on macOS, but my configuration references sops-nix secrets that only exist on the target machine.
Current Setup
- Controller: macOS with nix-darwin and flakes
- Target: NixOS x86_64-linux server
- Secrets: Managed with sops-nix, using age keys derived from SSH keys
secrets/default.nix:
{ ... }:
{
sops = {
defaultSopsFile = ./secrets.yaml;
age.sshKeyPaths = [ "/root/.ssh/id_ed25519" ];
age.generateKey = true;
secrets = {
"pangolin/newt_id" = {};
"pangolin/newt_secret" = {};
"ssh_keys/dobrynikolov" = {};
"ssh_keys/dobrynikolov.pub" = {};
"ssh_keys/engineer" = {};
"ssh_keys/engineer.pub" = {};
};
};
}
Deployment command:
nixos-rebuild-ng switch \
--flake ".#engineer" \
--target-host "root@192.168.1.6" \
--build-host "root@192.168.1.6" \
--sudo \
--impure
The Problem
My NixOS configuration uses openssh.authorizedKeys.keyFiles that reference sops secrets:
users.users.engineer = {
openssh.authorizedKeys.keyFiles = [
config.sops.secrets."ssh_keys/dobrynikolov.pub".path # /run/secrets/ssh_keys/dobrynikolov
config.sops.secrets."ssh_keys/engineer.pub".path
];
};
When I run the deployment, evaluation happens locally on macOS (despite --build-host), and it fails with:
error: opening file '/private/var/run/secrets/ssh_keys/dobrynikolov.pub': No such file or directory
inb4 store .pub secrets in plain text
Issue comes up with other secrets aswell
This path (/run/secrets/...) only exists on the target NixOS machine after sops-nix decrypts secrets during activation.
What I’ve Tried
- Using
--build-host- doesn’t change where evaluation happens - Using
--impureflag - still evaluates locally
My Questions
-
Is there a way to make
nixos-rebuildevaluate the configuration on the remote machine instead of locally? -
What’s the recommended pattern for using sops-nix secrets in configurations when deploying cross-platform (macOS → Linux)? Should I:
- Use activation scripts instead of
authorizedKeys.keyFiles? - Accept that I need to rsync the flake and run
nixos-rebuilddirectly on the target?
- Use activation scripts instead of
-
Is there an
--eval-hostor equivalent flag I’m missing that would solve this?
Workaround I’m Considering
The only solution I can think of is:
rsync -az ./ root@192.168.1.6:/tmp/deploy/
ssh root@192.168.1.6 "cd /tmp/deploy && nixos-rebuild switch --flake .#engineer"
But this defeats the purpose of nixos-rebuild’s remote deployment features.
Thanks in advance!