From 32771cf3922689527a8ea7e593a4522c36f82020 Mon Sep 17 00:00:00 2001 From: Tyler Beckman Date: Sun, 15 Dec 2024 23:36:16 -0700 Subject: [PATCH] Refactor everything else --- flake.nix | 106 +++--------------- .../{modules => config}/bootloader.nix | 0 .../{modules => config}/default.nix | 4 + .../{modules => config}/display.nix | 0 .../{modules => config}/locale.nix | 0 .../{modules => config}/networking.nix | 0 .../{modules => config}/nixpkgs.nix | 0 .../{modules => config}/programs.nix | 0 .../{ => config}/services/default.nix | 0 .../{ => config}/services/jellyfin.nix | 0 .../{modules => config}/users.nix | 0 hosts/laptop-server/config/vscode-server.nix | 8 ++ hosts/laptop-server/default.nix | 18 ++- .../laptop/{modules => config}/bluetooth.nix | 0 .../laptop/{modules => config}/bootloader.nix | 0 hosts/laptop/{modules => config}/default.nix | 0 hosts/laptop/{modules => config}/desktop.nix | 0 hosts/laptop/{modules => config}/display.nix | 0 .../{modules => config}/environment.nix | 0 hosts/laptop/{modules => config}/fonts.nix | 0 hosts/laptop/{modules => config}/locale.nix | 0 hosts/laptop/{modules => config}/mounts.nix | 0 .../laptop/{modules => config}/networking.nix | 0 hosts/laptop/{modules => config}/nixpkgs.nix | 0 hosts/laptop/{modules => config}/nvidia.nix | 0 hosts/laptop/{modules => config}/packages.nix | 0 hosts/laptop/{modules => config}/sound.nix | 0 hosts/laptop/{modules => config}/swap.nix | 0 hosts/laptop/{modules => config}/users.nix | 0 hosts/laptop/default.nix | 14 ++- utils/default.nix | 79 +++++++++++++ 31 files changed, 135 insertions(+), 94 deletions(-) rename hosts/laptop-server/{modules => config}/bootloader.nix (100%) rename hosts/laptop-server/{modules => config}/default.nix (67%) rename hosts/laptop-server/{modules => config}/display.nix (100%) rename hosts/laptop-server/{modules => config}/locale.nix (100%) rename hosts/laptop-server/{modules => config}/networking.nix (100%) rename hosts/laptop-server/{modules => config}/nixpkgs.nix (100%) rename hosts/laptop-server/{modules => config}/programs.nix (100%) rename hosts/laptop-server/{ => config}/services/default.nix (100%) rename hosts/laptop-server/{ => config}/services/jellyfin.nix (100%) rename hosts/laptop-server/{modules => config}/users.nix (100%) create mode 100644 hosts/laptop-server/config/vscode-server.nix rename hosts/laptop/{modules => config}/bluetooth.nix (100%) rename hosts/laptop/{modules => config}/bootloader.nix (100%) rename hosts/laptop/{modules => config}/default.nix (100%) rename hosts/laptop/{modules => config}/desktop.nix (100%) rename hosts/laptop/{modules => config}/display.nix (100%) rename hosts/laptop/{modules => config}/environment.nix (100%) rename hosts/laptop/{modules => config}/fonts.nix (100%) rename hosts/laptop/{modules => config}/locale.nix (100%) rename hosts/laptop/{modules => config}/mounts.nix (100%) rename hosts/laptop/{modules => config}/networking.nix (100%) rename hosts/laptop/{modules => config}/nixpkgs.nix (100%) rename hosts/laptop/{modules => config}/nvidia.nix (100%) rename hosts/laptop/{modules => config}/packages.nix (100%) rename hosts/laptop/{modules => config}/sound.nix (100%) rename hosts/laptop/{modules => config}/swap.nix (100%) rename hosts/laptop/{modules => config}/users.nix (100%) create mode 100644 utils/default.nix diff --git a/flake.nix b/flake.nix index fa804dc..ceb943b 100755 --- a/flake.nix +++ b/flake.nix @@ -57,103 +57,27 @@ vscode-server.url = "github:nix-community/nixos-vscode-server"; }; - outputs = inputs@{ self, nixpkgs, home-manager, nix-index-database, vscode-server, colmena, ... }: let - system = "x86_64-linux"; - pkgs = nixpkgs.legacyPackages.${system}; - secrets = import ./secrets.nix; + outputs = inputs@{ self, colmena, ... }: let + utils = import ./utils { + inherit inputs; + secrets = import ./secrets.nix; + }; in { - nixosConfigurations.ty-nixos = nixpkgs.lib.nixosSystem { - inherit system; - - modules = [ - ./hosts/laptop - - # Better command-not-found - nix-index-database.nixosModules.nix-index - { programs.nix-index-database.comma.enable = true; } - - # Home manager - home-manager.nixosModules.home-manager - ./home-manager - { meta.home-manager.preset = "plasma-desktop"; } - ]; - - specialArgs = { - inherit inputs system secrets; - }; + # Setup nixos-rebuild configurations + nixosConfigurations = { + "ty-nixos" = utils.createNixosSystem { entrypoint = ./hosts/laptop; }; + "ty-laptop-server" = utils.createNixosSystem { entrypoint = ./hosts/laptop-server; }; }; - nixosConfigurations."ty-laptop-server" = nixpkgs.lib.nixosSystem { - inherit system; - - modules = [ - ./hosts/laptop-server - - # Better command-not-found - nix-index-database.nixosModules.nix-index - { programs.nix-index-database.comma.enable = true; } - - # Home manager - home-manager.nixosModules.home-manager - ./home-manager - { meta.home-manager.preset = "cli"; } - - # VSCode server support - vscode-server.nixosModules.default - ({ pkgs, ... }: { services.vscode-server = { enable = true; nodejsPackage = pkgs.nodejs-18_x; installPath = "$HOME/.vscodium-server"; }; }) + # Setup colmena configurations + colmena = utils.createColmenaHive { + hostConfigs = [ + { name = "ty-nixos"; entrypoint = ./hosts/laptop; } + { name = "ty-laptop-server"; entrypoint = ./hosts/laptop-server; sshHost = "old-lenovo-laptop"; } ]; - - specialArgs = { - inherit inputs system secrets; - }; }; + # Enable direct flake support for colmena colmenaHive = colmena.lib.makeHive self.outputs.colmena; - colmena = { - meta = { - nixpkgs = import nixpkgs { system = "x86_64-linux"; }; - specialArgs = { - inherit inputs secrets; - - system = "x86_64-linux"; - }; - allowApplyAll = false; - }; - - "ty-laptop-server" = { config, ... }: { - deployment = { - replaceUnknownProfiles = false; - targetUser = "root"; - targetHost = "old-lenovo-laptop"; # i should rename my tailscale devices properly - targetPort = 22; - }; - - imports = [ - ./hosts/laptop-server - - # Better command-not-found - nix-index-database.nixosModules.nix-index - { programs.nix-index-database.comma.enable = true; } - - # Home manager - home-manager.nixosModules.home-manager - ./home-manager - { - ty-home-manager-options = { - plasma.enable = false; - beets.enable = false; - firefox.enable = false; - thunderbird.enable = false; - rescrobbled.enable = false; - vscode.enable = false; - }; - } - - # VSCode server support - vscode-server.nixosModules.default - ({ pkgs, ... }: { services.vscode-server = { enable = true; nodejsPackage = pkgs.nodejs-18_x; installPath = "$HOME/.vscodium-server"; }; }) - ]; - }; - }; }; } diff --git a/hosts/laptop-server/modules/bootloader.nix b/hosts/laptop-server/config/bootloader.nix similarity index 100% rename from hosts/laptop-server/modules/bootloader.nix rename to hosts/laptop-server/config/bootloader.nix diff --git a/hosts/laptop-server/modules/default.nix b/hosts/laptop-server/config/default.nix similarity index 67% rename from hosts/laptop-server/modules/default.nix rename to hosts/laptop-server/config/default.nix index cb562aa..0e65250 100644 --- a/hosts/laptop-server/modules/default.nix +++ b/hosts/laptop-server/config/default.nix @@ -1,6 +1,9 @@ { ... }: { imports = [ + # Folders + ./services + # Individual files ./bootloader.nix ./display.nix ./locale.nix @@ -8,5 +11,6 @@ ./nixpkgs.nix ./programs.nix ./users.nix + ./vscode-server.nix ]; } \ No newline at end of file diff --git a/hosts/laptop-server/modules/display.nix b/hosts/laptop-server/config/display.nix similarity index 100% rename from hosts/laptop-server/modules/display.nix rename to hosts/laptop-server/config/display.nix diff --git a/hosts/laptop-server/modules/locale.nix b/hosts/laptop-server/config/locale.nix similarity index 100% rename from hosts/laptop-server/modules/locale.nix rename to hosts/laptop-server/config/locale.nix diff --git a/hosts/laptop-server/modules/networking.nix b/hosts/laptop-server/config/networking.nix similarity index 100% rename from hosts/laptop-server/modules/networking.nix rename to hosts/laptop-server/config/networking.nix diff --git a/hosts/laptop-server/modules/nixpkgs.nix b/hosts/laptop-server/config/nixpkgs.nix similarity index 100% rename from hosts/laptop-server/modules/nixpkgs.nix rename to hosts/laptop-server/config/nixpkgs.nix diff --git a/hosts/laptop-server/modules/programs.nix b/hosts/laptop-server/config/programs.nix similarity index 100% rename from hosts/laptop-server/modules/programs.nix rename to hosts/laptop-server/config/programs.nix diff --git a/hosts/laptop-server/services/default.nix b/hosts/laptop-server/config/services/default.nix similarity index 100% rename from hosts/laptop-server/services/default.nix rename to hosts/laptop-server/config/services/default.nix diff --git a/hosts/laptop-server/services/jellyfin.nix b/hosts/laptop-server/config/services/jellyfin.nix similarity index 100% rename from hosts/laptop-server/services/jellyfin.nix rename to hosts/laptop-server/config/services/jellyfin.nix diff --git a/hosts/laptop-server/modules/users.nix b/hosts/laptop-server/config/users.nix similarity index 100% rename from hosts/laptop-server/modules/users.nix rename to hosts/laptop-server/config/users.nix diff --git a/hosts/laptop-server/config/vscode-server.nix b/hosts/laptop-server/config/vscode-server.nix new file mode 100644 index 0000000..952cdc0 --- /dev/null +++ b/hosts/laptop-server/config/vscode-server.nix @@ -0,0 +1,8 @@ +{ pkgs, ... }: +{ + services.vscode-server = { + enable = true; + nodejsPackage = pkgs.nodejs-18_x; + installPath = "$HOME/.vscodium-server"; + }; +} \ No newline at end of file diff --git a/hosts/laptop-server/default.nix b/hosts/laptop-server/default.nix index 3daba20..42ab5aa 100644 --- a/hosts/laptop-server/default.nix +++ b/hosts/laptop-server/default.nix @@ -8,9 +8,23 @@ { imports = [ + ## External modules + + # Better command-not-found + inputs.nix-index-database.nixosModules.nix-index + { programs.nix-index-database.comma.enable = true; } + + # Home manager + inputs.home-manager.nixosModules.home-manager + ../../home-manager + { meta.home-manager.preset = "cli"; } + + # VSCode server support + inputs.vscode-server.nixosModules.default + + ## Normal configuration ./hardware-configuration.nix - ./modules - ./services + ./config ]; system.stateVersion = "24.11"; diff --git a/hosts/laptop/modules/bluetooth.nix b/hosts/laptop/config/bluetooth.nix similarity index 100% rename from hosts/laptop/modules/bluetooth.nix rename to hosts/laptop/config/bluetooth.nix diff --git a/hosts/laptop/modules/bootloader.nix b/hosts/laptop/config/bootloader.nix similarity index 100% rename from hosts/laptop/modules/bootloader.nix rename to hosts/laptop/config/bootloader.nix diff --git a/hosts/laptop/modules/default.nix b/hosts/laptop/config/default.nix similarity index 100% rename from hosts/laptop/modules/default.nix rename to hosts/laptop/config/default.nix diff --git a/hosts/laptop/modules/desktop.nix b/hosts/laptop/config/desktop.nix similarity index 100% rename from hosts/laptop/modules/desktop.nix rename to hosts/laptop/config/desktop.nix diff --git a/hosts/laptop/modules/display.nix b/hosts/laptop/config/display.nix similarity index 100% rename from hosts/laptop/modules/display.nix rename to hosts/laptop/config/display.nix diff --git a/hosts/laptop/modules/environment.nix b/hosts/laptop/config/environment.nix similarity index 100% rename from hosts/laptop/modules/environment.nix rename to hosts/laptop/config/environment.nix diff --git a/hosts/laptop/modules/fonts.nix b/hosts/laptop/config/fonts.nix similarity index 100% rename from hosts/laptop/modules/fonts.nix rename to hosts/laptop/config/fonts.nix diff --git a/hosts/laptop/modules/locale.nix b/hosts/laptop/config/locale.nix similarity index 100% rename from hosts/laptop/modules/locale.nix rename to hosts/laptop/config/locale.nix diff --git a/hosts/laptop/modules/mounts.nix b/hosts/laptop/config/mounts.nix similarity index 100% rename from hosts/laptop/modules/mounts.nix rename to hosts/laptop/config/mounts.nix diff --git a/hosts/laptop/modules/networking.nix b/hosts/laptop/config/networking.nix similarity index 100% rename from hosts/laptop/modules/networking.nix rename to hosts/laptop/config/networking.nix diff --git a/hosts/laptop/modules/nixpkgs.nix b/hosts/laptop/config/nixpkgs.nix similarity index 100% rename from hosts/laptop/modules/nixpkgs.nix rename to hosts/laptop/config/nixpkgs.nix diff --git a/hosts/laptop/modules/nvidia.nix b/hosts/laptop/config/nvidia.nix similarity index 100% rename from hosts/laptop/modules/nvidia.nix rename to hosts/laptop/config/nvidia.nix diff --git a/hosts/laptop/modules/packages.nix b/hosts/laptop/config/packages.nix similarity index 100% rename from hosts/laptop/modules/packages.nix rename to hosts/laptop/config/packages.nix diff --git a/hosts/laptop/modules/sound.nix b/hosts/laptop/config/sound.nix similarity index 100% rename from hosts/laptop/modules/sound.nix rename to hosts/laptop/config/sound.nix diff --git a/hosts/laptop/modules/swap.nix b/hosts/laptop/config/swap.nix similarity index 100% rename from hosts/laptop/modules/swap.nix rename to hosts/laptop/config/swap.nix diff --git a/hosts/laptop/modules/users.nix b/hosts/laptop/config/users.nix similarity index 100% rename from hosts/laptop/modules/users.nix rename to hosts/laptop/config/users.nix diff --git a/hosts/laptop/default.nix b/hosts/laptop/default.nix index 51090fa..72c1cd7 100644 --- a/hosts/laptop/default.nix +++ b/hosts/laptop/default.nix @@ -1,8 +1,20 @@ { inputs, ... }: { imports = [ + ## External modules + + # Better command-not-found + inputs.nix-index-database.nixosModules.nix-index + { programs.nix-index-database.comma.enable = true; } + + # Home manager + inputs.home-manager.nixosModules.home-manager + ../../home-manager + { meta.home-manager.preset = "plasma-desktop"; } + + ## Normal configuration ./hardware-configuration.nix - ./modules + ./config ]; system.stateVersion = "24.05"; diff --git a/utils/default.nix b/utils/default.nix new file mode 100644 index 0000000..69f2597 --- /dev/null +++ b/utils/default.nix @@ -0,0 +1,79 @@ +{ inputs, secrets }: +{ + createNixosSystem = { + system ? "x86_64-linux", + entrypoint + }: inputs.nixpkgs.lib.nixosSystem { + inherit system; + + specialArgs = { + inherit inputs system secrets; + }; + + modules = [ entrypoint ]; + }; + + createColmenaHive = { + defaultSystem ? "x86_64-linux", + hostConfigs ? [] + }: { + # Set meta options for the colmena hive + meta = { + # Standard options + allowApplyAll = false; + # Defaults for nodes + nixpkgs = import inputs.nixpkgs { system = defaultSystem; }; + specialArgs = { + inherit inputs secrets; + system = defaultSystem; + }; + # Overrides for individual nodes + nodeNixpkgs = ( + builtins.foldl' + (acc: cur: + acc // { + ${cur.name} = import inputs.nixpkgs { system = cur.system; }; + } + ) + {} + (builtins.filter + (c: builtins.hasAttr "system" c && c.system != defaultSystem) + hostConfigs) + ); + nodeSpecialArgs = ( + builtins.foldl' + (acc: cur: + acc // { + ${cur.name} = { + inherit inputs secrets; + system = cur.system; + }; + } + ) + {} + (builtins.filter + (c: builtins.hasAttr "system" c && c.system != defaultSystem) + hostConfigs) + ); + }; + } // ( + # Add all of the hosts + builtins.foldl' + (acc: cur: + acc // { + ${cur.name} = { ... }: { + deployment = { + replaceUnknownProfiles = false; + targetUser = if (builtins.hasAttr "sshUser" cur) then cur.sshUser else "root"; + targetHost = if (builtins.hasAttr "sshHost" cur) then cur.sshHost else cur.name; + targetPort = if (builtins.hasAttr "sshPort" cur) then cur.sshPort else 22; + }; + + imports = [ cur.entrypoint ]; + }; + } + ) + {} + hostConfigs + ); +} \ No newline at end of file