{ pkgs, ... }:
let
  addNuShebang =
    path:
    builtins.concatStringsSep "\n\n" [
      "#!${pkgs.nushell}/bin/nu"
      (builtins.readFile path)
    ];
in
{
  networking.networkmanager.dispatcherScripts = [
    {
      type = "basic";
      source = pkgs.writeText "dispatcher" (addNuShebang ./dispatcher.nu);
    }
  ];

  environment.etc =
    with builtins;
    (listToAttrs (
      map (v: {
        name = "networkhooks/${v}";
        value = {
          text = addNuShebang ./hooks/${v};
          mode = "0755";
        };
      }) (attrNames (readDir ./hooks))
    ));
}
