Backslash in String readFile Issue?

I want to read a file with a public SSH key,

client_public_key = builtins.readFile ./;


openssh.authorizedKeys.keys = [ client_public_key ];

for a user. But I cannot login.

If I paste and copy the string in the configuration manually it works OK…

client_public_key = "..I50j\vdMu..";

But, I noticed if I query,

nix-instantiate --eval --strict --attr config.users...openssh.authorizedKeys.keys ./nixos.nix

the returned key has an extra backslash:


Could this be the problem? readFile escapes the backslash?

Am I doing something silly to cause this? Or missing something obvious?

Just remove the backslash.
A string like "\v" in Nix is equal to "v", but when you use builtins.readFile it will preserve the backslash and you get an invalid key.

Edit: you can easily test things like this in the nix repl:

nix-repl> builtins.readFile ./foo

nix-repl> "\v"
1 Like