flake-parts/setups/nixos: improve code

This commit is contained in:
Gabriel Arazas 2024-03-05 20:38:33 +08:00
parent d15434a96b
commit c17eb9b29e
No known key found for this signature in database
GPG Key ID: ADE0C41DAB221FCC

View File

@ -20,10 +20,8 @@ let
# Just to be sure, we'll use everything with the given nixpkgs' stdlib. # Just to be sure, we'll use everything with the given nixpkgs' stdlib.
lib = nixpkgs.lib; lib = nixpkgs.lib;
# A modified version of `nixosSystem` from nixpkgs flake. There is a # Evaluating the system ourselves (which is trivial) instead of relying
# recent change at nixpkgs (at 039f73f134546e59ec6f1b56b4aff5b81d889f64) # on nixpkgs.lib.nixosSystem flake output.
# that prevents setting our own custom functions so we'll have to
# evaluate the NixOS system ourselves.
nixosSystem = args: import "${nixpkgs}/nixos/lib/eval-config.nix" args; nixosSystem = args: import "${nixpkgs}/nixos/lib/eval-config.nix" args;
in in
(lib.makeOverridable nixosSystem) { (lib.makeOverridable nixosSystem) {
@ -355,21 +353,18 @@ let
config = lib.mkMerge [ config = lib.mkMerge [
(lib.mkIf hasHomeManagerUsers { (lib.mkIf hasHomeManagerUsers {
users.users = users.users =
lib.mkMerge lib.mapAttrs
(lib.mapAttrsToList (name: hmUser: hmUser.userConfig)
(name: hmUser: { ${name} = hmUser.userConfig; }) setupConfig.homeManagerUsers.users;
setupConfig.homeManagerUsers.users);
home-manager.users = lib.mkMerge home-manager.users =
(lib.mapAttrsToList lib.mapAttrs
(name: hmUser: { (name: hmUser: {
${name} = { lib, ... }: {
imports = imports =
partsConfig.setups.home-manager.configs.${name}.modules partsConfig.setups.home-manager.configs.${name}.modules
++ hmUser.additionalModules; ++ hmUser.additionalModules;
};
}) })
setupConfig.homeManagerUsers.users); setupConfig.homeManagerUsers.users;
}) })
(lib.mkIf (isNixpkgs "global") { (lib.mkIf (isNixpkgs "global") {
@ -378,15 +373,12 @@ let
# Disable all options that are going to be blocked once # Disable all options that are going to be blocked once
# `home-manager.useGlobalPkgs` is used. # `home-manager.useGlobalPkgs` is used.
home-manager.users = home-manager.users =
lib.mkMerge lib.mapAttrs
(lib.mapAttrsToList
(name: _: { (name: _: {
${name} = {
nixpkgs.overlays = lib.mkForce null; nixpkgs.overlays = lib.mkForce null;
nixpkgs.config = lib.mkForce null; nixpkgs.config = lib.mkForce null;
};
}) })
setupConfig.homeManagerUsers.users); setupConfig.homeManagerUsers.users;
# Then apply all of the user overlays into the nixpkgs instance # Then apply all of the user overlays into the nixpkgs instance
# of the NixOS system. # of the NixOS system.
@ -414,15 +406,12 @@ let
(lib.mkIf (isNixpkgs "separate") { (lib.mkIf (isNixpkgs "separate") {
home-manager.useGlobalPkgs = lib.mkForce false; home-manager.useGlobalPkgs = lib.mkForce false;
home-manager.users = home-manager.users =
lib.mkMerge lib.mapAttrs
(lib.mapAttrsToList
(name: _: { (name: _: {
${name} = {
nixpkgs.overlays = nixpkgs.overlays =
partsConfig.setups.home-manager.configs.${name}.overlays; partsConfig.setups.home-manager.configs.${name}.overlays;
};
}) })
setupConfig.homeManagerUsers.users); setupConfig.homeManagerUsers.users;
}) })
]; ];
} }