Skip to content

Generate unbound configuration files from blocklist files #2833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Yethal
Copy link

@Yethal Yethal commented Mar 3, 2025

  • Generate unbound.conf files from each hosts file in repository
  • Add an overlay exposing the confs files under unboundconfs nested scope
  • Unbound users consuming the flake are now able to import the blocklists via config similar to this:
{pkgs, ...}:
{
  services.unbound = {
    enable = true;
    settings = {
      include = [
        pkgs.unboundconfs.fakenews-gambling-porn
      ];
    };
  };
}

Copy link

welcome bot commented Mar 3, 2025

Thank you for submitting this pull request! We’ll get back to you as soon as we can!

flake.nix Outdated
line
else
let
address = builtins.elemAt (nixpkgs.lib.strings.splitString " " line) 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not split the string once in the let block instead of twice? What happens with null?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean by null with this case. We're splitting the hosts file on newline and apply transformation to all lines that aren't comments or empty lines

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

elemAt returns a value or null. Are there cases where this can fail?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, on empty lines which we're skipping in the if statement

let
pkgs = nixpkgsFor.${system};
dir = ./alternates;
lists =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block would probably run faster as a single fold instead of iterating the whole list 3 times (4 including the post-let mapAttrs). If it isn’t that expensive, I still think lib.pipe would be a lot easier to read this case instead of trying to read the block backwards from lines bottom to top.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I originally wrote this I was using the experimental pipe-operator and then converted the code to the original pipe-less nix but lib.pipe does seem like an okay compromise

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha. The pipe change here I think is a lot easier for the reader to follow.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I completely agree but I wasn't sure what's the consensus regarding usage of lib.pipe. In my own nix code I just use pipe operator everywhere but I understand this is not common practice

@toastal
Copy link
Contributor

toastal commented Mar 9, 2025

Why 2 commits reverting a formatting instead of amending to fix the single commit? Some of the formatting would be addressed tho with https://gitlab.com/StevenBlack/hosts/-/merge_requests/2 or #2813

@toastal
Copy link
Contributor

toastal commented Mar 9, 2025

Additionally, there is a smell about directories. You should probably be filtering on just hosts files with lib.fileset so READMEs, PNGs, & such do not a) cause a rebuild if changed & b) aren’t copied to the Nix store since they wouldn’t be relevant. It’s a little hard to tell if that’s what’s happening here or not without a src, but it could be worth having a look. It could also be an alternative to the lists variable being quite long in packages to just filter on the types you need first instead of mechanically testing.

@Yethal Yethal force-pushed the add-unbound-confs-overlay branch from e27f4a1 to c18f148 Compare March 11, 2025 07:20
@Yethal
Copy link
Author

Yethal commented Mar 11, 2025

@toastal I am filtering on hosts files, no other files within /alternates are considered, it's just pipe-less Nix code with multiple chained functions is difficult to read

@Yethal Yethal requested a review from toastal March 11, 2025 07:25
@Yethal Yethal force-pushed the add-unbound-confs-overlay branch 2 times, most recently from 7e4631c to f0e982b Compare March 11, 2025 17:43
@Yethal Yethal force-pushed the add-unbound-confs-overlay branch from f0e982b to 2cc50cc Compare March 11, 2025 17:44
@Yethal
Copy link
Author

Yethal commented Mar 11, 2025

Given the include field in unbound config is a list we could optimize this even further by only generating packages for non-combined list variants and allow users to combine them themselves by adding multiple entries to include list so instead of

{pkgs, ...}:
{
  services.unbound = {
    enable = true;
    settings = {
      include = [
        pkgs.unboundconfs.fakenews-gambling-porn
      ];
    };
  };
}

People would do

{pkgs, ...}:
{
  services.unbound = {
    enable = true;
    settings = {
      include = [
        pkgs.unboundconfs.fakenews
        pkgs.unboundconfs.gambling
        pkgs.unboundconfs.porn
      ];
    };
  };
}

Copy link
Contributor

@toastal toastal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No opinion on trying to shorten the list, but generally looks good

@Yethal
Copy link
Author

Yethal commented Mar 11, 2025

This drops the amount of packages to evaluate from 30 to 4 so should speed up evaluation as well.

@Yethal
Copy link
Author

Yethal commented Mar 25, 2025

@toastal Is there anything else to do here or can we merge?

@toastal
Copy link
Contributor

toastal commented Mar 25, 2025

Nope. I am not a maintainer… I also have Nix changes open.

@Yethal
Copy link
Author

Yethal commented Mar 25, 2025

@StevenBlack I believe I require your assistance with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants