Unverified Commit 06eb3059 authored by Masum Reza's avatar Masum Reza Committed by GitHub
Browse files

Merge pull request #321649 from Frontear/update-stevenblack-blocklist

stevenblack-blocklist: rev bump and improvements of module + package
parents 27b155c8 ab98e84e
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
  ];
}
+69 −0
Original line number Diff line number Diff line
{
  lib,
  stdenvNoCC,
  fetchFromGitHub,
  nix-update-script,
}:
stdenvNoCC.mkDerivation (finalAttrs: {
  pname = "stevenblack-blocklist";
  version = "3.14.84";

  src = fetchFromGitHub {
    owner = "StevenBlack";
    repo = "hosts";
    rev = "refs/tags/${finalAttrs.version}";
    hash = "sha256-tahf6mdtmZofwMZfMsuDAqCR/V1qZt6vV+o6t4YTKG0=";
  };

  outputs = [
    # default src fallback
    "out"

    # base hosts file
    "ads"

    # extensions only
    "fakenews"
    "gambling"
    "porn"
    "social"
  ];

  dontConfigure = true;
  dontBuild = true;

  installPhase = ''
    runHook preInstall

    mkdir -p $out $ads $fakenews $gambling $porn $social

    # out
    find alternates -type f -not -name "hosts" -exec rm {} +
    cp -r alternates $out
    install -Dm644 hosts $out

    # ads
    install -Dm644 hosts $ads

    # extensions
    install -Dm644 alternates/fakenews-only/hosts $fakenews
    install -Dm644 alternates/gambling-only/hosts $gambling
    install -Dm644 alternates/porn-only/hosts $porn
    install -Dm644 alternates/social-only/hosts $social

    runHook postInstall
  '';

  passthru.updateScript = nix-update-script { };

  meta = with lib; {
    description = "Unified hosts file with base extensions";
    homepage = "https://github.com/StevenBlack/hosts";
    license = licenses.mit;
    maintainers = with maintainers; [
      moni
      Guanran928
      frontear
    ];
  };
})
+0 −24
Original line number Diff line number Diff line
{ lib, fetchFromGitHub }:

let
  version = "3.14.79";
in
fetchFromGitHub {
  name = "stevenblack-blocklist-${version}";

  owner = "StevenBlack";
  repo = "hosts";
  rev = version;
  hash = "sha256-MfQGu+Y4/A0GKIu9d//U+yiP0fN/7cWhEo2dut4UvcE=";

  meta = with lib; {
    description = "Unified hosts file with base extensions";
    homepage = "https://github.com/StevenBlack/hosts";
    license = licenses.mit;
    maintainers = with maintainers; [
      moni
      Guanran928
      frontear
    ];
  };
}
+0 −2
Original line number Diff line number Diff line
@@ -13163,8 +13163,6 @@ with pkgs;
  staticjinja = with python3.pkgs; toPythonApplication staticjinja;
  stevenblack-blocklist  = callPackage ../tools/networking/stevenblack-blocklist { };
  stress = callPackage ../tools/system/stress { };
  stress-ng = callPackage ../tools/system/stress-ng { };