From 668c2f17c426adfbbfd1fbb9b2a715be6fd65fee Mon Sep 17 00:00:00 2001 From: xezo360hye Date: Tue, 6 Aug 2024 01:58:25 +0300 Subject: [PATCH] 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 --- flake.nix | 35 ++++++++++++++++++++--------------- home/common.nix | 5 ----- system/common.nix | 4 ---- system/maidena.nix | 9 --------- system/tokishiko.nix | 8 -------- 5 files changed, 20 insertions(+), 41 deletions(-) diff --git a/flake.nix b/flake.nix index 90235e5..4971c77 100644 --- a/flake.nix +++ b/flake.nix @@ -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; }; } diff --git a/home/common.nix b/home/common.nix index f7b8283..677a582 100644 --- a/home/common.nix +++ b/home/common.nix @@ -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"; }; } diff --git a/system/common.nix b/system/common.nix index 443ecc1..a96f1d2 100644 --- a/system/common.nix +++ b/system/common.nix @@ -84,8 +84,4 @@ in tappingDragLock = false; }; }; - - - # Something important - system.stateVersion = "24.05"; } diff --git a/system/maidena.nix b/system/maidena.nix index a1118a0..fd4de79 100644 --- a/system/maidena.nix +++ b/system/maidena.nix @@ -1,13 +1,4 @@ { - inputs, - config, - pkgs, - lib, - ... -}: -{ - networking.hostName = "maidena"; - services = { desktopManager.plasma6.enable = true; displayManager.sddm = { diff --git a/system/tokishiko.nix b/system/tokishiko.nix index 260a709..cc8b530 100644 --- a/system/tokishiko.nix +++ b/system/tokishiko.nix @@ -1,12 +1,4 @@ { - inputs, - config, - pkgs, - lib, - ... -}: -{ - networking.hostName = "tokishiko"; console.keyMap = "no"; services = {