Unverified Commit ab98e84e authored by Ali Rizvi's avatar Ali Rizvi
Browse files

nixos/stevenblack: rework to use distinct package outputs

parent 24e4ca08
Loading
Loading
Loading
Loading
+32 −17
Original line number Diff line number Diff line
{ config, lib, pkgs, ... }:

{
  config,
  lib,
  pkgs,
  ...
}:
let
  inherit (lib) optionals mkOption mkEnableOption types mkIf elem concatStringsSep maintainers;
  cfg = config.networking.stevenblack;
  inherit (lib)
    getOutput
    maintainers
    mkEnableOption
    mkIf
    mkOption
    mkPackageOption
    types
    ;

  # 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";
  cfg = config.networking.stevenblack;
in
{
  options.networking.stevenblack = {
    enable = mkEnableOption "the stevenblack hosts file blocklist";

    package = mkPackageOption pkgs "stevenblack-blocklist" { };

    block = mkOption {
      type = types.listOf (types.enum [ "fakenews" "gambling" "porn" "social" ]);
      type = types.listOf (
        types.enum [
          "fakenews"
          "gambling"
          "porn"
          "social"
        ]
      );
      default = [ ];
      description = "Additional blocklist extensions.";
    };
  };

  config = mkIf cfg.enable {
    networking.hostFiles = [ ]
      ++ optionals (activatedHosts != [ ]) [ hostsPath ]
      ++ optionals (activatedHosts == [ ]) [ "${pkgs.stevenblack-blocklist}/hosts" ];
    networking.hostFiles = map (x: "${getOutput x cfg.package}/hosts") ([ "ads" ] ++ cfg.block);
  };

  meta.maintainers = [ maintainers.moni maintainers.artturin ];
  meta.maintainers = with maintainers; [
    moni
    artturin
    frontear
  ];
}