Skip to content

Commit

Permalink
Make system module and home module a list
Browse files Browse the repository at this point in the history
So that it can be extended in a downstream flake which imports flake module on lite-config.
  • Loading branch information
yelite committed Apr 1, 2024
1 parent bbdeb12 commit 8c7292e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 40 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ An example:
];
};
# The system module will be imported for all host configurations.
systemModule = ./system;
# The home module is a Home Manager module, used by all host configurations.
homeModule = ./home;
# System modules will be imported for all host configurations.
systemModules = [ ./system ];
# Home modules are imported by Home Manager in all host configurations.
homeModules = [ ./home ];
# This directory contains per-host system module.
hostModuleDir = ./hosts;
Expand Down Expand Up @@ -161,10 +161,10 @@ have more complex tasks to accomplish within the flake.
darwin = inputs.nix-darwin.lib.darwinSystem;
};
# The system module will be imported for all host configurations.
systemModule = ./system;
# The home module is a Home Manager module, used by all host configurations.
homeModule = ./home;
# System modules will be imported for all host configurations.
systemModules = [ ./system ];
# Home modules are imported by Home Manager in all host configurations.
homeModules = [ ./home ];
# This directory contains per-host system module.
hostModuleDir = ./hosts;
Expand Down
64 changes: 32 additions & 32 deletions flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,19 @@ toplevel @ {
'';
};

systemModule = mkOption {
type = types.nullOr types.deferredModule;
systemModules = mkOption {
type = types.listOf types.deferredModule;
default = [];
description = ''
The system module to be imported by all hosts.
Shared system modules (NixOS or nix-darwin) to be imported by all hosts.
'';
};

homeModule = mkOption {
type = types.nullOr types.deferredModule;
default = null;
homeModules = mkOption {
type = types.listOf types.deferredModule;
default = [];
description = ''
The home manager module to be imported by all hosts.
Home manager modules to be imported by all hosts.
'';
};

Expand Down Expand Up @@ -190,7 +191,7 @@ toplevel @ {
The home-manager flake to use.
This should be set if home-manager isn't named as `home-manager` in flake inputs.
This has no effect if {option}`lite-config.homeModule` is null.
This has no effect if {option}`lite-config.homeModules` is empty.
'';
};

Expand All @@ -201,10 +202,10 @@ toplevel @ {
Per-user Home Manager module used for exporting homeConfigurations to be used
by systems other than NixOS and nix-darwin.
The exported homeConfigurations will import both `lite-config.homeModule` and the value of
The exported homeConfigurations will import `lite-config.homeModules` and the value of
this attrset.
This has no effect if {option}`lite-config.homeModule` is null.
This has no effect if {option}`lite-config.homeModules` is empty.
'';
example =
literalExpression
Expand All @@ -221,7 +222,7 @@ toplevel @ {
};
};

useHomeManager = cfg.homeModule != null;
useHomeManager = cfg.homeModules != [];

makeSystemConfig = hostName: hostConfig:
withSystem hostConfig.system ({liteConfigPkgs, ...}: let
Expand All @@ -242,21 +243,19 @@ toplevel @ {
modules =
[
hostModule
cfg.systemModule
{
_file = ./.;
nixpkgs.pkgs = liteConfigPkgs;
networking.hostName = hostName;
}
]
++ cfg.systemModules
++ lib.optionals useHomeManager [
homeManagerSystemModule
{
_file = ./.;
home-manager = {
sharedModules = [
cfg.homeModule
];
sharedModules = cfg.homeModules;
useGlobalPkgs = true;
extraSpecialArgs = specialArgs;
};
Expand All @@ -283,23 +282,24 @@ toplevel @ {
mkHomeConfiguration = pkgs: username: module:
cfg.homeManagerFlake.lib.homeManagerConfiguration {
inherit pkgs;
modules = [
cfg.homeModule
module
({config, ...}: let
hostPlatform = pkgs.stdenv.hostPlatform;
defaultHome =
if hostPlatform.isLinux
then "/home/${config.home.username}"
else if hostPlatform.isDarwin
then "/Users/${config.home.username}"
else throw "System type ${hostPlatform.system} not supported.";
in {
_file = ./.;
home.username = mkDefault username;
home.homeDirectory = mkDefault defaultHome;
})
];
modules =
[
module
({config, ...}: let
hostPlatform = pkgs.stdenv.hostPlatform;
defaultHome =
if hostPlatform.isLinux
then "/home/${config.home.username}"
else if hostPlatform.isDarwin
then "/Users/${config.home.username}"
else throw "System type ${hostPlatform.system} not supported.";
in {
_file = ./.;
home.username = mkDefault username;
home.homeDirectory = mkDefault defaultHome;
})
]
++ cfg.homeModules;

extraSpecialArgs = {
inherit inputs;
Expand Down

1 comment on commit 8c7292e

@jcf
Copy link

@jcf jcf commented on 8c7292e Apr 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

Please sign in to comment.