OOKNET                             [ /  search the index  ]  
──────────────────────────────────────────────────────────────────────────────────────
══════════════════════════════════════════════════════════════════════════════════════
OOKNET   [ /  search  ]  
────────────────────────────────────────────────
════════════════════════════════════════════════
 
HASH      9459f9e1f68e
DATE      2024-11-30
SUBJECT   nixos: add server conditionals to network manager configuration
FILES     2 CHANGED
HASH      9459f9e1f68e
DATE      2024-11-30
SUBJECT   nixos: add server conditionals to
          network manager configuration
FILES     2 CHANGED
 

diff --git a/modules/nixos/base/networking.nix b/modules/nixos/base/networking.nix
index fa9bffe..9a9252c 100644
--- a/modules/nixos/base/networking.nix
+++ b/modules/nixos/base/networking.nix
@@ -1,5 +1,10 @@
-{lib, ...}: let
+{
+  lib,
+  config,
+  ...
+}: let
   inherit (lib) mkForce mkDefault;
+  inherit (config.ooknet) host;
 in {
   networking = {
     enableIPv6 = true;
@@ -15,8 +20,13 @@ in {
       dns = "systemd-resolved";
       plugins = mkForce [];
       wifi = {
-        macAddress = "random";
-        scanRandMacAddress = true;
+        # why does my server have wifi? not sure.
+        # 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;
       };
       unmanaged = ["interface-name:tailscale*"];
@@ -30,5 +40,7 @@ in {
       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 s
erver
+  systemd.services.NetworkManager-wait-online.enable = host.role != "server";
 }

diff --git a/modules/nixos/base/networking.n
ix b/modules/nixos/base/networking.nix
index fa9bffe..9a9252c 100644
--- a/modules/nixos/base/networking.nix
+++ b/modules/nixos/base/networking.nix
@@ -1,5 +1,10 @@
-{lib, ...}: let
+{
+  lib,
+  config,
+  ...
+}: let
   inherit (lib) mkForce mkDefault;
+  inherit (config.ooknet) host;
 in {
   networking = {
     enableIPv6 = true;
@@ -15,8 +20,13 @@ in {
       dns = "systemd-resolved";
       plugins = mkForce [];
       wifi = {
-        macAddress = "random";
-        scanRandMacAddress = true;
+        # why does my server have wifi? not
 sure.
+        # 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;
       };
       unmanaged = ["interface-name:tailscal
e*"];
@@ -30,5 +40,7 @@ in {
       fallbackDns = ["8.8.8.8"]; # google d
ns
     };
   };
-  systemd.services.NetworkManager-wait-onli
ne.enable = false;
+  # sometimes causes issues with network ma
nager service never actually starting
+  # requiring me to manually start the serv
ice. fine on a workstation, not on a server
+  systemd.services.NetworkManager-wait-onli
ne.enable = host.role != "server";
 }
 

diff --git a/outputs/lib/containers.nix b/outputs/lib/containers.nix
new file mode 100644
index 0000000..829f800
--- /dev/null
+++ b/outputs/lib/containers.nix
@@ -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.po
rt;
+    })
+    # 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;
+}

diff --git a/outputs/lib/containers.nix b/ou
tputs/lib/containers.nix
new file mode 100644
index 0000000..829f800
--- /dev/null
+++ b/outputs/lib/containers.nix
@@ -0,0 +1,67 @@
+{lib, ...}: let
+  inherit (builtins) isBool;
+  inherit (lib) toUpper optionalAttrs mapAt
trs' nameValuePair;
+
+  # convert homepage attributes to labels
+  mkHomepageLabels = {
+    name,
+    domain,
+    group,
+    widget ? {},
+    ...
+  } @ args: let
+    # common homepage labels
+    commonLabels = mapAttrs' (n: v: nameVal
uePair "homepage.${n}" (toString v)) {
+      inherit name group;
+      icon = "${name}.svg";
+      href = domain;
+      description = args.description or nam
e;
+    };
+
+    # 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: l
et
+    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}.entrypo
ints" = "websecure";
+      "traefik.http.routers.${name}.tls" = 
"true";
+      "traefik.http.routes.${name}.certreso
lver" = "cloudflare";
+    })
+    # traefik service labels
+    // (optionalAttrs ((args ? domain) && (
args ? port)) {
+      "traefik.http.services.${name}.loadba
lancer.server.port" = toString args.port;
+    })
+    # homepage labels
+    // (optionalAttrs (args ? homepage) (mk
HomepageLabels {
+      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;
+}
 
[ BACK TO LOG ]
──────────────────────────────────────────────────────────────────────────────────────
OOKNET
────────────────────────────────────────────────
OOKNET