Skip to content

Commit

Permalink
feat: modularize nixosSystem with hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
yunfachi committed Nov 28, 2023
1 parent bf3d485 commit 34e97fa
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 17 deletions.
22 changes: 6 additions & 16 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,12 @@
inherit username system;
};
in {
nixosConfigurations.dekomori = nixpkgs.lib.nixosSystem {
inherit specialArgs;
modules = [
./hosts/dekomori
./modules/desktop
./options/desktop
nixosConfigurations = import ./hosts (
{inherit specialArgs;} // {isNixOS = true;}
);

home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;

home-manager.extraSpecialArgs = specialArgs;
home-manager.users."${username}" = ./home/desktop;
}
];
};
homeConfigurations = import ./hosts (
{inherit specialArgs;} // {isNixOS = false;}
);
};
}
54 changes: 54 additions & 0 deletions hosts/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
specialArgs,
isNixOS,
...
}: let
username = "${specialArgs.username}";
mkHost = host: type: let
lib = specialArgs.inputs.nixpkgs.lib;
home-manager = specialArgs.inputs.home-manager;
nixpkgs = specialArgs.inputs.nixpkgs;
in
if isNixOS
then
lib.nixosSystem {
inherit specialArgs;
modules = [
./${host}
../modules/${type}
../options/${type}
home-manager.nixosModules.home-manager
{
home-manager = {
# Because we use Home-Manager as a pure configuration manager.
useUserPackages = lib.mkForce false;
useGlobalPkgs = lib.mkForce true;

extraSpecialArgs = specialArgs;
users."${username}" = {
imports = [
../home/${type}
];
};
};
}
];
}
else
home-manager.lib.homeManagerConfiguration {
extraSpecialArgs = specialArgs;
pkgs = import nixpkgs {config.allowUnfree = lib.mkForce true;};
modules = [
../home/${type}
];
};
in
builtins.listToAttrs (builtins.attrValues (builtins.mapAttrs (host: type: {

This comment has been minimized.

Copy link
@yunfachi

yunfachi Nov 28, 2023

Author Owner
  1. Conversion of the dictionary { "dekomori" = "desktop" } into a dictionary with nested dictionaries { "dekomori" = { name = "dekomori"; value = <nixosConfig> } }.

  2. Conversion of the dictionary from the first step into a list of dictionaries [ { name = "dekomori"; value = <nixosConfig> } ].

  3. Conversion of the list from the second step back into a dictionary { dekomori = <nixosConfig> }.

name =
if isNixOS
then host
else "${username}@${host}";
value = mkHost host type;
}) {
"dekomori" = "desktop";
}))
2 changes: 1 addition & 1 deletion modules/core/user.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
users.groups."${username}" = {};
users.users."${username}" = {
# TODO: probably not needed
#home = "/home/yunfachi";
#home = "/home/${username}";
isNormalUser = true;
description = "${username}";
extraGroups = [
Expand Down

0 comments on commit 34e97fa

Please sign in to comment.