nix/lib/default.nix
2023-12-12 13:27:40 +09:00

121 lines
No EOL
3.6 KiB
Nix

{ self, inputs, outputs, stateVersion, hmStateVersion, ... }: {
deploy = {
hostname,
platform ? "x86_64-linux",
username ? "albert"
}: {
user = "${username}";
hostname = "${hostname}";
sshOpts = [ "-A" ];
profiles = {
system = {
path = inputs.deploy-rs.lib.${platform}.activate.nixos self.nixosConfigurations.${hostname};
user = "root";
sshUser = "${username}";
};
home-manager = {
path = inputs.deploy-rs.lib.${platform}.activate.home-manager self.homeConfigurations."${username}@${hostname}";
user = "${username}";
sshUser = "${username}";
};
};
};
# Helper function for generating home-manager configs
mkHome = {
hostname,
username ? "albert",
desktop ? null,
platform ? "x86_64-linux",
theme ? "default"
}: inputs.home-manager.lib.homeManagerConfiguration {
pkgs = inputs.nixpkgs.legacyPackages.${platform};
extraSpecialArgs = { inherit inputs outputs desktop hostname platform username hmStateVersion theme; };
modules = [
../home-manager
];
};
# Helper function for generating host configs
mkHost = {
hostname,
username ? "albert",
desktop ? null,
gpu ? null,
platform ? "x86_64-linux",
theme ? "default",
type ? "default"
}: inputs.nixpkgs.lib.nixosSystem {
specialArgs = { inherit inputs outputs desktop hostname username stateVersion gpu platform theme; };
modules = [
# Types are 'default', 'small', and 'minimal'
../nixos/${type}.nix
inputs.sops-nix.nixosModules.sops
inputs.lanzaboote.nixosModules.lanzaboote
];
};
# Combines mkHost and mkHome for image building
mkImage = {
hostname ,
username ? "albert",
desktop ? null,
platform ? "x86_64-linux",
gpu ? null,
theme ? "default",
format
}: inputs.nixos-generators.nixosGenerate {
specialArgs = { inherit inputs outputs desktop hostname username stateVersion hmStateVersion gpu platform theme format; };
format = format;
system = platform;
modules = [
../nixos
../nixos/common/modules/installer.nix
inputs.sops-nix.nixosModules.sops
inputs.lanzaboote.nixosModules.lanzaboote
inputs.home-manager.nixosModules.home-manager {
home-manager.extraSpecialArgs = { inherit inputs outputs desktop hostname username hmStateVersion stateVersion gpu platform theme format; };
home-manager.users."${username}" = import ../home-manager;
}
];
};
# Combines mkHost and mkHome for image building
mkMinImage = {
hostname ,
username ? "albert",
desktop ? null,
platform ? "x86_64-linux",
gpu ? null,
theme ? "default",
format
}:
inputs.nixos-generators.nixosGenerate {
specialArgs = { inherit inputs outputs desktop hostname username stateVersion hmStateVersion gpu platform theme format; };
format = format;
system = platform;
modules = [
../nixos/minimal.nix
../nixos/common/modules/installer.nix
inputs.sops-nix.nixosModules.sops
];
};
forAllSystems = inputs.nixpkgs.lib.genAttrs [
"aarch64-linux"
"x86_64-linux"
];
# Checks for deploy-rs - Makes deploy-rs fail when system evaluations fail
checks = builtins.mapAttrs (system: deployLib: deployLib.deployChecks self.deploy) deploy-rs.lib;
# Devshell for bootstrapping; acessible via 'nix develop'
devShells = libx.forAllSystems (system:
let pkgs = nixpkgs.legacyPackages.${system};
in import ./shell.nix { inherit pkgs sops-nix deploy-rs system; }
);
}