Sops won't create a secrets.yaml file

  • My NixOS config root directly is called nix-main
  • I have my .sops.yaml file in that root directory
  • I am trying to create a secrets.yaml file in a host machine directory like nix-main/hosts/desktop/secrets.yaml
  • when I run from my nix config root directory

sops hosts/desktop/secrets.yaml

it will open up the nano editor, I will make the changes I want on the boiler plate that comes up and I try to save/exit and it always gives the following error:

Could not open in-place file for writing: open /hosts/desktop/secrets.yaml: no such file or directory

  1. I thought that by running the sops command it could create the file, I didn’t need to have a pre-existing one.
  2. If I do create an empty one first, it will still open up it’s own boiler plate one instead of the one I created and will give the same error after editing and saving

I see an important one-character difference between these lines:

sops  hosts/desktop/secrets.yaml
open /hosts/desktop/secrets.yaml: no such file or directory
     ^ this character

You told it to create a file at a relative path – hosts/desktop/secrets.yaml below your NixOS config root – but it’s trying to write to the absolute path /hosts/desktop/secrets.yaml instead, and failing, because that’s the wrong place.

That strikes me as a bug. I have sops 3.9.4 and it handles relative paths correctly, maybe you have a different version?

You may be able to work around the bug by giving sops an absolute path instead: try this command

sops $(pwd)/hosts/desktop/secrets.yaml
1 Like

Thank you, I’m embarrassed that a little character difference like that I didn’t catch. But you’re right that difference is what caused the error.

Those tiny differences are easy to miss because they are tiny. Don’t beat yourself up over it :slight_smile:

1 Like