Im trying to configure sops but it fails to start.
❯ systemctl --user status sops-nix.service
○ sops-nix.service - sops-nix activation
Loaded: loaded (/home/felipepinto/.config/systemd/user/sops-nix.service; enabled; preset: ignored)
Active: inactive (dead) since Thu 2025-02-20 13:07:42 WET; 29min ago
Invocation: 8e8e503234044545a586ba41acfab11e
Process: 2005 ExecStart=/nix/store/lp7lnzws9sl3k6ysqk30y5xv89a256fh-sops-nix-user (code=exited, status=1/FA>
Main PID: 2005 (code=exited, status=1/FAILURE)
Mem peak: 25.6M
CPU: 19ms
fev 20 13:07:42 gmktecK8 systemd[1985]: Starting sops-nix activation...
fev 20 13:07:42 gmktecK8 lp7lnzws9sl3k6ysqk30y5xv89a256fh-sops-nix-user[2005]: generating machine-specific age key...
fev 20 13:07:42 gmktecK8 lp7lnzws9sl3k6ysqk30y5xv89a256fh-sops-nix-user[2013]: /nix/store/wdap4cr3bnm685f27y9bb6q5b6q18msl-coreutils-9.5/bin/mkdir: cannot create directory ‘/var/lib/sops-nix’: Permission denied
fev 20 13:07:42 gmktecK8 lp7lnzws9sl3k6ysqk30y5xv89a256fh-sops-nix-user[2020]: age-keygen: error: failed to open output file "/var/lib/sops-nix/key.txt": open /var/lib/sops-nix/key.txt: no such file or directory
fev 20 13:07:42 gmktecK8 lp7lnzws9sl3k6ysqk30y5xv89a256fh-sops-nix-user[2020]: age-keygen: report unexpected or unhelpful errors at https://filippo.io/age/report
fev 20 13:07:42 gmktecK8 lp7lnzws9sl3k6ysqk30y5xv89a256fh-sops-nix-user[2029]: Cannot read ssh key '/etc/ssh/ssh_host_ed25519_key': open /etc/ssh/ssh_host_ed25519_key: permission denied
fev 20 13:07:42 gmktecK8 lp7lnzws9sl3k6ysqk30y5xv89a256fh-sops-nix-user[2029]: /nix/store/5l7m96290y8546fx7803i23v4lldfwd9-sops-install-secrets-0.0.1/bin/sops-install-secrets: cannot read keyfile '/var/lib/sops-nix/key.txt': open /var/lib/sops-nix/key.txt: no such file o>
fev 20 13:07:42 gmktecK8 systemd[1985]: sops-nix.service: Main process exited, code=exited, status=1/FAILURE
fev 20 13:07:42 gmktecK8 systemd[1985]: sops-nix.service: Failed with result 'exit-code'.
fev 20 13:07:42 gmktecK8 systemd[1985]: Failed to start sops-nix activation.
~
i configured sops like this:
{ lib, config, inputs, pkgs, ... }:
{
imports = [ inputs.sops-nix.nixosModules.sops ];
options.modules.security.sops.enable =
lib.mkEnableOption "enable sops module";
config = lib.mkIf config.modules.security.sops.enable {
environment.systemPackages = [ pkgs.sops ];
sops = {
defaultSopsFormat = "yaml";
# This will add secrets.yml to the nix store
# You can avoid this by adding a string to the full path instead, i.e.
# defaultSopsFile = ../../../secrets/secrets.yaml;
defaultSopsFile = "/root/.sops/secrets/secrets.yaml";
# defaultSopsFile = ./secrets/example.yaml;
# This will automatically import SSH keys as age keys
age.sshKeyPaths = [ "/etc/ssh/ssh_host_ed25519_key" ];
# This is using an age key that is expected to already be in the filesystem
age.keyFile = "/var/lib/sops-nix/key.txt";
# This will generate a new key if the key specified above does not exist
age.generateKey = true;
};
};
}