dotfiles/machines/lib.nix

108 lines
3.1 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 = ldTernary inputs.nixpkgs.lib.nixosSystem inputs.darwin.lib.darwinSystem;
2024-05-07 18:20:52 +02:00
module = ldTernary "nixosModules" "darwinModules";
hostPlatform = ldTernary "linux" "darwin";
2023-11-26 12:12:22 +01:00
linuxModules = [ inputs.nixos-cosmic.nixosModules.default ];
darwinModules = [ inputs.nekowinston-nur.darwinModules.default ];
2024-05-07 18:20:52 +02:00
pkgs = inputs.nixpkgs.legacyPackages.${system};
inherit (pkgs) lib;
2024-05-07 18:20:52 +02:00
inherit (pkgs.lib) mkOption types;
in
{
${target}."${host}" = builder {
inherit system;
modules =
[
{
options = {
dotfiles = {
username = mkOption {
type = types.str;
default = username;
description = "The username of the user";
};
desktop = mkOption {
type = types.nullOr (
types.enum [
"cosmic"
"gnome"
"hyprland"
"sway"
]
);
default = if (pkgs.stdenv.isLinux && isGraphical) then "sway" else null;
description = "The desktop environment to use";
};
2023-12-07 15:40:49 +01:00
};
isGraphical = mkOption {
type = types.bool;
default = isGraphical;
description = "Whether the system is a graphical target";
2023-12-07 15:40:49 +01:00
};
};
config.networking.hostName = host;
}
./common/shared
./common/${hostPlatform}
./${host}
inputs.home-manager.${module}.home-manager
(hmCommonConfig { inherit username; })
]
++ lib.optionals pkgs.stdenv.isLinux linuxModules
++ lib.optionals pkgs.stdenv.isDarwin darwinModules
++ extraModules;
2024-05-07 18:20:52 +02:00
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);
}