Skip to content

Commit f0e982b

Browse files
committed
Add generated unbound.conf files as packages
1 parent 75b18a2 commit f0e982b

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

flake.nix

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,25 @@
77
nixpkgsFor = forAllSystems (system: import nixpkgs {
88
inherit system;
99
});
10+
11+
toUnboundConf = (
12+
file:
13+
nixpkgs.lib.strings.concatMapStringsSep "\n" (
14+
line:
15+
if (nixpkgs.lib.strings.hasPrefix "#" line) || (line == "") then
16+
line
17+
else
18+
let
19+
split_line = (nixpkgs.lib.strings.splitString " " line);
20+
address = builtins.elemAt split_line 0;
21+
domain = builtins.elemAt split_line 1;
22+
in
23+
''
24+
local-zone: "${domain}" redirect
25+
local-data: "${domain} A ${address}"
26+
''
27+
) (nixpkgs.lib.strings.splitString "\n" (builtins.readFile file))
28+
);
1029
in
1130
{
1231
nixosModule = { config, ... }:
@@ -50,5 +69,35 @@
5069
];
5170
};
5271
});
72+
73+
overlays.default = (
74+
final: prev: {
75+
unboundconfs = prev.lib.makeScope prev.pkgs.newScope (newscope: self.packages.${prev.system});
76+
}
77+
);
78+
79+
packages = forAllSystems (
80+
system:
81+
let
82+
pkgs = nixpkgsFor.${system};
83+
dir = ./alternates;
84+
lists =
85+
pkgs.lib.trivial.pipe (builtins.readDir ./alternates) [
86+
(pkgs.lib.attrsets.filterAttrs (k: v: v == "directory"))
87+
(pkgs.lib.attrsets.mapAttrs (k: v: dir + "/${k}/hosts"))
88+
(pkgs.lib.attrsets.filterAttrs (k: v: builtins.pathExists v))
89+
]
90+
// {
91+
all = ./hosts;
92+
};
93+
in
94+
pkgs.lib.attrsets.mapAttrs (
95+
k: v:
96+
pkgs.writeTextFile {
97+
name = k;
98+
text = toUnboundConf v;
99+
}
100+
) lists
101+
);
53102
};
54103
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hosts",
3-
"version": "3.15.20",
3+
"version": "3.15.21",
44
"description": "Extending and consolidating hosts files from several well-curated sources like adaway.org, mvps.org, malwaredomainlist.com, someonewhocares.org, and potentially others. You can optionally invoke extensions to block additional sites by category.",
55
"main": "",
66
"private": true,

0 commit comments

Comments
 (0)