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 = {
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:
let
inherit (self) outputs;
inherit (nixpkgs) lib;
username = "andrey";
hostnames = [ "tokishiko" "maidena" ];
stateVersion = "24.05";
mkSystem = hostname: {
makeSystem = hostname: {
"${hostname}" = nixpkgs.lib.nixosSystem {
specialArgs = { inherit inputs; };
system = "x86_64-linux";
modules = [
./system/common.nix
./system/${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 {
pkgs = nixpkgs.legacyPackages.x86_64-linux;
extraSpecialArgs = inputs;
modules = [
nixvim.homeManagerModules.nixvim
nethack.homeManagerModules.nethack
modules = homeManagerModules ++ [
./home/${hostname}.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 {
nixosConfigurations = merge mkSystem;
homeConfigurations = merge mkHome;
nixosConfigurations = forEachHost makeSystem;
homeConfigurations = forEachHost makeHome;
};
}

View File

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

View File

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

View File

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

View File

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