astro / nix-openwrt-imagebuilder

Build OpenWRT images in Nix derivations
MIT License
129 stars 16 forks source link

PR to support modular interface? #22

Open tomeon opened 1 year ago

tomeon commented 1 year ago

Hello, and thanks for this neat and useful toolchain. I'm trying to do a better job of managing my OpenWRT-based router and APs, and as a confirmed Nixaholic this repository is just what I needed.

Would you be interested in a PR introducing a modular interface to the OpenWRT image builder code? I have a (very) rough cut at such an interface up on SourceHut here.

The high-level view:

{
  openwrtImages.default = self.lib.openwrtImage {
    modules = [
      {
        image = {
          profileName = "avm_fritz7412";
          packages.include = ["tcpdump"];
          packages.exclude = ["ppp"];
          disabledServices = ["dnsmasq"];
          snippets."etc/uci-defaults/99-custom".text = ''
            uci -q batch << EOI
            set system.@system[0].hostname='testap'
            commit
            EOI
          '';
        };
      }
    ];
  };
}

If specified as a flake output, the image and associated assets could then be built with nix build '.#openwrtImages.default.config.system.build.image'. I plan to add a wrapper command for this that would permit doing, say, nix-openwrt-imagebuild '.#default'.

Any interest in integrating something like this in your project?

Thank you!

astro commented 1 year ago

In general, great idea! I already use the NixOS module system for networking configuration.

However, this piece of code already has a few ways of calling it. I prefer the managability and flexibility of putting lib.evalModules in my own code, passing the nix-openwrt-imagebuilder parameters together in one place. Are there use-cases where doing so would be inconvenient?

To me it starts to make sense if we start defining all the OpenWRT options as sensible NixOS module options. @ehmry launched a fork into this direction starting in #9. Although it would be nice to have, I am not sure I am ready to maintain and update such a bulk of declarations. Can it be automated just like I've done with the download hashes?

ehmry commented 1 year ago

I'm not working with OpenWRT anymore so I'm not maintain my module fork. As I recall @mic92 has similar configuration work that is relevant.

Mic92 commented 1 year ago

https://github.com/Mic92/dotfiles/blob/main/openwrt/example.nix

astro commented 10 months ago

There is also https://git.eno.space/dewclaw.git/tree/ now.

pedorich-n commented 3 months ago

Hey, @tomeon! I noticed that your sourcehut repository is active and that you have implemented a very comprehensive module system, including the flake-parts module ❤️. Are you still interested in creating a PR to port it to this repository? 👀

I believe everyone would benefit from a more modular system that allows for atomic changes, better type-safety, and auto-generated documentation similar to NixOS modules.


Regarding @astro's comment:

Although it would be nice to have, I am not sure I am ready to maintain and update such a bulk of declarations.

I think @tomeon's approach to modules is simpler and easier to maintain than what was proposed in https://github.com/astro/nix-openwrt-imagebuilder/pull/9. While it would be great to have many individual services wrapped into Nix expressions like NixOS service modules, I agree that it would be hard to maintain.

In my opinion, wrapping UCI expressions into NIX and exposing packages, disabledServices, and files makes more sense, as it aligns more closely with what is already implemented in this repository and with ImageBuilder's interface.