Refactor everything else

This commit is contained in:
Tyler Beckman 2024-12-15 23:36:16 -07:00
parent 7539811ce3
commit 32771cf392
Signed by: Ty
GPG key ID: 2813440C772555A4
31 changed files with 135 additions and 94 deletions

106
flake.nix
View file

@ -57,103 +57,27 @@
vscode-server.url = "github:nix-community/nixos-vscode-server"; vscode-server.url = "github:nix-community/nixos-vscode-server";
}; };
outputs = inputs@{ self, nixpkgs, home-manager, nix-index-database, vscode-server, colmena, ... }: let outputs = inputs@{ self, colmena, ... }: let
system = "x86_64-linux"; utils = import ./utils {
pkgs = nixpkgs.legacyPackages.${system}; inherit inputs;
secrets = import ./secrets.nix; secrets = import ./secrets.nix;
};
in { in {
nixosConfigurations.ty-nixos = nixpkgs.lib.nixosSystem { # Setup nixos-rebuild configurations
inherit system; nixosConfigurations = {
"ty-nixos" = utils.createNixosSystem { entrypoint = ./hosts/laptop; };
"ty-laptop-server" = utils.createNixosSystem { entrypoint = ./hosts/laptop-server; };
};
modules = [ # Setup colmena configurations
./hosts/laptop colmena = utils.createColmenaHive {
hostConfigs = [
# Better command-not-found { name = "ty-nixos"; entrypoint = ./hosts/laptop; }
nix-index-database.nixosModules.nix-index { name = "ty-laptop-server"; entrypoint = ./hosts/laptop-server; sshHost = "old-lenovo-laptop"; }
{ 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;
};
};
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"; }; })
];
specialArgs = {
inherit inputs system secrets;
};
}; };
# Enable direct flake support for colmena
colmenaHive = colmena.lib.makeHive self.outputs.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"; }; })
];
};
};
}; };
} }

View file

@ -1,6 +1,9 @@
{ ... }: { ... }:
{ {
imports = [ imports = [
# Folders
./services
# Individual files
./bootloader.nix ./bootloader.nix
./display.nix ./display.nix
./locale.nix ./locale.nix
@ -8,5 +11,6 @@
./nixpkgs.nix ./nixpkgs.nix
./programs.nix ./programs.nix
./users.nix ./users.nix
./vscode-server.nix
]; ];
} }

View file

@ -0,0 +1,8 @@
{ pkgs, ... }:
{
services.vscode-server = {
enable = true;
nodejsPackage = pkgs.nodejs-18_x;
installPath = "$HOME/.vscodium-server";
};
}

View file

@ -8,9 +8,23 @@
{ {
imports = [ 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 ./hardware-configuration.nix
./modules ./config
./services
]; ];
system.stateVersion = "24.11"; system.stateVersion = "24.11";

View file

@ -1,8 +1,20 @@
{ inputs, ... }: { inputs, ... }:
{ {
imports = [ 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 ./hardware-configuration.nix
./modules ./config
]; ];
system.stateVersion = "24.05"; system.stateVersion = "24.05";

79
utils/default.nix Normal file
View file

@ -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
);
}