dotfiles/machines/lib.nix

98 lines
2.7 KiB
Nix
Raw Normal View History

2024-05-07 18:20:52 +02:00
{ inputs, overlays }:
rec {
hmCommonConfig =
{ username }:
(
{ config, pkgs, ... }:
let
homeLib = import ../home/lib.nix { inherit inputs username pkgs; };
in
{
config = {
nixpkgs = {
overlays = overlays;
config.permittedInsecurePackages = [ ];
};
home-manager = {
backupFileExtension = "backup";
extraSpecialArgs = homeLib.extraSpecialArgs;
sharedModules = homeLib.modules;
useGlobalPkgs = true;
useUserPackages = true;
users.${username}.imports = [ ../home ];
};
};
}
);
2023-11-26 12:12:22 +01:00
2024-05-07 18:20:52 +02:00
mkSystem =
{
host,
system,
username,
isGraphical ? false,
extraModules ? [ ],
}:
let
ldTernary =
l: d:
if pkgs.stdenv.isLinux then
l
else if pkgs.stdenv.isDarwin then
d
else
throw "Unsupported system";
target = ldTernary "nixosConfigurations" "darwinConfigurations";
builder = with inputs; ldTernary nixpkgs.lib.nixosSystem darwin.lib.darwinSystem;
module = ldTernary "nixosModules" "darwinModules";
hostPlatform = ldTernary "linux" "darwin";
2023-11-26 12:12:22 +01:00
2024-05-07 18:20:52 +02:00
pkgs = inputs.nixpkgs.legacyPackages.${system};
inherit (pkgs.lib) mkOption types;
in
{
${target}."${host}" = builder {
inherit system;
modules = [
2023-06-24 21:24:20 +02:00
{
2024-02-15 18:49:22 +01:00
options = {
2023-12-07 15:40:49 +01:00
dotfiles = {
2024-02-15 18:49:22 +01:00
username = mkOption {
type = types.str;
2023-12-07 15:40:49 +01:00
default = username;
description = "The username of the user";
};
2024-02-15 18:49:22 +01:00
desktop = mkOption {
2024-05-07 18:20:52 +02:00
type = types.nullOr (
types.enum [
"gnome"
"sway"
]
);
2023-12-07 15:40:49 +01:00
default = "sway";
description = "The desktop environment to use";
};
};
2024-02-15 18:49:22 +01:00
isGraphical = mkOption {
type = types.bool;
2023-12-07 15:40:49 +01:00
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
};
2024-02-23 10:13:54 +01:00
config.dotfiles.desktop = pkgs.lib.mkIf (!isGraphical) null;
2024-02-15 18:49:22 +01:00
config.networking.hostName = host;
2023-06-24 21:24:20 +02:00
}
./common/shared
./common/${hostPlatform}
./${host}
2024-02-23 10:13:54 +01:00
inputs.home-manager.${module}.home-manager
2024-05-07 18:20:52 +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);
}