nixos: add server conditionals to network manager configuration
ensure wifi mac address is static if host is a server
This commit is contained in:
parent
4f20813139
commit
9459f9e1f6
2 changed files with 83 additions and 4 deletions
|
|
@ -1,5 +1,10 @@
|
||||||
{lib, ...}: let
|
{
|
||||||
|
lib,
|
||||||
|
config,
|
||||||
|
...
|
||||||
|
}: let
|
||||||
inherit (lib) mkForce mkDefault;
|
inherit (lib) mkForce mkDefault;
|
||||||
|
inherit (config.ooknet) host;
|
||||||
in {
|
in {
|
||||||
networking = {
|
networking = {
|
||||||
enableIPv6 = true;
|
enableIPv6 = true;
|
||||||
|
|
@ -15,8 +20,13 @@ in {
|
||||||
dns = "systemd-resolved";
|
dns = "systemd-resolved";
|
||||||
plugins = mkForce [];
|
plugins = mkForce [];
|
||||||
wifi = {
|
wifi = {
|
||||||
macAddress = "random";
|
# why does my server have wifi? not sure.
|
||||||
scanRandMacAddress = true;
|
# ensure my mac addr is static so I can reserve an IP
|
||||||
|
macAddress =
|
||||||
|
if host.role == "server"
|
||||||
|
then "permanent"
|
||||||
|
else "random";
|
||||||
|
scanRandMacAddress = host.role != "server";
|
||||||
powersave = true;
|
powersave = true;
|
||||||
};
|
};
|
||||||
unmanaged = ["interface-name:tailscale*"];
|
unmanaged = ["interface-name:tailscale*"];
|
||||||
|
|
@ -30,5 +40,7 @@ in {
|
||||||
fallbackDns = ["8.8.8.8"]; # google dns
|
fallbackDns = ["8.8.8.8"]; # google dns
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
systemd.services.NetworkManager-wait-online.enable = false;
|
# sometimes causes issues with network manager service never actually starting
|
||||||
|
# requiring me to manually start the service. fine on a workstation, not on a server
|
||||||
|
systemd.services.NetworkManager-wait-online.enable = host.role != "server";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
67
outputs/lib/containers.nix
Normal file
67
outputs/lib/containers.nix
Normal file
|
|
@ -0,0 +1,67 @@
|
||||||
|
{lib, ...}: let
|
||||||
|
inherit (builtins) isBool;
|
||||||
|
inherit (lib) toUpper optionalAttrs mapAttrs' nameValuePair;
|
||||||
|
|
||||||
|
# convert homepage attributes to labels
|
||||||
|
mkHomepageLabels = {
|
||||||
|
name,
|
||||||
|
domain,
|
||||||
|
group,
|
||||||
|
widget ? {},
|
||||||
|
...
|
||||||
|
} @ args: let
|
||||||
|
# common homepage labels
|
||||||
|
commonLabels = mapAttrs' (n: v: nameValuePair "homepage.${n}" (toString v)) {
|
||||||
|
inherit name group;
|
||||||
|
icon = "${name}.svg";
|
||||||
|
href = domain;
|
||||||
|
description = args.description or name;
|
||||||
|
};
|
||||||
|
|
||||||
|
# process widget attributes, flattening them into label format
|
||||||
|
processWidget = attrs:
|
||||||
|
mapAttrs' (n: v:
|
||||||
|
nameValuePair "homepage.widget.${n}" (
|
||||||
|
if isBool v
|
||||||
|
then
|
||||||
|
if v
|
||||||
|
then "true"
|
||||||
|
else "false"
|
||||||
|
else toString v
|
||||||
|
))
|
||||||
|
attrs;
|
||||||
|
in
|
||||||
|
commonLabels // (processWidget widget);
|
||||||
|
|
||||||
|
mkContainerLabels = {name, ...} @ args: let
|
||||||
|
homepage = args.homepage or {};
|
||||||
|
baseWidget = homepage.widget or {};
|
||||||
|
in
|
||||||
|
# traefik router labels
|
||||||
|
(optionalAttrs (args ? domain) {
|
||||||
|
"traefik.enable" = "true";
|
||||||
|
"traefik.http.routers.${name}.rule" = "Host(`${args.domain}`)";
|
||||||
|
"traefik.http.routers.${name}.entrypoints" = "websecure";
|
||||||
|
"traefik.http.routers.${name}.tls" = "true";
|
||||||
|
"traefik.http.routes.${name}.certresolver" = "cloudflare";
|
||||||
|
})
|
||||||
|
# traefik service labels
|
||||||
|
// (optionalAttrs ((args ? domain) && (args ? port)) {
|
||||||
|
"traefik.http.services.${name}.loadbalancer.server.port" = toString args.port;
|
||||||
|
})
|
||||||
|
# homepage labels
|
||||||
|
// (optionalAttrs (args ? homepage) (mkHomepageLabels {
|
||||||
|
inherit name;
|
||||||
|
inherit (args) domain;
|
||||||
|
group = args.homepage.group or name;
|
||||||
|
widget =
|
||||||
|
baseWidget
|
||||||
|
// {
|
||||||
|
type = name;
|
||||||
|
url = args.domain;
|
||||||
|
key = "{{HOMEPAGE_FILE_${toUpper name}}}";
|
||||||
|
};
|
||||||
|
}));
|
||||||
|
in {
|
||||||
|
inherit mkContainerLabels;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue