How to hide my DNS resolver from the config

I currently use NextDNS and I have my DNS config like this:

nameservers = [
  "45.90.28.0#000000.dns.nextdns.io"
  "2a07:a8c0::#000000.dns.nextdns.io" 
  "45.90.30.0#000000.dns.nextdns.io"
  "2a07:a8c1::#000000.dns.nextdns.io"
];

(Of course changing the actual ID to 000000)

The problem is that I have my config on Github and would like to make it public, so I need to hide this ID. I already use sops-nix to hide passwords and other stuff, but I could not find a way to do this. Is there any other way?

This is a pretty frequent question. There are effectively two options, git-crypt, or you maintain a second configuration in a private repository that is imported by the public one to add the sensitive options. Flakes are usually used for the latter, but you can also achieve that in a traditional config with fetchFromGitHub.

This is assuming the values aren’t actually secret secret but just sensitive. If they are secrets, then this particular NixOS module does not support treating these values as secret and you would have to write your own that does permit reading the values from a file so you can use sops - or of course patch the upstream one and contribute so everyone can benefit :wink:

I don’t think that’s true for nextdns IDs (can DNS-over-TLS/HTTPS server URLs be intercepted by recursive DNS servers? I think so?) and that’d be an awfully small entropy if it were, so treating it as sensitive is probably fine, but I’ve never used the service myself.

1 Like

Hey, I don’t know about the interception thing, but I just don’t want my ID to be public. I found a solution with their own client, which has a config-file argument. So I’m using it like this:

services.nextdns = {
  enable = true;
  arguments = [
    "-config-file"
    "${config.sops.secrets.nextdnsID.path}"
  ];
};

networking.nameservers = [
  "127.0.0.1"
  "::1"
];

As you can see it was solved with sops-nix, which is quite neat as I already use it so I won’t have to use another tool for the job.

Thanks for the explanation!

1 Like

@arthsmn Thanks for the solution. Quick question - what do you have stored in the nextdnsID? I’d like to also pass in some settings to build the config. sops-nix doesn’t allow for multiline strings right?

It does, see yaml syntax: Quoting - Learn - yaml.info

Basically:

literal block scalar: |
  a multiline text
  line 2
  line 3
1 Like

Hmm… interesting. I did try that initially. I was getting a similar error from sops-nix when I had my config in non-string form. Let me try again, maybe I had a syntax error.

@TLATER ah seems like I had an error in my config. Thank you!