dotfiles/machines/lib.nix

89 lines
2.4 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 = {
nixpkgs = {
overlays = overlays;
config.permittedInsecurePackages = [];
};
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};
2024-02-15 18:49:22 +01:00
inherit (pkgs.lib) mkOption types;
in {
${target}."${host}" = builder {
inherit system;
2024-02-23 10:13:54 +01:00
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-02-23 10:13:54 +01: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
2023-06-24 21:24:20 +02:00
]
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);
}