nix/lib/default.nix

217 lines
6.9 KiB
Nix
Raw Normal View History

2024-03-25 11:53:39 +09:00
{ lib ? lib, self, inputs, outputs, stateVersion, hmStateVersion , ... }: {
2023-12-09 22:10:15 +09:00
deploy = {
hostname,
2024-01-31 12:31:01 +09:00
system ? "x86_64-linux",
2023-12-09 22:10:15 +09:00
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 = {
2024-01-31 12:31:01 +09:00
system.path = inputs.deploy-rs.lib.${system}.activate.nixos self.nixosConfigurations.${hostname};
home-manager.path = inputs.deploy-rs.lib.${system}.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,
2024-01-31 12:31:01 +09:00
system ? "x86_64-linux",
2024-06-12 19:15:32 +09:00
theme ? "default",
2024-07-15 19:09:15 +09:00
type ? "default",
2023-08-31 20:22:44 +09:00
}: inputs.home-manager.lib.homeManagerConfiguration {
2024-01-31 12:31:01 +09:00
pkgs = inputs.nixpkgs.legacyPackages.${system};
2024-07-15 20:39:14 +09:00
extraSpecialArgs = { inherit inputs outputs desktop hostname system username hmStateVersion theme; };
2024-02-19 14:40:42 +09:00
modules = [ ../home-manager/${type}.nix ];
2023-08-23 16:53:29 +09:00
};
2024-03-20 17:23:30 +09:00
mkContainer = {
2024-03-21 18:51:41 +09:00
hostname,
2024-03-20 17:23:30 +09:00
username ? "albert",
2024-03-22 22:36:01 +09:00
desktop ? null,
2024-03-20 17:23:30 +09:00
system ? "x86_64-linux",
2024-06-12 19:15:32 +09:00
theme ? "default",
2024-03-22 22:36:01 +09:00
type ? "default",
2024-03-20 17:23:30 +09:00
repo ? "nixpkgs",
2024-03-22 22:36:01 +09:00
unfree ? false,
2024-03-26 09:00:46 +09:00
ip ? null,
2024-04-05 22:51:54 +09:00
ephemeral ? false,
deployment_type ? "containers",
2024-03-22 22:36:01 +09:00
pkgs ? import inputs.${repo}
{ inherit system; config.allowUnfree = unfree; hostPlatform = system; },
pkgs-unstable ? import inputs.nixpkgs-unstable
{ inherit system; config.allowUnfree = unfree; hostPlatform = system; }
2024-03-20 17:23:30 +09:00
}: {
2024-04-05 22:51:54 +09:00
bindMounts = lib.mkMerge [
2024-03-25 11:53:39 +09:00
( import ../nixos/containers/mounts.nix )
( import ../nixos/containers/${hostname}/mounts.nix )
];
2024-04-07 21:05:15 +09:00
ephemeral = ephemeral;
2024-04-05 22:51:54 +09:00
autoStart = true;
privateNetwork = true;
2024-04-07 08:42:00 +09:00
hostBridge = "nix-br0";
localAddress = "192.168.2.${ip}";
2024-03-25 12:30:28 +09:00
restartIfChanged = true;
2024-04-07 08:42:00 +09:00
enableTun = true;
specialArgs = { inherit pkgs-unstable hostname username desktop theme system repo unfree stateVersion ip deployment_type; };
config = { lib, config, pkgs-unstable, hostname, username, desktop, theme, system, repo, stateVersion, ip, deployment_type, ... }: {
2024-03-26 09:00:46 +09:00
nixpkgs.pkgs = import inputs.${repo} {
inherit system;
config.allowUnfree = unfree;
hostPlatform = system;
};
2024-03-21 20:27:53 +09:00
imports = [
../nixos/containers
2024-03-25 12:30:28 +09:00
inputs.sops-nix.nixosModules.sops
2024-04-26 20:49:35 +09:00
inputs.home-manager.nixosModules.home-manager {
home-manager.extraSpecialArgs = { inherit inputs outputs desktop hostname username hmStateVersion stateVersion system theme ; };
home-manager.users."${username}" = import ../home-manager;
}
2024-03-21 20:27:53 +09:00
];
2024-03-20 17:23:30 +09:00
};
};
2024-04-26 20:49:35 +09:00
# Helper function for generating host configs
mkDeck = {
hostname,
username ? "albert",
desktop ? null,
gpu ? null,
system ? "x86_64-linux",
2024-06-12 19:15:32 +09:00
theme ? "default",
2024-04-26 20:49:35 +09:00
type ? "default",
repo ? "nixpkgs-unstable",
deployment_type ? "hosts",
2024-04-26 20:49:35 +09:00
}: inputs.${repo}.lib.nixosSystem {
specialArgs = {
inherit inputs outputs desktop hostname username hmStateVersion stateVersion gpu system theme self deployment_type;
2024-04-26 20:49:35 +09:00
# Some packages (ie, Vintage Story) I want to keep on unstable no matter what default repo I use
pkgs-unstable = import inputs.nixpkgs-unstable {
inherit system;
2024-04-26 22:00:24 +09:00
config.allowUnfree = true;
2024-04-26 20:49:35 +09:00
hostPlatform = system;
};
};
modules = [
# Types are 'default', 'small', and 'minimal'
2024-04-27 15:59:29 +09:00
../nixos/${type}.nix
2024-04-26 20:49:35 +09:00
inputs.sops-nix.nixosModules.sops
inputs.lanzaboote.nixosModules.lanzaboote
];
};
2024-02-09 22:59:27 +09:00
# Helper function for generating host configs
2024-02-09 22:38:38 +09:00
mkHost = {
hostname,
username ? "albert",
desktop ? null,
gpu ? null,
system ? "x86_64-linux",
2024-06-12 19:15:32 +09:00
theme ? "default",
2024-02-09 22:38:38 +09:00
type ? "default",
repo ? "nixpkgs",
deployment_type ? "hosts",
2024-02-09 22:38:38 +09:00
unfree ? false
2024-03-20 17:26:47 +09:00
}: inputs.${repo}.lib.nixosSystem {
2024-04-26 20:49:35 +09:00
specialArgs = {
inherit inputs outputs desktop hostname username hmStateVersion stateVersion gpu system theme self deployment_type;
2024-04-26 20:49:35 +09:00
# Choose whether to pull from stable or unstable
pkgs = import inputs.${repo} {
inherit system;
config.allowUnfree = unfree;
hostPlatform = system;
};
# Some packages (ie, Vintage Story) I want to keep on unstable no matter what default repo I use
pkgs-unstable = import inputs.nixpkgs-unstable {
inherit system;
config.allowUnfree = unfree;
hostPlatform = system;
};
2024-02-09 22:42:09 +09:00
};
2024-02-09 22:50:43 +09:00
2024-04-26 20:49:35 +09:00
modules = [
# Types are 'default', 'small', and 'minimal'
../nixos/${type}.nix
inputs.sops-nix.nixosModules.sops
inputs.lanzaboote.nixosModules.lanzaboote
2024-02-09 22:59:27 +09:00
];
2024-02-09 22:23:02 +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,
2024-01-31 12:31:01 +09:00
system ? "x86_64-linux",
2023-09-19 08:03:21 +09:00
gpu ? null,
2024-06-12 19:15:32 +09:00
theme ? "default",
2024-04-24 10:46:03 +09:00
repo ? "nixpkgs",
unfree ? false,
2023-09-19 13:19:24 +09:00
format
2023-12-09 21:34:27 +09:00
}: inputs.nixos-generators.nixosGenerate {
2024-04-24 10:46:03 +09:00
specialArgs = {
2024-07-15 20:39:14 +09:00
inherit inputs outputs desktop hostname username stateVersion hmStateVersion gpu system theme format;
2024-04-24 10:46:03 +09:00
# Choose whether to pull from stable or unstable
pkgs = import inputs.${repo} {
inherit system;
config.allowUnfree = unfree;
hostPlatform = system;
};
# Some packages (ie, Vintage Story) I want to keep on unstable no matter what default repo I use
pkgs-unstable = import inputs.nixpkgs-unstable {
inherit system;
config.allowUnfree = unfree;
hostPlatform = system;
};
};
2024-01-31 12:31:01 +09:00
system = system;
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
2024-05-08 08:28:11 +09:00
"${inputs.nixpkgs}/nixos/modules/profiles/all-hardware.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-07-15 20:39:14 +09:00
home-manager.extraSpecialArgs = { inherit inputs outputs desktop hostname username hmStateVersion stateVersion gpu system 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,
2024-01-31 12:32:27 +09:00
system ? "x86_64-linux",
2023-09-21 20:31:55 +09:00
gpu ? null,
2024-06-12 19:15:32 +09:00
theme ? "default",
2023-09-21 20:31:55 +09:00
format
2024-03-20 17:26:47 +09:00
}: inputs.nixos-generators.nixosGenerate {
2024-01-31 12:31:01 +09:00
specialArgs = { inherit inputs outputs desktop hostname username stateVersion hmStateVersion gpu system theme format; };
system = system;
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"
];
2024-02-19 14:40:42 +09:00
}