How to edit host files on NixOS: a friendly GitHub repository


I am new to NixOS. This GitHub repository really helped me out learning how to edit the host files and make it persistent across different NixOS generations. In addition, the configuration.nix is not messed up with multiple lines because there is a pointer to another file called hosts.nix.

Moreover, I used Steve Blank host files list in order to block everything listed by his famous repository as Unified hosts + fakenews + gambling + porn + social.

This is my configuration.nix file and my hosts.nix.

This is the key point in the config file template:

{ config, pkgs, ... }:

  imports =
    [ # Include the results of the hardware scan.


There is a pointer to a file called hosts.nix that should have something like:

{ config, pkgs, ... }:

{ networking.extraHosts = ''       # Example




hey if you want to go full star trek, and don’t mind having externally fetched resources in your configuration.nix , you can used a fixed output derivation (FOD) to fetch the data directly from steve.

extrahostsfromsteve = pkgs.fetchurl { url = ""; sha256 = "sha256-C39FsyMQ3PJEwcfPsYSF7SZQZGA79m6o70vmwyFMPLM="; }

{ networking.extraHosts = '' ${builtins.readFile extrahostsfromsteve} ''; }

if you want to go beyond star trek, and use a system configuration flake i think you could clone steve’s repo as a flake input, and then be able to ‘follow’ the master of the repo, so when you do a update to the flake, it advances the latest commit from the master branch on good old steve’s repo automatically. My flake ninja foo is slowly improving, so this may be doable or in fact impossible.

I’ll let that be an exercise for the reader(s).


Dear @nixinator,
I am sorry but I could not complete your exercise yet. Could you please tell me how to go about it?

Hosted by Flying Circus.