nix/lib/default.nix

106 lines
3.1 KiB
Nix
Raw Normal View History

2023-12-09 22:24:58 +09:00
{ self, inputs, outputs, stateVersion, hmStateVersion, ... }: {
2023-12-09 22:10:15 +09:00
deploy = {
hostname,
platform ? "x86_64-linux",
username ? "albert"
}: {
2023-12-12 20:37:35 +09:00
user = "root";
2023-12-12 21:06:50 +09:00
sshUser = "${username}";
2023-12-10 11:07:31 +09:00
hostname = "${hostname}";
2023-12-12 20:37:35 +09:00
sshOpts = [ "-A" "-q"];
2023-12-10 12:43:57 +09:00
2023-12-11 13:09:49 +09:00
profiles = {
2023-12-13 08:53:03 +09:00
system.path = inputs.deploy-rs.lib.${platform}.activate.nixos self.nixosConfigurations.${hostname};
home-manager.path = inputs.deploy-rs.lib.${platform}.activate.home-manager self.homeConfigurations."${username}@${hostname}";
2023-12-13 09:09:39 +09:00
home-manager.user = "${username}";
2023-12-10 12:43:57 +09:00
};
2023-12-11 13:18:06 +09:00
};
2023-12-09 22:10:15 +09:00
2023-08-23 16:53:29 +09:00
# Helper function for generating home-manager configs
2023-08-31 20:22:44 +09:00
mkHome = {
hostname,
2023-09-16 21:21:45 +09:00
username ? "albert",
2023-08-31 20:22:44 +09:00
desktop ? null,
platform ? "x86_64-linux",
2024-01-06 21:48:55 +09:00
theme ? "default",
type ? "default"
2023-08-31 20:22:44 +09:00
}: inputs.home-manager.lib.homeManagerConfiguration {
2023-08-23 19:47:21 +09:00
pkgs = inputs.nixpkgs.legacyPackages.${platform};
2024-01-06 21:48:55 +09:00
extraSpecialArgs = { inherit inputs outputs desktop hostname platform username hmStateVersion theme; };
2023-08-25 19:07:54 +09:00
modules = [
../home-manager/${type}.nix
2023-08-25 19:07:54 +09:00
];
2023-08-23 16:53:29 +09:00
};
# Helper function for generating host configs
2023-08-31 20:22:44 +09:00
mkHost = {
hostname,
2023-09-16 21:21:45 +09:00
username ? "albert",
2023-08-31 20:22:44 +09:00
desktop ? null,
gpu ? null,
platform ? "x86_64-linux",
2024-01-06 21:48:55 +09:00
theme ? "default",
2023-11-26 11:51:14 +09:00
type ? "default"
2023-08-31 20:22:44 +09:00
}: inputs.nixpkgs.lib.nixosSystem {
2024-01-06 21:48:55 +09:00
specialArgs = { inherit inputs outputs desktop hostname username stateVersion gpu platform theme; };
2023-08-23 16:53:29 +09:00
modules = [
2023-11-26 11:51:14 +09:00
# Types are 'default', 'small', and 'minimal'
../nixos/${type}.nix
2023-08-27 19:50:23 +09:00
inputs.sops-nix.nixosModules.sops
inputs.lanzaboote.nixosModules.lanzaboote
2023-09-19 09:30:44 +09:00
];
2023-08-23 16:53:29 +09:00
};
2023-09-19 08:03:21 +09:00
# Combines mkHost and mkHome for image building
mkImage = {
2023-09-19 09:54:18 +09:00
hostname ,
2023-09-19 09:30:44 +09:00
username ? "albert",
desktop ? null,
platform ? "x86_64-linux",
2023-09-19 08:03:21 +09:00
gpu ? null,
2024-01-06 21:48:55 +09:00
theme ? "default",
2023-09-19 13:19:24 +09:00
format
2023-12-09 21:34:27 +09:00
}: inputs.nixos-generators.nixosGenerate {
2024-01-06 21:48:55 +09:00
specialArgs = { inherit inputs outputs desktop hostname username stateVersion hmStateVersion gpu platform theme format; };
2023-09-19 13:13:57 +09:00
system = platform;
2023-12-14 20:00:41 +09:00
format = format;
2023-09-19 10:41:49 +09:00
2023-09-19 08:45:25 +09:00
modules = [
2023-09-19 09:30:44 +09:00
../nixos
2023-09-22 08:32:18 +09:00
../nixos/common/modules/installer.nix
2023-09-19 09:30:44 +09:00
inputs.sops-nix.nixosModules.sops
inputs.lanzaboote.nixosModules.lanzaboote
2023-09-21 21:47:59 +09:00
inputs.home-manager.nixosModules.home-manager {
2024-01-06 21:48:55 +09:00
home-manager.extraSpecialArgs = { inherit inputs outputs desktop hostname username hmStateVersion stateVersion gpu platform theme format; };
2023-09-21 21:47:59 +09:00
home-manager.users."${username}" = import ../home-manager;
}
2023-09-19 09:30:44 +09:00
];
2023-09-19 08:03:21 +09:00
};
2023-12-14 19:41:07 +09:00
# Small version
2023-09-21 20:31:55 +09:00
mkMinImage = {
hostname ,
username ? "albert",
desktop ? null,
platform ? "x86_64-linux",
gpu ? null,
2024-01-06 21:48:55 +09:00
theme ? "default",
2023-09-21 20:31:55 +09:00
format
}:
inputs.nixos-generators.nixosGenerate {
2024-01-06 21:48:55 +09:00
specialArgs = { inherit inputs outputs desktop hostname username stateVersion hmStateVersion gpu platform theme format; };
2023-09-21 20:31:55 +09:00
system = platform;
2023-12-14 20:00:41 +09:00
format = format;
2023-09-21 20:31:55 +09:00
modules = [
../nixos/minimal.nix
2023-09-22 08:32:18 +09:00
../nixos/common/modules/installer.nix
2023-09-21 20:31:55 +09:00
inputs.sops-nix.nixosModules.sops
];
};
2023-08-23 16:53:29 +09:00
forAllSystems = inputs.nixpkgs.lib.genAttrs [
"aarch64-linux"
"x86_64-linux"
];
2023-09-19 08:48:43 +09:00
}