From 053ce2b76b2463c69911fdfe5d313b3e0212de66 Mon Sep 17 00:00:00 2001 From: stupidcomputer Date: Tue, 31 Dec 2024 11:48:50 -0600 Subject: [PATCH] merge lib/hosts.nix into lib/machines.nix --- boxes/aristotle/default.nix | 12 ++++++++---- boxes/copernicus/default.nix | 9 +++++++-- boxes/netbox/default.nix | 6 +++++- lib/hosts.nix | 13 ------------- lib/machines.nix | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 52 insertions(+), 20 deletions(-) delete mode 100644 lib/hosts.nix diff --git a/boxes/aristotle/default.nix b/boxes/aristotle/default.nix index 6aee151..47a853b 100644 --- a/boxes/aristotle/default.nix +++ b/boxes/aristotle/default.nix @@ -1,4 +1,4 @@ -{ config, pkgs, lib, ... }: +{ pkgs, lib, machines, ... }: { imports = [ @@ -17,8 +17,13 @@ networkmanager.enable = true; firewall.allowedTCPPorts = [ 24800 ]; - hosts = { - "127.0.0.1" = [ "news.ycombinator.com" ]; # i'm finally free + hosts = lib.attrsets.mergeAttrsList [ + (machines.mkHosts machines "router" "localnet") + (machines.mkHosts machines "copernicus" "localnet") + (machines.mkHosts machines "phone" "localnet") + (machines.mkHosts machines "netbox" "internet") + ] // { + "127.0.0.1" = [ "news.ycombinator.com" ]; }; }; hardware = { @@ -35,7 +40,6 @@ isNormalUser = true; description = "usr"; extraGroups = [ "networkmanager" "wheel" "input" ]; - packages = with pkgs; []; }; nixpkgs.config.allowUnfree = true; diff --git a/boxes/copernicus/default.nix b/boxes/copernicus/default.nix index 3fa3e7d..7319a03 100644 --- a/boxes/copernicus/default.nix +++ b/boxes/copernicus/default.nix @@ -1,4 +1,4 @@ -{ lib, config, pkgs, ...}: +{ pkgs, lib, machines, ...}: { imports = [ @@ -6,7 +6,6 @@ ./nvidia.nix ./services ../../config/copernicus.nix - ../../lib/hosts.nix ../../lib/bootstrap.nix ]; @@ -130,6 +129,12 @@ }; }; }; + hosts = lib.attrsets.mergeAttrsList [ + (machines.mkHosts machines "aristotle" "localnet") + (machines.mkHosts machines "router" "localnet") + (machines.mkHosts machines "phone" "localnet") + (machines.mkHosts machines "netbox" "internet") + ]; }; services.getty.autologinUser = "usr"; diff --git a/boxes/netbox/default.nix b/boxes/netbox/default.nix index 66fccc2..acc8443 100644 --- a/boxes/netbox/default.nix +++ b/boxes/netbox/default.nix @@ -1,4 +1,4 @@ -{ pkgs, ... }: +{ pkgs, lib, machines, ... }: { imports = [ @@ -115,5 +115,9 @@ }; }; }; + hosts = lib.attrsets.mergeAttrsList [ + (machines.mkHosts machines "copernicus" "wgnet") + (machines.mkHosts machines "aristotle" "wgnet") + ]; }; } diff --git a/lib/hosts.nix b/lib/hosts.nix deleted file mode 100644 index fc0baf6..0000000 --- a/lib/hosts.nix +++ /dev/null @@ -1,13 +0,0 @@ -{ lib, config, pkgs, inputs, ...}: - -{ - networking.hosts = { - "192.168.1.1" = [ "router" ]; - "192.168.1.200" = [ "mainsail" ]; - "192.168.1.201" = [ "x230t" ]; - "192.168.1.202" = [ "mlg" ]; - "192.168.1.203" = [ "phone" ]; - "149.28.63.115" = [ "netbox" ]; - }; -} - diff --git a/lib/machines.nix b/lib/machines.nix index c9f8802..7cd50b4 100644 --- a/lib/machines.nix +++ b/lib/machines.nix @@ -1,17 +1,49 @@ { + router = { + ip-addrs = { + localnet = "192.168.1.1"; + }; + }; copernicus = { pubkey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILBGh1FHPneg7PCDkhMs2BCJPTIRVJkRTKpOj1w02ydD usr"; wg-pubkey = "JlH1X4KRT+B8Uau+qTLtBqyapkbGClIj1db7znU77kc="; + ip-addrs = { + localnet = "192.168.1.201"; + wgnet = "10.100.0.2"; + }; }; phone = { pubkey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILuVT5W3kzjzsuMIWk1oeGtL8jZGtAhRSx8dK8oBJQcG u0_a291"; + ip-addrs = { + localnet = "192.168.1.203"; + }; }; aristotle = { pubkey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKTDyKneaM44I5to883ghEnnPonedCKDbCX+OnrQ9vO5 usr"; wg-pubkey = "Sw2yyMhyS8GOCWm1VuGn3Y7cfx606dXOGK5mux8ckQU="; + ip-addrs = { + localnet = "192.168.1.202"; + wgnet = "10.100.0.3"; + }; }; netbox = { wg-privkey = ../secrets/netbox-wg-priv.age; wg-pubkey = "0fOqAfsYO4HvshMPnlkKL7Z1RChq98hjDr0Q8o7OJFE="; + ip-addrs = { + internet = "beepboop.systems"; + wgnet = "10.100.0.1"; + }; }; + + mkHosts = machines: hostname: network: + builtins.listToAttrs [ + { + "name" = ( + builtins.getAttr network ( + builtins.getAttr hostname machines + ).ip-addrs + ); + "value" = [ hostname ]; + } + ]; }