From 6d04251eb7fad58cf4255241260791f79238e437 Mon Sep 17 00:00:00 2001 From: caandt Date: Sun, 27 Oct 2024 01:36:51 -0500 Subject: [PATCH] refactor --- flake.nix | 47 +++++++++---------- {system => hosts}/hyuganatsu/default.nix | 2 +- .../hyuganatsu/hardware-configuration.nix | 0 hosts/hyuganatsu/users/ahnwuoa/default.nix | 10 ++++ {system => hosts}/iyokan/default.nix | 0 .../iyokan/hardware-configuration.nix | 0 system/{common => }/audio.nix | 0 system/{common => }/bash.nix | 0 system/{common => }/boot.nix | 0 system/{common => }/configuration.nix | 0 system/{common => }/default.nix | 0 system/{common => }/display.nix | 0 system/{common => }/locale.nix | 0 system/{common => }/plasma.nix | 0 system/{common => }/security.nix | 0 system/{common => }/users.nix | 0 system/{common => }/virt.nix | 0 user/home.nix | 7 +-- 18 files changed, 36 insertions(+), 30 deletions(-) rename {system => hosts}/hyuganatsu/default.nix (93%) rename {system => hosts}/hyuganatsu/hardware-configuration.nix (100%) create mode 100644 hosts/hyuganatsu/users/ahnwuoa/default.nix rename {system => hosts}/iyokan/default.nix (100%) rename {system => hosts}/iyokan/hardware-configuration.nix (100%) rename system/{common => }/audio.nix (100%) rename system/{common => }/bash.nix (100%) rename system/{common => }/boot.nix (100%) rename system/{common => }/configuration.nix (100%) rename system/{common => }/default.nix (100%) rename system/{common => }/display.nix (100%) rename system/{common => }/locale.nix (100%) rename system/{common => }/plasma.nix (100%) rename system/{common => }/security.nix (100%) rename system/{common => }/users.nix (100%) rename system/{common => }/virt.nix (100%) diff --git a/flake.nix b/flake.nix index ea0e23c..b41d711 100644 --- a/flake.nix +++ b/flake.nix @@ -19,31 +19,30 @@ system = "x86_64-linux"; pkgs = nixpkgs.legacyPackages.${system}; pkgs-stable = nixpkgs-stable.legacyPackages.${system}; - specialArgs = { - inherit pkgs-stable; - inherit flake-programs-sqlite; - }; - in { - nixosConfigurations = { - hyuganatsu = nixpkgs.lib.nixosSystem { + in with builtins; with nixpkgs.lib.attrsets; { + nixosConfigurations = mapAttrs' (host: _: { + name = host; + value = nixpkgs.lib.nixosSystem { inherit system; - inherit specialArgs; - modules = [ system/hyuganatsu ]; + specialArgs = { + inherit pkgs-stable; + inherit flake-programs-sqlite; + }; + modules = [ (./hosts + "/${host}") ]; }; - iyokan = nixpkgs.lib.nixosSystem { - inherit system; - inherit specialArgs; - modules = [ system/iyokan ]; - }; - }; - homeConfigurations.ahnwuoa = home-manager.lib.homeManagerConfiguration { - inherit pkgs; - extraSpecialArgs = rec { - inherit pkgs-stable; - username = "ahnwuoa"; - homeDirectory = "/home/${username}"; - }; - modules = [ ./user ]; - }; + }) (readDir ./hosts); + homeConfigurations = foldl' (a: b: a//b) {} (map (host: let users = ./hosts + "/${host}/users"; in + if pathExists users + then mapAttrs' (user: _: { + name = "${user}@${host}"; + value = home-manager.lib.homeManagerConfiguration { + inherit pkgs; + extraSpecialArgs = { + inherit pkgs-stable; + }; + modules = [ (users + "/${user}") ]; + };}) (readDir users) + else {} + ) (attrNames (readDir ./hosts))); }; } diff --git a/system/hyuganatsu/default.nix b/hosts/hyuganatsu/default.nix similarity index 93% rename from system/hyuganatsu/default.nix rename to hosts/hyuganatsu/default.nix index d69f7b6..c7d10e9 100644 --- a/system/hyuganatsu/default.nix +++ b/hosts/hyuganatsu/default.nix @@ -2,7 +2,7 @@ { imports = [ - ../common + ../../system ./hardware-configuration.nix ]; diff --git a/system/hyuganatsu/hardware-configuration.nix b/hosts/hyuganatsu/hardware-configuration.nix similarity index 100% rename from system/hyuganatsu/hardware-configuration.nix rename to hosts/hyuganatsu/hardware-configuration.nix diff --git a/hosts/hyuganatsu/users/ahnwuoa/default.nix b/hosts/hyuganatsu/users/ahnwuoa/default.nix new file mode 100644 index 0000000..af3b5a6 --- /dev/null +++ b/hosts/hyuganatsu/users/ahnwuoa/default.nix @@ -0,0 +1,10 @@ +{ config, ... }: + +{ + imports = [ + ../../../../user + ]; + + home.username = "ahnwuoa"; + home.homeDirectory = "/home/${config.home.username}"; +} diff --git a/system/iyokan/default.nix b/hosts/iyokan/default.nix similarity index 100% rename from system/iyokan/default.nix rename to hosts/iyokan/default.nix diff --git a/system/iyokan/hardware-configuration.nix b/hosts/iyokan/hardware-configuration.nix similarity index 100% rename from system/iyokan/hardware-configuration.nix rename to hosts/iyokan/hardware-configuration.nix diff --git a/system/common/audio.nix b/system/audio.nix similarity index 100% rename from system/common/audio.nix rename to system/audio.nix diff --git a/system/common/bash.nix b/system/bash.nix similarity index 100% rename from system/common/bash.nix rename to system/bash.nix diff --git a/system/common/boot.nix b/system/boot.nix similarity index 100% rename from system/common/boot.nix rename to system/boot.nix diff --git a/system/common/configuration.nix b/system/configuration.nix similarity index 100% rename from system/common/configuration.nix rename to system/configuration.nix diff --git a/system/common/default.nix b/system/default.nix similarity index 100% rename from system/common/default.nix rename to system/default.nix diff --git a/system/common/display.nix b/system/display.nix similarity index 100% rename from system/common/display.nix rename to system/display.nix diff --git a/system/common/locale.nix b/system/locale.nix similarity index 100% rename from system/common/locale.nix rename to system/locale.nix diff --git a/system/common/plasma.nix b/system/plasma.nix similarity index 100% rename from system/common/plasma.nix rename to system/plasma.nix diff --git a/system/common/security.nix b/system/security.nix similarity index 100% rename from system/common/security.nix rename to system/security.nix diff --git a/system/common/users.nix b/system/users.nix similarity index 100% rename from system/common/users.nix rename to system/users.nix diff --git a/system/common/virt.nix b/system/virt.nix similarity index 100% rename from system/common/virt.nix rename to system/virt.nix diff --git a/user/home.nix b/user/home.nix index db3019e..364d9d8 100644 --- a/user/home.nix +++ b/user/home.nix @@ -1,9 +1,6 @@ -{ config, pkgs, pkgs-stable, username, homeDirectory, ... }: +{ config, pkgs, pkgs-stable, ... }: { - home.username = username; - home.homeDirectory = homeDirectory; - home.packages = with pkgs; [ (pkgs.symlinkJoin { name = "firefox"; @@ -11,7 +8,7 @@ buildInputs = [ pkgs.makeWrapper ]; postBuild = '' wrapProgram $out/bin/firefox \ - --set HOME "${homeDirectory}/.local/share" + --set HOME "${config.home.homeDirectory}/.local/share" ''; }) alacritty