Seems my hosts file (/etc/hosts) points to /nix/store/gds7bha3bx0a22pnzw93pgf0666anpyr-etc-hosts and is read only.

How am I meant to modify this file?

1 Answer 1


Modify the nixos config with:

networking.extraHosts =
  '' other-localhost server
  • It sounds like it could be an answer; perhaps Chris could use some extra words to explain what this is and why it works?
    – Jeff Schaller
    Dec 17, 2018 at 16:22
  • 2
    Perhaps a reference could be github.com/NixOS/nixpkgs/blob/master/nixos/modules/config/…
    – Jeff Schaller
    Dec 17, 2018 at 16:36
  • When I reviewing, I thought that it looked like a fairly random piece of data. It is clear that is has something to do with the code at the GitHub link that Jeff posted in an earlier comment, but it looks malformed (or I just don't understand the the syntax, which appears different from the GitHub code). If this is a proper answer, please add information about where and how and why this code snipped would be used. Until then, I will still consider this to be a non-answer. If it's a clarification to the question, then please update the question with this info and describe how it's relevant.
    – Kusalananda
    Dec 17, 2018 at 18:14
  • 1
    Well, yes, networking.extraHosts from the configuration.nix file will get into the /etc/hosts on the resulting NixOS system. Dec 17, 2018 at 18:51
  • 1
    For future travelers, here's what the link above looked like when originally commented: github.com/NixOS/nixpkgs/blob/… Jan 15, 2021 at 17:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.