From 8c5ba7f4c35a691dd4c44887b15e20d90abae264 Mon Sep 17 00:00:00 2001 From: Evie Litherland-Smith Date: Thu, 31 Aug 2023 12:22:29 +0100 Subject: [PATCH] Major rewrite to system config Move home-manager setup back into being NixOS module where possible Parameterise common elements of system config to minimise rewriting and pass as function to all places needed --- flake.nix | 149 ++++++++++++++++--------------- hosts/Legion/configuration.nix | 12 +-- hosts/Legion/home.nix | 9 +- hosts/Monarch/home.nix | 11 ++- hosts/Ronin/configuration.nix | 16 +--- hosts/Ronin/home.nix | 9 +- hosts/Vanguard/configuration.nix | 21 +---- hosts/Vanguard/home.nix | 17 ++-- hosts/hyprland.nix | 17 +++- 9 files changed, 115 insertions(+), 146 deletions(-) diff --git a/flake.nix b/flake.nix index 21043963..3679553a 100644 --- a/flake.nix +++ b/flake.nix @@ -22,83 +22,90 @@ }; }; - outputs = { self, nixpkgs, home-manager, hyprland, anyrun, wallpapers, tokyonight, }: - let shell = "zsh"; + outputs = + { self, nixpkgs, home-manager, hyprland, anyrun, wallpapers, tokyonight, }: + let + systemConfig = + { hostName, user ? "xenia", system ? "x86_64-linux", shell ? "zsh" }: + let + pkgs = import nixpkgs { + inherit system; + config.allowUnfree = true; + overlays = [ + (final: prev: { + waybar = prev.waybar.overrideAttrs (oldAttrs: { + mesonFlags = oldAttrs.mesonFlags ++ [ "-Dexperimental=true" ]; + }); + }) + ]; + }; + in nixpkgs.lib.nixosSystem { + inherit pkgs; + specialArgs = { inherit hostName user shell hyprland; }; + modules = [ + ./hosts/${hostName}/configuration.nix + ./services/${hostName}.nix + { + networking = { inherit hostName; }; + users.users.${user} = { + isNormalUser = true; + description = "Evie Litherland-Smith"; + group = "users"; + extraGroups = [ "networkmanager" "wheel" "video" ]; + shell = pkgs.${shell}; + openssh.authorizedKeys.keys = import ./auth/authorized_keys.nix; + }; + } + home-manager.nixosModules.home-manager + { + home-manager = { + useGlobalPkgs = true; + useUserPackages = false; + extraSpecialArgs = { + inherit user hyprland anyrun wallpapers tokyonight; + shellConfig = ./home/shell/${shell}.nix; + }; + users.${user} = import ./hosts/${hostName}/home.nix; + }; + } + ]; + }; + homeConfig = { hostName, user, system ? "x86_64-linux", shell ? "zsh" }: + home-manager.lib.homeManagerConfiguration { + pkgs = nixpkgs.legacyPackages.${system}; + extraSpecialArgs = { + inherit user shell hyprland anyrun wallpapers tokyonight; + shellConfig = ./home/shell/${shell}.nix; + }; + modules = [ ./hosts/${hostName}/home.nix ]; + }; in { - nixosConfigurations = let - userConfig = { - isNormalUser = true; - description = "Evie Litherland-Smith"; - group = "users"; - extraGroups = [ "networkmanager" "wheel" "video" ]; - shell = pkgs.${shell}; - openssh.authorizedKeys.keys = import ./auth/authorized_keys.nix; + nixosConfigurations = { + Legion = systemConfig { + hostName = "Legion"; + user = "elitherl"; + system = "x86_64-linux"; + shell = "zsh"; }; - specialArgs = { inherit shell userConfig hyprland; }; - waybar-experimental-overlay = final: prev: { - waybar = prev.waybar.overrideAttrs (oldAttrs: { - mesonFlags = oldAttrs.mesonFlags ++ [ "-Dexperimental=true" ]; - }); + Ronin = systemConfig { + hostName = "Ronin"; + user = "elitherl"; + system = "x86_64-linux"; + shell = "zsh"; }; - system = "x86_64-linux"; - pkgs = import nixpkgs { - inherit system; - config.allowUnfree = true; - overlays = [ waybar-experimental-overlay ]; - }; - in { - Legion = let hostname = "Legion"; - in nixpkgs.lib.nixosSystem { - inherit pkgs specialArgs; - modules = [ ./hosts/${hostname}/configuration.nix ]; - }; - Vanguard = let hostname = "Vanguard"; - in nixpkgs.lib.nixosSystem { - inherit pkgs specialArgs; - modules = [ ./hosts/${hostname}/configuration.nix ]; - }; - Ronin = let hostname = "Ronin"; - in nixpkgs.lib.nixosSystem { - inherit pkgs specialArgs; - modules = [ ./hosts/${hostname}/configuration.nix ]; + Vanguard = systemConfig { + hostName = "Vanguard"; + user = "xenia"; + system = "x86_64-linux"; + shell = "zsh"; }; }; - homeConfigurations = let - extraSpecialArgs = { - inherit hyprland anyrun wallpapers tokyonight; - shellConfig = ./home/shell/${shell}.nix; - }; - in { - # NixOS home configurations - "xenia@Vanguard" = let - hostname = "Vanguard"; - pkgs = self.nixosConfigurations.${hostname}.pkgs; - in home-manager.lib.homeManagerConfiguration { - inherit pkgs extraSpecialArgs; - modules = [ ./hosts/${hostname}/home.nix ]; - }; - "xenia@Legion" = let - hostname = "Legion"; - pkgs = self.nixosConfigurations.${hostname}.pkgs; - in home-manager.lib.homeManagerConfiguration { - inherit pkgs extraSpecialArgs; - modules = [ ./hosts/${hostname}/home.nix ]; - }; - "elitherl@Ronin" = let - hostname = "Ronin"; - pkgs = self.nixosConfigurations.${hostname}.pkgs; - in home-manager.lib.homeManagerConfiguration { - inherit pkgs extraSpecialArgs; - modules = [ ./hosts/${hostname}/home.nix ]; - }; - # Legacy home configurations - "tux@Monarch" = let - hostname = "Monarch"; + homeConfigurations = { + "tux@Monarch" = homeConfig { + hostName = "Monarch"; + user = "tux"; system = "aarch64-darwin"; - pkgs = nixpkgs.legacyPackages.${system}; - in home-manager.lib.homeManagerConfiguration { - inherit pkgs extraSpecialArgs; - modules = [ ./hosts/${hostname}/home.nix ]; + shell = "zsh"; }; }; }; diff --git a/hosts/Legion/configuration.nix b/hosts/Legion/configuration.nix index 17a91b03..8a16456b 100644 --- a/hosts/Legion/configuration.nix +++ b/hosts/Legion/configuration.nix @@ -1,24 +1,17 @@ # Edit this configuration file to define what should be installed on # your system. Help is available in the configuration.nix(5) man page # and in the NixOS manual (accessible by running `nixos-help`). -{userConfig, ...}: let - user = "xenia"; - hostName = "Legion"; -in { +{ ... }: { imports = [ # Include the results of the hardware scan. ./hardware-configuration.nix ../common.nix - ../../services/${hostName}.nix ]; # Use the systemd-boot EFI boot loader. boot.loader.systemd-boot.enable = true; boot.loader.efi.canTouchEfiVariables = true; - networking = { - hostName = hostName; # Define your hostname. - nameservers = ["192.168.1.230" "127.0.0.1" "9.9.9.9"]; - }; + networking.nameservers = [ "192.168.1.230" "127.0.0.1" "9.9.9.9" ]; system.autoUpgrade = { enable = true; dates = "02:00"; @@ -28,7 +21,6 @@ in { upper = "05:00"; }; }; - users.users.${user} = userConfig; # This value determines the NixOS release from which the default # settings for stateful data, like file locations and database versions diff --git a/hosts/Legion/home.nix b/hosts/Legion/home.nix index 921e4482..4d357bab 100644 --- a/hosts/Legion/home.nix +++ b/hosts/Legion/home.nix @@ -1,7 +1,5 @@ -{ pkgs, shellConfig, ... }: -let - username = "xenia"; - homeDirectory = "/home/${username}"; +{ pkgs, user, shellConfig, ... }: +let homeDirectory = "/home/${user}"; in { imports = [ shellConfig @@ -11,7 +9,8 @@ in { ../../home/tui ]; home = { - inherit username homeDirectory; + inherit homeDirectory; + username = user; stateVersion = "22.11"; }; programs = { diff --git a/hosts/Monarch/home.nix b/hosts/Monarch/home.nix index 86417707..51fa3216 100644 --- a/hosts/Monarch/home.nix +++ b/hosts/Monarch/home.nix @@ -1,10 +1,8 @@ -{ pkgs, ... }: -let - username = "tux"; - homeDirectory = "/Users/${username}"; +{ pkgs, user, shell ? "zsh", ... }: +let homeDirectory = "/Users/${user}"; in { imports = [ - ../../home/shell/zsh.nix + ../../home/shell/${shell}.nix ../../home/git ../../home/ssh ../../home/tui @@ -13,7 +11,8 @@ in { ../../home/emacs ]; home = { - inherit username homeDirectory; + inherit homeDirectory; + username = user; stateVersion = "23.05"; packages = with pkgs; [ coreutils-prefixed ]; }; diff --git a/hosts/Ronin/configuration.nix b/hosts/Ronin/configuration.nix index 556ee5a5..f1c27f27 100644 --- a/hosts/Ronin/configuration.nix +++ b/hosts/Ronin/configuration.nix @@ -1,16 +1,11 @@ # Edit this configuration file to define what should be installed on # your system. Help is available in the configuration.nix(5) man page # and in the NixOS manual (accessible by running ‘nixos-help’). -{ userConfig, ... }: -let - user = "elitherl"; - hostName = "Ronin"; -in { +{ ... }: { imports = [ # Include the results of the hardware scan. ./hardware-configuration.nix ../hyprland.nix - ../../services/${hostName}.nix ]; # Bootloader. boot.loader.systemd-boot.enable = true; @@ -25,20 +20,11 @@ in { boot.initrd.luks.devices."luks-761eeb11-3091-4142-9232-4fb33165eccd".keyFile = "/crypto_keyfile.bin"; - networking.hostName = hostName; # Define your hostname. hardware.bluetooth.enable = true; environment.etc."ppp/options".text = '' ipcp-accept-remote ''; programs.light.enable = true; - users.users.${user} = userConfig; - services.greetd = { - enable = true; - settings = { - default_session.user = user; - initial_session.user = user; - }; - }; # This value determines the NixOS release from which the default # settings for stateful data, like file locations and database versions diff --git a/hosts/Ronin/home.nix b/hosts/Ronin/home.nix index 58d7829f..9072ddd3 100644 --- a/hosts/Ronin/home.nix +++ b/hosts/Ronin/home.nix @@ -1,11 +1,10 @@ -{ pkgs, lib, shellConfig, ... }: -let - username = "elitherl"; - homeDirectory = "/home/${username}"; +{ pkgs, lib, user, shellConfig, ... }: +let homeDirectory = "/home/${user}"; in { imports = [ shellConfig ../../home ]; home = { - inherit username homeDirectory; + inherit homeDirectory; + username = user; stateVersion = "22.11"; packages = with pkgs; [ openfortivpn diff --git a/hosts/Vanguard/configuration.nix b/hosts/Vanguard/configuration.nix index 618ed381..79829a9b 100644 --- a/hosts/Vanguard/configuration.nix +++ b/hosts/Vanguard/configuration.nix @@ -1,25 +1,17 @@ # Edit this configuration file to define what should be installed on # your system. Help is available in the configuration.nix(5) man page # and in the NixOS manual (accessible by running ‘nixos-help’). -{ pkgs, userConfig, ... }: -let - user = "xenia"; - hostName = "Vanguard"; -in { +{ pkgs, ... }: { imports = [ # Include the results of the hardware scan. ./hardware-configuration.nix ../hyprland.nix - ../../services/${hostName}.nix ]; # Bootloader. boot.loader.systemd-boot.enable = true; boot.loader.efi.canTouchEfiVariables = true; - networking = { - hostName = hostName; # Define your hostname. - nameservers = [ "192.168.1.230" "9.9.9.9" ]; - }; + networking.nameservers = [ "192.168.1.230" "9.9.9.9" ]; environment.systemPackages = with pkgs; [ mesa ]; hardware = { bluetooth.enable = true; @@ -32,15 +24,6 @@ in { dedicatedServer.openFirewall = true; }; - users.users.${user} = userConfig; - services.greetd = { - enable = true; - settings = { - default_session.user = user; - initial_session.user = user; - }; - }; - # This value determines the NixOS release from which the default # settings for stateful data, like file locations and database versions # on your system were taken. It‘s perfectly fine and recommended to leave diff --git a/hosts/Vanguard/home.nix b/hosts/Vanguard/home.nix index 33bd60f6..0b01a225 100644 --- a/hosts/Vanguard/home.nix +++ b/hosts/Vanguard/home.nix @@ -1,15 +1,10 @@ -{ shellConfig, ... }: -let - username = "xenia"; - homeDirectory = "/home/${username}"; -in -{ - imports = [ - shellConfig - ../../home - ]; +{ user, shellConfig, ... }: +let homeDirectory = "/home/${user}"; +in { + imports = [ shellConfig ../../home ]; home = { - inherit username homeDirectory; + inherit homeDirectory; + username = user; stateVersion = "22.11"; }; programs.home-manager.enable = true; diff --git a/hosts/hyprland.nix b/hosts/hyprland.nix index e9f42064..aafa0fac 100644 --- a/hosts/hyprland.nix +++ b/hosts/hyprland.nix @@ -1,4 +1,4 @@ -{ pkgs, hyprland, ... }: { +{ pkgs, hyprland, user ? "xenia", ... }: { imports = [ ./desktop.nix hyprland.nixosModules.default ]; environment.systemPackages = with pkgs; [ xdg-utils @@ -21,9 +21,18 @@ blueman.enable = true; gvfs.enable = true; tumbler.enable = true; - greetd.settings = { - default_session.command = "Hyprland"; - initial_session.command = "Hyprland"; + greetd = { + enable = true; + settings = { + default_session = { + inherit user; + command = "Hyprland"; + }; + initial_session = { + inherit user; + command = "Hyprland"; + }; + }; }; }; fonts = {