dotfiles/machines/lib.nix

85 lines
2.3 KiB
Nix
Raw Normal View History

2023-11-26 12:12:22 +01:00
{
inputs,
overlays,
}: rec {
2023-06-15 01:40:55 +02:00
hmCommonConfig = {username}: ({
config,
pkgs,
...
2023-06-15 01:40:55 +02:00
}: let
homeLib = import ../home/lib.nix {inherit inputs username pkgs;};
in {
config = {
2023-06-20 21:07:44 +02:00
nixpkgs.overlays = overlays;
home-manager = {
backupFileExtension = "backup";
2023-06-15 01:40:55 +02:00
extraSpecialArgs = homeLib.extraSpecialArgs;
sharedModules = homeLib.modules;
useGlobalPkgs = true;
useUserPackages = true;
users.${username}.imports = [../home];
};
};
});
2023-11-26 12:12:22 +01:00
mkSystem = {
host,
system,
username,
2023-11-28 12:21:17 +01:00
isGraphical ? false,
extraModules ? [],
}: let
2023-11-26 12:12:22 +01:00
ldTernary = l: d:
if pkgs.stdenv.isLinux
then l
else if pkgs.stdenv.isDarwin
then d
2023-06-24 21:24:20 +02:00
else throw "Unsupported system";
2023-11-26 12:12:22 +01:00
target = ldTernary "nixosConfigurations" "darwinConfigurations";
builder = with inputs; ldTernary nixpkgs.lib.nixosSystem darwin.lib.darwinSystem;
module = ldTernary "nixosModules" "darwinModules";
hostPlatform = ldTernary "linux" "darwin";
pkgs = inputs.nixpkgs.legacyPackages.${system};
in {
${target}."${host}" = builder {
inherit system;
2023-06-15 01:40:55 +02:00
modules = with inputs;
2023-06-24 21:24:20 +02:00
[
{
2023-12-07 15:40:49 +01:00
options = let
inherit (pkgs) lib;
in {
dotfiles = {
username = lib.mkOption {
type = lib.types.str;
default = username;
description = "The username of the user";
};
desktop = lib.mkOption {
type = lib.types.enum ["gnome" "sway"];
default = "sway";
description = "The desktop environment to use";
};
};
isGraphical = lib.mkOption {
type = lib.types.bool;
default = isGraphical;
2023-12-31 06:03:50 +01:00
description = "Whether the system is a graphical target";
2023-12-07 15:40:49 +01:00
};
2023-11-28 12:21:17 +01:00
};
2023-06-24 21:24:20 +02:00
}
./common/shared
./common/${hostPlatform}
./${host}
home-manager.${module}.home-manager
]
2023-06-15 01:40:55 +02:00
++ [(hmCommonConfig {inherit username;})]
++ extraModules;
specialArgs = {inherit inputs;};
};
};
2023-11-26 12:12:22 +01:00
2023-06-24 21:24:20 +02:00
mkSystems = systems: inputs.nixpkgs.lib.mkMerge (map mkSystem systems);
}