nixos/stevenblack: rework to use distinct package outputs

This commit is contained in:
Ali Rizvi 2024-06-26 17:37:27 -04:00
parent 24e4ca0864
commit ab98e84e0d
No known key found for this signature in database
GPG key ID: BCB5CEFDE22282F5

View file

@ -1,34 +1,49 @@
{ config, lib, pkgs, ... }: {
config,
lib,
pkgs,
...
}:
let let
inherit (lib) optionals mkOption mkEnableOption types mkIf elem concatStringsSep maintainers; inherit (lib)
getOutput
maintainers
mkEnableOption
mkIf
mkOption
mkPackageOption
types
;
cfg = config.networking.stevenblack; cfg = config.networking.stevenblack;
# needs to be in a specific order
activatedHosts = with cfg; [ ]
++ optionals (elem "fakenews" block) [ "fakenews" ]
++ optionals (elem "gambling" block) [ "gambling" ]
++ optionals (elem "porn" block) [ "porn" ]
++ optionals (elem "social" block) [ "social" ];
hostsPath = "${pkgs.stevenblack-blocklist}/alternates/" + concatStringsSep "-" activatedHosts + "/hosts";
in in
{ {
options.networking.stevenblack = { options.networking.stevenblack = {
enable = mkEnableOption "the stevenblack hosts file blocklist"; enable = mkEnableOption "the stevenblack hosts file blocklist";
package = mkPackageOption pkgs "stevenblack-blocklist" { };
block = mkOption { block = mkOption {
type = types.listOf (types.enum [ "fakenews" "gambling" "porn" "social" ]); type = types.listOf (
types.enum [
"fakenews"
"gambling"
"porn"
"social"
]
);
default = [ ]; default = [ ];
description = "Additional blocklist extensions."; description = "Additional blocklist extensions.";
}; };
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
networking.hostFiles = [ ] networking.hostFiles = map (x: "${getOutput x cfg.package}/hosts") ([ "ads" ] ++ cfg.block);
++ optionals (activatedHosts != [ ]) [ hostsPath ]
++ optionals (activatedHosts == [ ]) [ "${pkgs.stevenblack-blocklist}/hosts" ];
}; };
meta.maintainers = [ maintainers.moni maintainers.artturin ]; meta.maintainers = with maintainers; [
moni
artturin
frontear
];
} }