-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
58 lines (55 loc) · 1.75 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
{
description = "StevenBlack blocklist reformatted for Unbound";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils, ... }:
let
confName = "blocklist.conf";
in
flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = import nixpkgs { inherit system; };
in
{
packages.default = pkgs.stdenv.mkDerivation
{
name = "stevenblack-unbound";
version = "unstable-2025-01-31";
src = pkgs.fetchFromGitHub
{
owner = "StevenBlack";
repo = "hosts";
rev = "8ca227e21a43ad28d978aadff2da75f1bbd90e98";
sha256 = "0kpha475jsw8fbq2z1mn4m94a6a5skgmkia0q6w8sh8lba30y9y3";
};
sourceRoot = ".";
installPhase = ''
cat source/hosts | awk '/^0\.0\.0\.0/ { if ( $2 !~ /0\.0\.0\.0/ ) { print "local-zone: \""$2".\" always_null" }}' > blocklist.conf
mkdir -p $out
cp blocklist.conf $out/${confName}
'';
};
}
) //
{
nixosModules.default = { config, lib, pkgs, ... }:
with lib;
let
pkg = self.packages.${pkgs.system}.default;
cfg = config.services.unbound.blocklist;
in
{
options.services.unbound.blocklist = {
enable = mkEnableOption "Enables DNS blocklist generated from StevenBlack hosts file";
};
config = mkIf cfg.enable {
services.unbound.settings.server = {
include = "${pkg}/${confName}";
};
};
};
};
}