From 9cfda0b7a258fca311dcf3897f5b19e2a0ff3b7e Mon Sep 17 00:00:00 2001 From: ocfox Date: Mon, 30 Sep 2024 15:09:40 +0800 Subject: [PATCH] host: refactor import --- hosts/civet/networking.nix | 2 + hosts/default.nix | 174 +++++++++--------------------------- hosts/whitefox/services.nix | 36 -------- 3 files changed, 43 insertions(+), 169 deletions(-) diff --git a/hosts/civet/networking.nix b/hosts/civet/networking.nix index 5c868eb..ab5c3c2 100644 --- a/hosts/civet/networking.nix +++ b/hosts/civet/networking.nix @@ -3,6 +3,8 @@ firewall.allowedTCPPorts = [ 80 443 + 7096 + 11283 ]; firewall.allowedUDPPorts = [ diff --git a/hosts/default.nix b/hosts/default.nix index 9e99218..30e54e5 100644 --- a/hosts/default.nix +++ b/hosts/default.nix @@ -7,151 +7,59 @@ ... }: let - whitefox-module = + genConf = + host: { pkgs, username, ... }@args: inputs.haumea.lib.load { - src = ./whitefox; + src = ./${host}; inputs = args // { inherit inputs; }; transformer = inputs.haumea.lib.transformers.liftDefault; }; - # silverfox-module = - # { pkgs, username, ... }@args: - # inputs.haumea.lib.load { - # src = ./silverfox; - # inputs = args // { - # inherit inputs; - # }; - # transformer = inputs.haumea.lib.transformers.liftDefault; - # }; - - arcticfox-module = - { pkgs, username, ... }@args: - inputs.haumea.lib.load { - src = ./arcticfox; - inputs = args // { - inherit inputs; - }; - transformer = inputs.haumea.lib.transformers.liftDefault; - }; - - redfox-module = - { pkgs, username, ... }@args: - inputs.haumea.lib.load { - src = ./redfox; - inputs = args // { - inherit inputs; - }; - transformer = inputs.haumea.lib.transformers.liftDefault; - }; - - civet-module = - { pkgs, ... }@args: - inputs.haumea.lib.load { - src = ./civet; - inputs = args // { - inherit inputs; - }; - transformer = inputs.haumea.lib.transformers.liftDefault; - }; - - sakhalin-module = - { pkgs, ... }@args: - inputs.haumea.lib.load { - src = ./sakhalin; - inputs = args // { - inherit inputs; + genNixosSystem = host: system: modules: { + "${host}" = nixpkgs.lib.nixosSystem { + inherit system; + modules = [ + (genConf "${host}") + ] ++ modules; + specialArgs = { + inherit inputs username home; }; - transformer = inputs.haumea.lib.transformers.liftDefault; - }; - - vulpes-module = - { pkgs, ... }@args: - inputs.haumea.lib.load { - src = ./vulpes; - inputs = args // { - inherit inputs; - }; - transformer = inputs.haumea.lib.transformers.liftDefault; - }; -in -{ - whitefox = nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - modules = [ - ./whitefox/_hardware.nix - whitefox-module - inputs.home-manager.nixosModules.home-manager - inputs.minegrub.nixosModules.default - inputs.agenix.nixosModules.default - inputs.niri.nixosModules.niri - inputs.self.nixosModules.default - { nix.registry.self.flake = self; } - ]; - specialArgs = { - inherit inputs username home; - }; - }; - - civet = nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - modules = [ - inputs.disko.nixosModules.disko - inputs.nixos-facter.nixosModules.facter - civet-module - ]; - specialArgs = { - inherit inputs; }; }; + inherit (nixpkgs.lib) mkMerge; +in +mkMerge [ + (genNixosSystem "whitefox" "x86_64-linux" [ + ./whitefox/_hardware.nix + inputs.home-manager.nixosModules.home-manager + inputs.minegrub.nixosModules.default + inputs.agenix.nixosModules.default + inputs.niri.nixosModules.niri + inputs.self.nixosModules.default + { nix.registry.self.flake = self; } + ]) - arcticfox = nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - modules = [ - ./arcticfox/_hardware.nix - arcticfox-module - inputs.home-manager.nixosModules.home-manager - inputs.agenix.nixosModules.default - { nix.registry.self.flake = self; } - ]; - specialArgs = { - inherit inputs username home; - }; - }; + (genNixosSystem "civet" "x86_64-linux" [ + inputs.disko.nixosModules.disko + inputs.nixos-facter.nixosModules.facter + ]) - redfox = nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - modules = [ - ./redfox/_hardware.nix - inputs.disko.nixosModules.disko - redfox-module - ]; - specialArgs = { - inherit inputs; - }; - }; + (genNixosSystem "redfox" "x86_64-linux" [ + ./redfox/_hardware.nix + inputs.disko.nixosModules.disko + ]) - sakhalin = nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - modules = [ - ./sakhalin/_hardware.nix - sakhalin-module - ]; - specialArgs = { - inherit inputs; - }; - }; + (genNixosSystem "arcticfox" "x86_64-linux" [ + ./arcticfox/_hardware.nix + inputs.home-manager.nixosModules.home-manager + inputs.agenix.nixosModules.default + { nix.registry.self.flake = self; } + ]) - vulpes = nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - modules = [ - ./vulpes/_hardware.nix - vulpes-module - ]; - specialArgs = { - inherit inputs; - }; - }; -} + (genNixosSystem "vulpes" "x86_64-linux" [ + ./vulpes/_hardware.nix + ]) +] diff --git a/hosts/whitefox/services.nix b/hosts/whitefox/services.nix index 3c918bc..ee31f6d 100644 --- a/hosts/whitefox/services.nix +++ b/hosts/whitefox/services.nix @@ -4,42 +4,6 @@ getty.autologinUser = username; devmon.enable = true; - home-assistant = { - enable = true; - customLovelaceModules = with pkgs.home-assistant-custom-lovelace-modules; [ - mini-graph-card - ]; - - lovelaceConfig = { - title = "My Awesome Home"; - views = [ - { - title = "Ele"; - cards = [ - { - type = "custom:mini-graph-card"; - entities = [ - { - entity = "sensor.last_electricity_usage"; - name = "每日用电量"; - aggregate_func = "first"; - show_state = true; - show_points = true; - } - ]; - group_by = "date"; - hour24 = true; - hours_to_show = 240; - } - ]; - } - ]; - }; - config = { - default_config = { }; - }; - }; - tailscale.enable = true; openssh.enable = true;