From 471a2d41dddb12967a95c23368b60a61e05c33a7 Mon Sep 17 00:00:00 2001 From: Denis Lehmann Date: Tue, 5 Oct 2021 23:37:29 +0200 Subject: [PATCH] Move and extend NixOS section --- readme_template.md | 69 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 17 deletions(-) diff --git a/readme_template.md b/readme_template.md index 138f1eda0..92a846fe1 100644 --- a/readme_template.md +++ b/readme_template.md @@ -169,23 +169,6 @@ in hosts format to the generated hosts file. `--whitelist `, or `-w `: Use the given whitelist file to remove hosts from the generated hosts file. -#### Using NixOS - -To install hosts file on your machine add the following into your `configuration.nix`: - -```nix -{ - networking.extraHosts = let - hostsPath = https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts; - hostsFile = builtins.fetchurl hostsPath; - in builtins.readFile "${hostsFile}"; -} -``` - -* NOTE: Change `hostsPath` if you need other versions of hosts file. -* NOTE: The call to `fetchurl` is impure. -Use `fetchFromGitHub` with the exact commit if you want to always get the same result. - ## How do I control which sources are unified? Add one or more *additional* sources, each in a subfolder of the `data/` @@ -297,6 +280,58 @@ editor. Gentoo users may find [`sb-hosts`](https://github.com/PF4Public/gentoo-overlay/tree/master/net-misc/sb-hosts) in [::pf4public](https://github.com/PF4Public/gentoo-overlay) Gentoo overlay +## NixOS + +To install hosts file on your machine add the following into your `configuration.nix`: + +```nix +{ + networking.extraHosts = let + hostsPath = https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts; + hostsFile = builtins.fetchurl hostsPath; + in builtins.readFile "${hostsFile}"; +} +``` + +* NOTE: Change `hostsPath` if you need other versions of hosts file. +* NOTE: The call to `fetchurl` is impure. +Use `fetchFromGitHub` with the exact commit if you want to always get the same result. + +### Nix Flake + +NixOS installations which are managed through *flakes* can use the hosts file like this: + +```nix +{ + inputs.hosts.url = github:StevenBlack/hosts; + outputs = { self, nixpkgs, hosts }: { + nixosConfigurations.my-hostname = { + system = ""; + modules = [ + + hosts.nixosModule { + networking.stevenBlackHosts.enable = true; + } + + ]; + }; + }; +} +``` + +The hosts extensions are also available with the following options: + +```nix +{ + networking.stevenBlackHosts = { + blockFakenews = true; + blockGambling = true; + blockPorn = true; + blockSocial = true; + }; +} +``` + ## Updating hosts file on Windows (NOTE: See also some third-party Hosts managers, listed below.)