forked from StevenBlack/hosts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
50 lines (48 loc) · 1.82 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
{
description = "Unified hosts file with base extensions.";
outputs = { self, nixpkgs, ... }@inputs:
let
forAllSystems = nixpkgs.lib.genAttrs nixpkgs.lib.platforms.unix;
nixpkgsFor = forAllSystems (system: import nixpkgs {
inherit system;
});
in
{
nixosModule = { config, ... }:
with nixpkgs.lib;
let
cfg = config.networking.stevenBlackHosts;
alternatesList = (if cfg.blockFakenews then [ "fakenews" ] else []) ++
(if cfg.blockGambling then [ "gambling" ] else []) ++
(if cfg.blockPorn then [ "porn" ] else []) ++
(if cfg.blockSocial then [ "social" ] else []);
alternatesPath = "alternates/" + builtins.concatStringsSep "-" alternatesList + "/";
in
{
options.networking.stevenBlackHosts = {
enable = mkEnableOption "Use Steven Black's hosts file as extra hosts.";
blockFakenews = mkEnableOption "Additionally block fakenews hosts.";
blockGambling = mkEnableOption "Additionally block gambling hosts.";
blockPorn = mkEnableOption "Additionally block porn hosts.";
blockSocial = mkEnableOption "Additionally block social hosts.";
};
config = mkIf cfg.enable {
networking.extraHosts =
builtins.readFile (
"${self}/" + (if alternatesList != [] then alternatesPath else "") + "hosts"
);
};
};
devShells = forAllSystems (system:
let pkgs = nixpkgsFor.${system}; in
{
default = pkgs.mkShell {
buildInputs = with pkgs; [
python3
python3Packages.flake8
python3Packages.requests
];
};
});
};
}