From a881c5d7e1f0cf2832b9101cc764715323dd5838 Mon Sep 17 00:00:00 2001 From: reo101 Date: Sat, 27 Jul 2024 13:04:48 +0300 Subject: [PATCH] refactor(flake)!: `machines` -> `hosts` --- .../x86_64-linux/__template__/home.nix | 0 .../aarch64-darwin/limonka/configuration.nix | 1 - .../limonka/home/pavelatanasov.nix | 0 .../apavel-a01/configuration.nix | 0 .../x86_64-darwin/apavel-a01/home/apavel.nix | 0 .../x86_64-darwin/limontozu/configuration.nix | 0 .../limontozu/home/pavelatanasov.nix | 0 .../aarch64-linux/cheetah/configuration.nix | 0 .../aarch64-linux/cheetah/home.nix | 0 .../__template__/configuration.nix | 0 .../x86_64-linux/__template__/deploy.nix | 0 .../__template__/hardware-configuration.nix | 0 .../x86_64-linux/homix/configuration.nix | 0 .../homix/hardware-configuration.nix | 0 .../nixos/x86_64-linux/homix/home/reo101.nix | 0 .../x86_64-linux/jeeves/configuration.nix | 7 +++ .../nixos/x86_64-linux/jeeves/deploy.nix | 0 .../nixos/x86_64-linux/jeeves/disko.nix | 0 .../jeeves/home-assistant/android.nix | 0 .../jeeves/home-assistant/default.nix | 0 .../jeeves/home-assistant/jokes.nix | 0 .../nixos/x86_64-linux/jeeves/home/jeeves.nix | 0 .../nixos/x86_64-linux/jeeves/jellyfin.nix | 0 .../nixos/x86_64-linux/jeeves/mindustry.nix | 0 .../nixos/x86_64-linux/jeeves/network.nix | 2 + .../nixos/x86_64-linux/jeeves/nginx.nix | 9 +++- .../nixos/x86_64-linux/jeeves/ollama.nix | 0 .../nixos/x86_64-linux/jeeves/samba.nix | 0 .../x86_64-linux/jeeves/transmission.nix | 0 .../nixos/x86_64-linux/jeeves/wireguard.nix | 0 modules/flake/configurations.nix | 50 ++++++++----------- modules/flake/deploy.nix | 4 +- nix/utils.nix | 24 ++++----- 33 files changed, 52 insertions(+), 45 deletions(-) rename {machines => hosts}/home-manager/x86_64-linux/__template__/home.nix (100%) rename {machines => hosts}/nix-darwin/aarch64-darwin/limonka/configuration.nix (99%) rename {machines => hosts}/nix-darwin/aarch64-darwin/limonka/home/pavelatanasov.nix (100%) rename {machines => hosts}/nix-darwin/x86_64-darwin/apavel-a01/configuration.nix (100%) rename {machines => hosts}/nix-darwin/x86_64-darwin/apavel-a01/home/apavel.nix (100%) rename {machines => hosts}/nix-darwin/x86_64-darwin/limontozu/configuration.nix (100%) rename {machines => hosts}/nix-darwin/x86_64-darwin/limontozu/home/pavelatanasov.nix (100%) rename {machines => hosts}/nix-on-droid/aarch64-linux/cheetah/configuration.nix (100%) rename {machines => hosts}/nix-on-droid/aarch64-linux/cheetah/home.nix (100%) rename {machines => hosts}/nixos/x86_64-linux/__template__/configuration.nix (100%) rename {machines => hosts}/nixos/x86_64-linux/__template__/deploy.nix (100%) rename {machines => hosts}/nixos/x86_64-linux/__template__/hardware-configuration.nix (100%) rename {machines => hosts}/nixos/x86_64-linux/homix/configuration.nix (100%) rename {machines => hosts}/nixos/x86_64-linux/homix/hardware-configuration.nix (100%) rename {machines => hosts}/nixos/x86_64-linux/homix/home/reo101.nix (100%) rename {machines => hosts}/nixos/x86_64-linux/jeeves/configuration.nix (96%) rename {machines => hosts}/nixos/x86_64-linux/jeeves/deploy.nix (100%) rename {machines => hosts}/nixos/x86_64-linux/jeeves/disko.nix (100%) rename {machines => hosts}/nixos/x86_64-linux/jeeves/home-assistant/android.nix (100%) rename {machines => hosts}/nixos/x86_64-linux/jeeves/home-assistant/default.nix (100%) rename {machines => hosts}/nixos/x86_64-linux/jeeves/home-assistant/jokes.nix (100%) rename {machines => hosts}/nixos/x86_64-linux/jeeves/home/jeeves.nix (100%) rename {machines => hosts}/nixos/x86_64-linux/jeeves/jellyfin.nix (100%) rename {machines => hosts}/nixos/x86_64-linux/jeeves/mindustry.nix (100%) rename {machines => hosts}/nixos/x86_64-linux/jeeves/network.nix (94%) rename {machines => hosts}/nixos/x86_64-linux/jeeves/nginx.nix (65%) rename {machines => hosts}/nixos/x86_64-linux/jeeves/ollama.nix (100%) rename {machines => hosts}/nixos/x86_64-linux/jeeves/samba.nix (100%) rename {machines => hosts}/nixos/x86_64-linux/jeeves/transmission.nix (100%) rename {machines => hosts}/nixos/x86_64-linux/jeeves/wireguard.nix (100%) diff --git a/machines/home-manager/x86_64-linux/__template__/home.nix b/hosts/home-manager/x86_64-linux/__template__/home.nix similarity index 100% rename from machines/home-manager/x86_64-linux/__template__/home.nix rename to hosts/home-manager/x86_64-linux/__template__/home.nix diff --git a/machines/nix-darwin/aarch64-darwin/limonka/configuration.nix b/hosts/nix-darwin/aarch64-darwin/limonka/configuration.nix similarity index 99% rename from machines/nix-darwin/aarch64-darwin/limonka/configuration.nix rename to hosts/nix-darwin/aarch64-darwin/limonka/configuration.nix index c155281..1be47af 100644 --- a/machines/nix-darwin/aarch64-darwin/limonka/configuration.nix +++ b/hosts/nix-darwin/aarch64-darwin/limonka/configuration.nix @@ -36,7 +36,6 @@ # keep-derivations = true # ''; - settings = { # Enable flakes and new 'nix' command experimental-features = [ diff --git a/machines/nix-darwin/aarch64-darwin/limonka/home/pavelatanasov.nix b/hosts/nix-darwin/aarch64-darwin/limonka/home/pavelatanasov.nix similarity index 100% rename from machines/nix-darwin/aarch64-darwin/limonka/home/pavelatanasov.nix rename to hosts/nix-darwin/aarch64-darwin/limonka/home/pavelatanasov.nix diff --git a/machines/nix-darwin/x86_64-darwin/apavel-a01/configuration.nix b/hosts/nix-darwin/x86_64-darwin/apavel-a01/configuration.nix similarity index 100% rename from machines/nix-darwin/x86_64-darwin/apavel-a01/configuration.nix rename to hosts/nix-darwin/x86_64-darwin/apavel-a01/configuration.nix diff --git a/machines/nix-darwin/x86_64-darwin/apavel-a01/home/apavel.nix b/hosts/nix-darwin/x86_64-darwin/apavel-a01/home/apavel.nix similarity index 100% rename from machines/nix-darwin/x86_64-darwin/apavel-a01/home/apavel.nix rename to hosts/nix-darwin/x86_64-darwin/apavel-a01/home/apavel.nix diff --git a/machines/nix-darwin/x86_64-darwin/limontozu/configuration.nix b/hosts/nix-darwin/x86_64-darwin/limontozu/configuration.nix similarity index 100% rename from machines/nix-darwin/x86_64-darwin/limontozu/configuration.nix rename to hosts/nix-darwin/x86_64-darwin/limontozu/configuration.nix diff --git a/machines/nix-darwin/x86_64-darwin/limontozu/home/pavelatanasov.nix b/hosts/nix-darwin/x86_64-darwin/limontozu/home/pavelatanasov.nix similarity index 100% rename from machines/nix-darwin/x86_64-darwin/limontozu/home/pavelatanasov.nix rename to hosts/nix-darwin/x86_64-darwin/limontozu/home/pavelatanasov.nix diff --git a/machines/nix-on-droid/aarch64-linux/cheetah/configuration.nix b/hosts/nix-on-droid/aarch64-linux/cheetah/configuration.nix similarity index 100% rename from machines/nix-on-droid/aarch64-linux/cheetah/configuration.nix rename to hosts/nix-on-droid/aarch64-linux/cheetah/configuration.nix diff --git a/machines/nix-on-droid/aarch64-linux/cheetah/home.nix b/hosts/nix-on-droid/aarch64-linux/cheetah/home.nix similarity index 100% rename from machines/nix-on-droid/aarch64-linux/cheetah/home.nix rename to hosts/nix-on-droid/aarch64-linux/cheetah/home.nix diff --git a/machines/nixos/x86_64-linux/__template__/configuration.nix b/hosts/nixos/x86_64-linux/__template__/configuration.nix similarity index 100% rename from machines/nixos/x86_64-linux/__template__/configuration.nix rename to hosts/nixos/x86_64-linux/__template__/configuration.nix diff --git a/machines/nixos/x86_64-linux/__template__/deploy.nix b/hosts/nixos/x86_64-linux/__template__/deploy.nix similarity index 100% rename from machines/nixos/x86_64-linux/__template__/deploy.nix rename to hosts/nixos/x86_64-linux/__template__/deploy.nix diff --git a/machines/nixos/x86_64-linux/__template__/hardware-configuration.nix b/hosts/nixos/x86_64-linux/__template__/hardware-configuration.nix similarity index 100% rename from machines/nixos/x86_64-linux/__template__/hardware-configuration.nix rename to hosts/nixos/x86_64-linux/__template__/hardware-configuration.nix diff --git a/machines/nixos/x86_64-linux/homix/configuration.nix b/hosts/nixos/x86_64-linux/homix/configuration.nix similarity index 100% rename from machines/nixos/x86_64-linux/homix/configuration.nix rename to hosts/nixos/x86_64-linux/homix/configuration.nix diff --git a/machines/nixos/x86_64-linux/homix/hardware-configuration.nix b/hosts/nixos/x86_64-linux/homix/hardware-configuration.nix similarity index 100% rename from machines/nixos/x86_64-linux/homix/hardware-configuration.nix rename to hosts/nixos/x86_64-linux/homix/hardware-configuration.nix diff --git a/machines/nixos/x86_64-linux/homix/home/reo101.nix b/hosts/nixos/x86_64-linux/homix/home/reo101.nix similarity index 100% rename from machines/nixos/x86_64-linux/homix/home/reo101.nix rename to hosts/nixos/x86_64-linux/homix/home/reo101.nix diff --git a/machines/nixos/x86_64-linux/jeeves/configuration.nix b/hosts/nixos/x86_64-linux/jeeves/configuration.nix similarity index 96% rename from machines/nixos/x86_64-linux/jeeves/configuration.nix rename to hosts/nixos/x86_64-linux/jeeves/configuration.nix index a25542e..efb0c46 100644 --- a/machines/nixos/x86_64-linux/jeeves/configuration.nix +++ b/hosts/nixos/x86_64-linux/jeeves/configuration.nix @@ -12,9 +12,16 @@ ./mindustry.nix # ./home-assistant ./samba.nix + # ./steam.nix # ./ollama.nix + # ./sunshine.nix + # ./photoprism.nix + # ./immich.nix + # ./nextcloud.nix ]; + # services.kanidm = { }; + age.rekey = { hostPubkey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPopSTZ81UyKp9JSljCLp+Syk51zacjh9fLteqxQ6/aB"; # masterIdentities = [ "${inputs.self}/secrets/privkey.age" ]; diff --git a/machines/nixos/x86_64-linux/jeeves/deploy.nix b/hosts/nixos/x86_64-linux/jeeves/deploy.nix similarity index 100% rename from machines/nixos/x86_64-linux/jeeves/deploy.nix rename to hosts/nixos/x86_64-linux/jeeves/deploy.nix diff --git a/machines/nixos/x86_64-linux/jeeves/disko.nix b/hosts/nixos/x86_64-linux/jeeves/disko.nix similarity index 100% rename from machines/nixos/x86_64-linux/jeeves/disko.nix rename to hosts/nixos/x86_64-linux/jeeves/disko.nix diff --git a/machines/nixos/x86_64-linux/jeeves/home-assistant/android.nix b/hosts/nixos/x86_64-linux/jeeves/home-assistant/android.nix similarity index 100% rename from machines/nixos/x86_64-linux/jeeves/home-assistant/android.nix rename to hosts/nixos/x86_64-linux/jeeves/home-assistant/android.nix diff --git a/machines/nixos/x86_64-linux/jeeves/home-assistant/default.nix b/hosts/nixos/x86_64-linux/jeeves/home-assistant/default.nix similarity index 100% rename from machines/nixos/x86_64-linux/jeeves/home-assistant/default.nix rename to hosts/nixos/x86_64-linux/jeeves/home-assistant/default.nix diff --git a/machines/nixos/x86_64-linux/jeeves/home-assistant/jokes.nix b/hosts/nixos/x86_64-linux/jeeves/home-assistant/jokes.nix similarity index 100% rename from machines/nixos/x86_64-linux/jeeves/home-assistant/jokes.nix rename to hosts/nixos/x86_64-linux/jeeves/home-assistant/jokes.nix diff --git a/machines/nixos/x86_64-linux/jeeves/home/jeeves.nix b/hosts/nixos/x86_64-linux/jeeves/home/jeeves.nix similarity index 100% rename from machines/nixos/x86_64-linux/jeeves/home/jeeves.nix rename to hosts/nixos/x86_64-linux/jeeves/home/jeeves.nix diff --git a/machines/nixos/x86_64-linux/jeeves/jellyfin.nix b/hosts/nixos/x86_64-linux/jeeves/jellyfin.nix similarity index 100% rename from machines/nixos/x86_64-linux/jeeves/jellyfin.nix rename to hosts/nixos/x86_64-linux/jeeves/jellyfin.nix diff --git a/machines/nixos/x86_64-linux/jeeves/mindustry.nix b/hosts/nixos/x86_64-linux/jeeves/mindustry.nix similarity index 100% rename from machines/nixos/x86_64-linux/jeeves/mindustry.nix rename to hosts/nixos/x86_64-linux/jeeves/mindustry.nix diff --git a/machines/nixos/x86_64-linux/jeeves/network.nix b/hosts/nixos/x86_64-linux/jeeves/network.nix similarity index 94% rename from machines/nixos/x86_64-linux/jeeves/network.nix rename to hosts/nixos/x86_64-linux/jeeves/network.nix index 6ca4b47..35176d1 100644 --- a/machines/nixos/x86_64-linux/jeeves/network.nix +++ b/hosts/nixos/x86_64-linux/jeeves/network.nix @@ -53,4 +53,6 @@ linkConfig.Name = "wan0"; # "wlp15s0"; }; }; + + # systemd.services.systemd-networkd.environment.SYSTEMD_LOG_LEVEL = "debug"; } diff --git a/machines/nixos/x86_64-linux/jeeves/nginx.nix b/hosts/nixos/x86_64-linux/jeeves/nginx.nix similarity index 65% rename from machines/nixos/x86_64-linux/jeeves/nginx.nix rename to hosts/nixos/x86_64-linux/jeeves/nginx.nix index 970edf4..6d85def 100644 --- a/machines/nixos/x86_64-linux/jeeves/nginx.nix +++ b/hosts/nixos/x86_64-linux/jeeves/nginx.nix @@ -1,6 +1,13 @@ { inputs, outputs, lib, pkgs, config, ... }: { + # age.secrets."nextcloud.adminpass" = { + # rekeyFile = "${inputs.self}/secrets/home/jeeves/nextcloud/adminpass.age"; + # mode = "770"; + # owner = "nextcloud"; + # group = "nextcloud"; + # }; + environment.systemPackages = [ # config.services.nextcloud.package ]; @@ -10,7 +17,7 @@ services.nginx = { enable = true; package = pkgs.openresty; - # virtualHosts."_.jeeves.local" = { + # virtualHosts."_.${config.networking.hostName}.local" = { # # listen = [ # # { # # addr = "127.0.0.1"; diff --git a/machines/nixos/x86_64-linux/jeeves/ollama.nix b/hosts/nixos/x86_64-linux/jeeves/ollama.nix similarity index 100% rename from machines/nixos/x86_64-linux/jeeves/ollama.nix rename to hosts/nixos/x86_64-linux/jeeves/ollama.nix diff --git a/machines/nixos/x86_64-linux/jeeves/samba.nix b/hosts/nixos/x86_64-linux/jeeves/samba.nix similarity index 100% rename from machines/nixos/x86_64-linux/jeeves/samba.nix rename to hosts/nixos/x86_64-linux/jeeves/samba.nix diff --git a/machines/nixos/x86_64-linux/jeeves/transmission.nix b/hosts/nixos/x86_64-linux/jeeves/transmission.nix similarity index 100% rename from machines/nixos/x86_64-linux/jeeves/transmission.nix rename to hosts/nixos/x86_64-linux/jeeves/transmission.nix diff --git a/machines/nixos/x86_64-linux/jeeves/wireguard.nix b/hosts/nixos/x86_64-linux/jeeves/wireguard.nix similarity index 100% rename from machines/nixos/x86_64-linux/jeeves/wireguard.nix rename to hosts/nixos/x86_64-linux/jeeves/wireguard.nix diff --git a/modules/flake/configurations.nix b/modules/flake/configurations.nix index 995eeb9..ebfb389 100644 --- a/modules/flake/configurations.nix +++ b/modules/flake/configurations.nix @@ -8,9 +8,12 @@ let hasDirectories recurseDir configuration-type-to-outputs-modules - configuration-type-to-outputs-machines; + configuration-type-to-outputs-hosts; in let + # Configuration helpers + configurationTypes = ["nixos" "nix-on-droid" "nix-darwin" "home-manager"]; + homeManagerModule = { root, system, hostname, users ? null }: { home-manager = { # Use same `pkgs` instance as system (i.e. carry over overlays) @@ -30,15 +33,13 @@ let config = "${root}/home.nix"; } else { # Not nixOnDroid - users = lib.attrsets.genAttrs - users + users = + lib.attrsets.genAttrs + users (user: import "${root}/home/${user}.nix"); }); }; - # Configuration helpers - configurationTypes = ["nixos" "nix-on-droid" "nix-darwin" "home-manager"]; - mkNixosHost = args @ { root, system, hostname, users }: lib.nixosSystem { inherit system; pkgs = withSystem system ({ pkgs, ... }: pkgs); @@ -120,7 +121,7 @@ let }; createConfigurations = - pred: mkHost: machines: + pred: mkHost: hosts: lib.foldAttrs lib.const [ ] @@ -138,7 +139,7 @@ let ${host} = mkHost { inherit system host configurationFiles; }; }) hosts) - machines)); + hosts)); in { options = let @@ -156,8 +157,8 @@ in Base directory of the contained configurations, used as a base for the rest of the options ''; type = types.path; - default = "${self}/machines"; - defaultText = ''''${self}/machines''; + default = "${self}/hosts"; + defaultText = ''''${self}/hosts''; }; } // ( lib.pipe @@ -194,29 +195,20 @@ in config = { flake = let - autoMachines = + autoHosts = lib.pipe configurationTypes [ (builtins.map (configurationType: lib.nameValuePair - "${configuration-type-to-outputs-machines configurationType}" - (if config.flake.autoConfigurations.${configurationType}.enable - then recurseDir config.flake.autoConfigurations.${configurationType}.dir - else { }))) + "${configuration-type-to-outputs-hosts configurationType}" + (if config.flake.autoConfigurations.${configurationType}.enable + then recurseDir config.flake.autoConfigurations.${configurationType}.dir + else { }))) builtins.listToAttrs ]; - in { - # Machines - # NOTE: manually inheriting generated machines to avoid recursion - # (`autoMachines` depends on `config.flake` itself) - inherit (autoMachines) - nixosMachines - darwinMachines - nixOnDroidMachines - homeManagerMachines; - + in autoHosts // { # Configurations nixosConfigurations = createConfigurations @@ -239,7 +231,7 @@ in (lib.strings.removeSuffix ".nix") (builtins.attrNames (configurationFiles."home" or { }))); }) - config.flake.${configuration-type-to-outputs-machines "nixos"}; + self.${configuration-type-to-outputs-hosts "nixos"}; nixOnDroidConfigurations = createConfigurations @@ -256,7 +248,7 @@ in inherit system; hostname = host; }) - config.flake.${configuration-type-to-outputs-machines "nix-on-droid"}; + self.${configuration-type-to-outputs-hosts "nix-on-droid"}; darwinConfigurations = createConfigurations @@ -279,7 +271,7 @@ in (lib.strings.removeSuffix ".nix") (builtins.attrNames (configurationFiles."home" or { }))); }) - config.flake.${configuration-type-to-outputs-machines "nix-darwin"}; + self.${configuration-type-to-outputs-hosts "nix-darwin"}; homeConfigurations = createConfigurations @@ -296,7 +288,7 @@ in inherit system; hostname = host; }) - config.flake.${configuration-type-to-outputs-machines "home-manager"}; + self.${configuration-type-to-outputs-hosts "home-manager"}; }; }; } diff --git a/modules/flake/deploy.nix b/modules/flake/deploy.nix index 46dc4e7..6d5a3c5 100644 --- a/modules/flake/deploy.nix +++ b/modules/flake/deploy.nix @@ -2,13 +2,13 @@ let inherit (import ../../nix/utils.nix { inherit lib self; }) - accumulateMachines + accumulateHosts configuration-type-to-deploy-type; in { flake = { deploy.nodes = - accumulateMachines + accumulateHosts # TODO: nix-on-droid ["nixos" "nix-darwin"] ({ host, system, configuration-type, configuration }: diff --git a/nix/utils.nix b/nix/utils.nix index ad30de3..ec81582 100644 --- a/nix/utils.nix +++ b/nix/utils.nix @@ -55,19 +55,19 @@ rec { (builtins.throw (mkError configuration-type)); - # TODO: abstract away `_Machines` and `_Modules` + # TODO: abstract away `_Hosts` and `_Modules` - configuration-type-to-outputs-machines = + configuration-type-to-outputs-hosts = gen-configuration-type-to { - nixos = "nixosMachines"; - nix-on-droid = "nixOnDroidMachines"; - nix-darwin = "darwinMachines"; - home-manager = "homeManagerMachines"; + nixos = "nixosHosts"; + nix-on-droid = "nixOnDroidHosts"; + nix-darwin = "darwinHosts"; + home-manager = "homeManagerHosts"; } (configuration-type: builtins.throw - "Invaild configuration-type \"${configuration-type}\" for flake outputs' machines"); + "Invaild configuration-type \"${configuration-type}\" for flake outputs' hosts"); configuration-type-to-outputs-modules = gen-configuration-type-to @@ -104,18 +104,18 @@ rec { builtins.throw "Invaild configuration-type \"${configuration-type}\" for deploy-rs deployment"); - accumulateMachines = configuration-types: host-system-configuration-type-configuration-fn: + accumulateHosts = configuration-types: host-system-configuration-type-configuration-fn: lib.flip lib.concatMapAttrs (lib.genAttrs configuration-types (configuration-type: let - machines = configuration-type-to-outputs-machines configuration-type; + hosts = configuration-type-to-outputs-hosts configuration-type; in - self.${machines})) - (configuration-type: machines: + self.${hosts})) + (configuration-type: hosts: lib.pipe - machines + hosts [ # Filter out nondirectories (lib.filterAttrs