From 9b3ebd974bde5c8ebe1f8c8f049f7ee2c6462655 Mon Sep 17 00:00:00 2001 From: Azat Bahawi Date: Thu, 2 May 2024 03:17:48 +0300 Subject: 2024-05-02 --- checks.nix | 8 +++++- configurations/default.nix | 2 +- flake.nix | 63 +++++++++++++++++++++++++++++++++++++--------- lib/my.nix | 11 ++++++++ modules/default.nix | 4 ++- modules/wireguard.nix | 23 +++++++++++++++++ overlays.nix | 2 +- topology.nix | 20 ++++++++++++--- 8 files changed, 114 insertions(+), 19 deletions(-) diff --git a/checks.nix b/checks.nix index 86cb452..3570574 100644 --- a/checks.nix +++ b/checks.nix @@ -1,4 +1,10 @@ -inputs: system: pkgs: { +{ + inputs, + pkgs, + system, + ... +}: +{ preCommit = inputs.git-hooks.lib.${system}.run { src = builtins.path { name = "nixfiles"; diff --git a/configurations/default.nix b/configurations/default.nix index 1c1bda0..78eb2bc 100644 --- a/configurations/default.nix +++ b/configurations/default.nix @@ -1,4 +1,4 @@ -inputs: +{ inputs, ... }: with inputs.self.lib; let mkConfiguration = diff --git a/flake.nix b/flake.nix index dc194f5..484f94b 100644 --- a/flake.nix +++ b/flake.nix @@ -133,6 +133,8 @@ outputs = inputs@{ self, nixpkgs, ... }: let + lib = nixpkgs.lib.extend (import ./lib); + system = "x86_64-linux"; pkgs = import nixpkgs { @@ -144,23 +146,23 @@ }; in { - lib = nixpkgs.lib.extend (import ./lib); + inherit lib; - legacyPackages.${system} = pkgs; + apps.${system}.default = { + type = "app"; + program = self.lib.getExe self.packages.${system}.nixfiles; + }; packages.${system} = { default = self.packages.${system}.nixfiles; inherit (self.legacyPackages.${system}) nixfiles; iso = self.nixosConfigurations.iso.config.system.build.isoImage; - }; - apps.${system}.default = { - type = "app"; - program = self.lib.getExe self.packages.${system}.nixfiles; + topology = self.topology.config.output; }; - overlays = import ./overlays.nix; + legacyPackages.${system} = pkgs; devShells.${system}.default = with pkgs; @@ -169,14 +171,51 @@ packages = [ go-task ]; }; - nixosModules = import ./modules self.lib; + formatter.${system} = pkgs.nixfmt; + + checks.${system} = import ./checks.nix { + inherit + inputs + lib + pkgs + system + ; + }; - nixosConfigurations = import ./configurations inputs; + nixosModules = import ./modules { + inherit + inputs + lib + pkgs + system + ; + }; - checks.${system} = import ./checks.nix inputs system pkgs; + nixosConfigurations = import ./configurations { + inherit + inputs + lib + pkgs + system + ; + }; - formatter.${system} = pkgs.nixfmt; + overlays = import ./overlays.nix { + inherit + inputs + lib + pkgs + system + ; + }; - topology = import ./topology.nix inputs self pkgs; + topology = import ./topology.nix { + inherit + inputs + lib + pkgs + system + ; + }; }; } diff --git a/lib/my.nix b/lib/my.nix index c0ec35a..7d2d1de 100644 --- a/lib/my.nix +++ b/lib/my.nix @@ -30,6 +30,12 @@ with lib; readOnly = true; }; + deviceIcon = mkOption { + description = "Device icon to be used with nix-topology."; + type = nullOr (either path str); + default = null; + }; + system = mkOption { description = "The machine's system."; type = nullOr (enum platforms.all); @@ -146,6 +152,7 @@ with lib; configurations = { # VPS in Germany. manwe = { + deviceIcon = "devices.cloud-server"; system = "x86_64-linux"; isHeadless = true; ipv4 = { @@ -188,6 +195,7 @@ with lib; # VPS in Germany. varda = { + deviceIcon = "devices.cloud-server"; system = "x86_64-linux"; isHeadless = true; ipv4 = { @@ -209,6 +217,7 @@ with lib; # VPS in France. yavanna = { + deviceIcon = "devices.cloud-server"; system = "x86_64-linux"; isHeadless = true; ipv4 = { @@ -236,6 +245,7 @@ with lib; # A beefy desktop: 7950x/rx6750xt/128GB. eonwe = { + deviceIcon = "devices.desktop"; system = "x86_64-linux"; isHeadful = true; wireguard = { @@ -248,6 +258,7 @@ with lib; # ThinkPad T480. melian = { + deviceIcon = "devices.laptop"; system = "x86_64-linux"; isHeadful = true; wireguard = { diff --git a/modules/default.nix b/modules/default.nix index 9ed1029..e41e09b 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -1,4 +1,6 @@ -lib: with lib; { +{ lib, ... }: +with lib; +{ nixfiles = { ... }: { diff --git a/modules/wireguard.nix b/modules/wireguard.nix index f645a90..6e5bdbc 100644 --- a/modules/wireguard.nix +++ b/modules/wireguard.nix @@ -9,6 +9,7 @@ with lib; let cfg = config.nixfiles.modules.wireguard; + inherit (config.lib.topology) mkConnection; in { options.nixfiles.modules.wireguard = { @@ -112,6 +113,13 @@ in secrets."wireguard-private-key-${this.hostname}".file = "${inputs.self}/secrets/wireguard-private-key-${this.hostname}"; networking.firewall.trustedInterfaces = [ cfg.interface ]; + + topology = with cfg; { + nodes.${this.hostname}.interfaces.${interface} = { + network = interface; + icon = "interfaces.wireguard"; + }; + }; }) (mkIf cfg.client.enable { networking.wg-quick.interfaces.${cfg.interface} = mkMerge [ @@ -210,6 +218,21 @@ in withRemoteIp = true; port = 9586; }; + + topology = with cfg; { + networks = { + ${interface} = { + name = interface; + cidrv4 = ipv4.subnet; + cidrv6 = ipv6.subnet; + icon = "interfaces.wireguard"; + }; + }; + + nodes.${this.hostname}.interfaces.${interface}.physicalConnections = mapAttrsToList ( + name: _: (mkConnection name interface) + ) (filterAttrs (n: v: !v.isOther && n != this.hostname && hasAttr "wireguard" v) my.configurations); + }; }) ]; } diff --git a/overlays.nix b/overlays.nix index 642c587..0adbc88 100644 --- a/overlays.nix +++ b/overlays.nix @@ -1,4 +1,4 @@ -{ +_: { default = final: prev: { bruh = prev.callPackage ./packages/bruh.nix { }; diff --git a/topology.nix b/topology.nix index 8830f12..a9d1501 100644 --- a/topology.nix +++ b/topology.nix @@ -1,8 +1,22 @@ -inputs: self: pkgs: +{ + inputs, + lib, + pkgs, + ... +}: +with lib; import inputs.nix-topology { inherit pkgs; modules = [ - { inherit (self) nixosConfigurations; } - (_: { }) + { + nixosConfigurations = filterAttrs ( + n: _: !(hasPrefix "test" n) && !(hasPrefix "iso" n) + ) inputs.self.nixosConfigurations; + } + (_: { + nodes = mapAttrs (_: v: { inherit (v) deviceIcon; }) ( + filterAttrs (_: v: !v.isOther) my.configurations + ); + }) ]; } -- cgit v1.2.3