Skip to content

Commit

Permalink
feat: init nix-topology
Browse files Browse the repository at this point in the history
  • Loading branch information
isabelroses committed Nov 19, 2024
1 parent f04a59e commit b2dcb60
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 1 deletion.
26 changes: 26 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,17 @@
};
};

# Nix topology a way to generate diagrams of your nix config
nix-topology = {
url = "github:oddlama/nix-topology";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
pre-commit-hooks.follows = "";
devshell.follows = "";
};
};

### Additional packages
# a plain simple way to host a mail server
simple-nixos-mailserver = {
Expand Down
1 change: 1 addition & 0 deletions modules/nixos/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
./nix.nix # nix settings for nixos only systems
./perless.nix # perless specific configurations
./remote-modules.nix # modules that are not in this repo, and don't have a nice place to be imported in
./topology.nix # our systems topology
./virtualization.nix # docker, QEMU, waydroid etc.
];
}
8 changes: 8 additions & 0 deletions modules/nixos/topology.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{ inputs, config, ... }:
{
imports = [ inputs.nix-topology.nixosModules.default ];

topology.self = {
name = config.networking.hostName;
};
}
2 changes: 1 addition & 1 deletion parts/args.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
allowUnfree = true;
allowUnsupportedSystem = true;
};
overlays = [ ];
overlays = [ inputs.nix-topology.overlays.default ];
};
};
}
1 change: 1 addition & 0 deletions parts/programs/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
imports = [
./topology # generate a image of the flakes topology
./deploy.nix # a setup for deploy-rs, which allows us to remotely build and deploy our flake
./formatter.nix # formatter for nix fmt, via treefmt is a formatter for every language
./git-hooks.nix # git hooks to help manage the flake
Expand Down
Binary file added parts/programs/topology/assets/mac.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added parts/programs/topology/assets/pihole.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions parts/programs/topology/assets/rpi.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions parts/programs/topology/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{ inputs, ... }:
let
# we need to remove lilith from the list of nixosConfigurations since
# it does not import nix-topology, as of thus it will throw an error
inherit (inputs.self) nixosConfigurations;
filteredConfigs = builtins.removeAttrs nixosConfigurations [ "lilith" ];
in
{
imports = [ inputs.nix-topology.flakeModule ];

# nix build .#topology.x86_64-linux.config.output
perSystem.topology = {
nixosConfigurations = filteredConfigs;
modules = [ ./output.nix ];
};
}
107 changes: 107 additions & 0 deletions parts/programs/topology/output.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{ config, ... }:
let
inherit (config.lib.topology)
mkInternet
mkDevice
mkRouter
mkConnection
;
in
{
nodes = {
internet = mkInternet {
connections = [
(mkConnection "minerva" "eth0")
(mkConnection "router" "eth0")
];
};

# our router
router = mkRouter "bingus" {
info = "BT Home Hub 5";

interfaceGroups = [
[ "eth0" ]
[
"eth1"
"eth2"
"eth3"
]
[ "wlan0" ]
];

interfaces = {
eth1.network = "LAN";
wlan0.network = "WLAN";
};

connections = {
eth1 = mkConnection "bongus" "eth0";
eth2 = mkConnection "amaterasu" "eth0";
wlan0 = [
(mkConnection "hydra" "wlan0")
(mkConnection "amaterasu" "wlan0")
(mkConnection "tatsumaki" "wlan0")
];
};
};

# devices not collected by nix-topology
bongus = mkDevice "bongus" {
info = "Raspberry Pi 4";
deviceIcon = ./assets/rpi.svg;
interfaces = {
eth0 = { };
eth1 = { };
};

services.pihole = {
name = "Pi-hole";
icon = ./assets/pihole.png;
};
};

tatsumaki = mkDevice "tatsumaki" {
info = "A MacBook Air";
deviceIcon = ./assets/mac.png;

interfaces.wlan0 = { };
};

# extra settings for devices that are collected by nix-topology
amaterasu = {
hardware.info = "My high-end gaming machine";

interfaces = {
eth0 = { };
wlan0 = { };
};
};

hydra = {
hardware.info = "A super mid spec laptop";
interfaces.wlan0 = { };
};

minerva.hardware.info = "A server for some of my infrastructure";

valkyrie = {
hardware.info = "WSL2 host, devenv on Windows";

guestType = "wsl";
parent = "amaterasu";
};
};

networks = {
LAN = {
name = "LAN";
cidrv4 = "192.68.1.0/24";
};

WLAN = {
name = "WLAN";
cidrv4 = "192.68.2.0/24";
};
};
}

0 comments on commit b2dcb60

Please sign in to comment.