dotfiles/machines/lib.nix

93 lines
2.5 KiB
Nix
Raw Normal View History

{inputs}: rec {
2023-06-20 21:07:44 +02:00
overlays = [
(final: prev: {
nur = import inputs.nur {
nurpkgs = prev;
pkgs = prev;
repoOverrides = {
caarlos0 = inputs.caarlos0-nur.packages.${prev.system};
nekowinston = inputs.nekowinston-nur.packages.${prev.system};
};
};
2023-06-20 21:07:44 +02:00
sway-unwrapped = inputs.swayfx.packages.${prev.system}.default;
vscode-extensions = inputs.nix-vscode-extensions.extensions.${prev.system};
})
inputs.nekowinston-nur.overlays.default
];
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];
};
};
});
mkSystem = {
host,
system,
username,
extraModules ? [],
}: let
target =
if isLinux
then "nixosConfigurations"
else if isDarwin
then "darwinConfigurations"
else throw "Unsupported system";
2023-06-15 01:40:55 +02:00
builder = with inputs;
if isLinux
then nixpkgs.lib.nixosSystem
else if isDarwin
then darwin.lib.darwinSystem
else throw "Unsupported system";
module =
if isLinux
2023-06-15 01:40:55 +02:00
then "nixosModules"
else if isDarwin
2023-06-15 01:40:55 +02:00
then "darwinModules"
else throw "Unsupported system";
2023-06-24 21:24:20 +02:00
hostPlatform =
if isLinux
then "linux"
else if isDarwin
then "darwin"
else throw "Unsupported system";
pkgs = inputs.nixpkgs.legacyPackages.${system};
2023-06-15 01:40:55 +02:00
inherit (pkgs.stdenv) isDarwin isLinux;
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
[
{
options.dotfiles.username = with pkgs.lib;
mkOption {
description = "Main user of this configuration.";
type = types.str;
default = "${username}";
};
}
./common/shared
./common/${hostPlatform}
./${host}
home-manager.${module}.home-manager
]
2023-06-16 02:35:20 +02:00
++ pkgs.lib.optionals isDarwin [nekowinston-nur.darwinModules.default]
2023-06-15 01:40:55 +02:00
++ [(hmCommonConfig {inherit username;})]
++ extraModules;
};
};
2023-06-24 21:24:20 +02:00
mkSystems = systems: inputs.nixpkgs.lib.mkMerge (map mkSystem systems);
}