nixos/flake.nix
xezo360hye 668c2f17c4 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
2024-08-06 01:59:04 +03:00

70 lines
1.9 KiB
Nix

{
description = "My homebrew NixOS configurations";
inputs = {
nixpkgs.url = github:nixos/nixpkgs/nixos-unstable;
home-manager = {
url = github:nix-community/home-manager;
inputs.nixpkgs.follows = "nixpkgs";
};
nixvim = {
url = github:nix-community/nixvim;
inputs.nixpkgs.follows = "nixpkgs";
};
nethack = {
url = git+https://git.psf.lt/xezo360hye/nethack?shallow=1;
};
};
outputs = { self, nixpkgs, home-manager, nixvim, nethack, ... } @ inputs:
let
inherit (self) outputs;
inherit (nixpkgs) lib;
username = "andrey";
hostnames = [ "tokishiko" "maidena" ];
stateVersion = "24.05";
makeSystem = hostname: {
"${hostname}" = nixpkgs.lib.nixosSystem {
specialArgs = { inherit inputs; };
modules = [
./system/common.nix
./system/${hostname}.nix
./hardware/${hostname}.nix
{
system.stateVersion = stateVersion;
networking.hostName = 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;
modules = homeManagerModules ++ [
./home/${hostname}.nix
./home/common.nix
{
news.display = "show";
home.username = username;
home.homeDirectory = "/home/${username}";
home.stateVersion = stateVersion;
}
];
};
};
forEachHost = fn: lib.fold lib.mergeAttrs {} (map fn hostnames);
in {
nixosConfigurations = forEachHost makeSystem;
homeConfigurations = forEachHost makeHome;
};
}