refactor(flake, system): improve code structure

Refactor configuration generation

- Inherit lib from nixpkgs
- Rename functions (mkHome -> makeHome, merge -> forEachHost
- Relocate some variables' definitions into config generator functions
- Create separate function to track home-manager modules
This commit is contained in:
xezo360hye 2024-08-06 01:58:25 +03:00
parent 2f0934d02b
commit 668c2f17c4
5 changed files with 20 additions and 41 deletions

View File

@ -16,49 +16,54 @@
nethack = { nethack = {
url = git+https://git.psf.lt/xezo360hye/nethack?shallow=1; url = git+https://git.psf.lt/xezo360hye/nethack?shallow=1;
#url = git+ssh://git@git.psf.lt/xezo360hye/nethack?shallow=1;
#url = path:/home/andrey/nethack;
}; };
# nixpkgs-2405.url = github:nixos/nixpkgs/nixos-24.05;
# hm-2405.url = github:nix-community/home-manager/release-24.05;
}; };
outputs = { self, nixpkgs, home-manager, nixvim, nethack, ... } @ inputs: outputs = { self, nixpkgs, home-manager, nixvim, nethack, ... } @ inputs:
let let
inherit (self) outputs; inherit (self) outputs;
inherit (nixpkgs) lib;
username = "andrey"; username = "andrey";
hostnames = [ "tokishiko" "maidena" ]; hostnames = [ "tokishiko" "maidena" ];
stateVersion = "24.05";
mkSystem = hostname: { makeSystem = hostname: {
"${hostname}" = nixpkgs.lib.nixosSystem { "${hostname}" = nixpkgs.lib.nixosSystem {
specialArgs = { inherit inputs; }; specialArgs = { inherit inputs; };
system = "x86_64-linux";
modules = [ modules = [
./system/common.nix ./system/common.nix
./system/${hostname}.nix ./system/${hostname}.nix
./hardware/${hostname}.nix ./hardware/${hostname}.nix
{
system.stateVersion = stateVersion;
networking.hostName = hostname;
}
]; ];
}; };
}; };
mkHome = hostname: { extractModule = { homeManagerModules, ... }: homeManagerModules."${lib.head (lib.attrNames homeManagerModules)}";
homeManagerModules = map extractModule [ nixvim nethack ];
makeHome = hostname: {
"${username}@${hostname}" = home-manager.lib.homeManagerConfiguration { "${username}@${hostname}" = home-manager.lib.homeManagerConfiguration {
pkgs = nixpkgs.legacyPackages.x86_64-linux; pkgs = nixpkgs.legacyPackages.x86_64-linux;
extraSpecialArgs = inputs; modules = homeManagerModules ++ [
modules = [
nixvim.homeManagerModules.nixvim
nethack.homeManagerModules.nethack
./home/${hostname}.nix ./home/${hostname}.nix
./home/common.nix ./home/common.nix
{
news.display = "show";
home.username = username;
home.homeDirectory = "/home/${username}";
home.stateVersion = stateVersion;
}
]; ];
}; };
}; };
merge = fn: nixpkgs.lib.fold nixpkgs.lib.mergeAttrs {} (map fn hostnames); forEachHost = fn: lib.fold lib.mergeAttrs {} (map fn hostnames);
in { in {
nixosConfigurations = merge mkSystem; nixosConfigurations = forEachHost makeSystem;
homeConfigurations = merge mkHome; homeConfigurations = forEachHost makeHome;
}; };
} }

View File

@ -56,7 +56,6 @@
}; };
news.display = "show";
nixpkgs.config.allowUnfree = true; nixpkgs.config.allowUnfree = true;
home = { home = {
@ -76,9 +75,5 @@
sessionVariables = { sessionVariables = {
ANI_CLI_PLAYER = "mpv"; ANI_CLI_PLAYER = "mpv";
}; };
username = "andrey";
homeDirectory = "/home/andrey";
stateVersion = "24.05";
}; };
} }

View File

@ -84,8 +84,4 @@ in
tappingDragLock = false; tappingDragLock = false;
}; };
}; };
# Something important
system.stateVersion = "24.05";
} }

View File

@ -1,13 +1,4 @@
{ {
inputs,
config,
pkgs,
lib,
...
}:
{
networking.hostName = "maidena";
services = { services = {
desktopManager.plasma6.enable = true; desktopManager.plasma6.enable = true;
displayManager.sddm = { displayManager.sddm = {

View File

@ -1,12 +1,4 @@
{ {
inputs,
config,
pkgs,
lib,
...
}:
{
networking.hostName = "tokishiko";
console.keyMap = "no"; console.keyMap = "no";
services = { services = {