homelab/nixos/flake.nix
plasmagoat dd7b32ac51
All checks were successful
Hello World / test (push) Successful in 3s
new base image
2025-06-07 04:33:52 +02:00

107 lines
3.8 KiB
Nix
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{
description = "Unified flake for Proxmox base image + live NixOS VMs";
inputs = {
# Nixpkgs repo for system packages
nixpkgs.url = "github:nixos/nixpkgs";
# nixos-generators lets us produce a "proxmox"-formatted image
nixos-generators = {
url = "github:nix-community/nixos-generators";
inputs.nixpkgs.follows = "nixpkgs";
};
# sops-nix secret management
sops-nix = {
url = "github:Mic92/sops-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, nixos-generators, sops-nix,... }:
let
system = "x86_64-linux";
################################################################################
# A) Define “live” NixOS VM configurations under nixosConfigurations
################################################################################
liveVMs = {
traefik = nixpkgs.lib.nixosSystem {
inherit system;
modules = [ ./hosts/traefik/host.nix ];
};
sandbox = nixpkgs.lib.nixosSystem {
inherit system;
modules = [ ./hosts/sandbox/host.nix ];
};
dns = nixpkgs.lib.nixosSystem {
inherit system;
modules = [ ./hosts/dns/host.nix ];
};
monitoring = nixpkgs.lib.nixosSystem {
inherit system;
modules = [ ./hosts/monitoring/host.nix sops-nix.nixosModules.sops ];
};
forgejo = nixpkgs.lib.nixosSystem {
inherit system;
modules = [ ./hosts/forgejo/host.nix sops-nix.nixosModules.sops ];
};
runner01 = nixpkgs.lib.nixosSystem {
inherit system;
modules = [ ./hosts/forgejo-runner/host.nix sops-nix.nixosModules.sops ];
specialArgs.runnerId = "01";
};
# dockerHost = pkgs.lib.nixosSystem {
# inherit system;
# modules = [
# ./configuration.nix
# ./users/plasmagoat.nix
# ./hosts/docker-host.nix # DockerHost VM settings (shown below)
# ];
# };
};
################################################################################
# B) Use nixos-generators to produce “template” images for Proxmox
################################################################################
# 1) Existing Proxmox “base” image generator
proxmoxTemplate = nixos-generators.nixosGenerate {
system = "x86_64-linux";
modules = [ ./base.nix ];
format = "proxmox"; # outputs a .vma.zst suitable for qmrestore
};
# 2) A “docker” generator which builds a Proxmoxready template
docker = nixos-generators.nixosGenerate {
system = "x86_64-linux";
modules = [ ./templates/docker.nix ];
format = "proxmox";
};
in
{
################################################################################
# 1) Export “live” VM configs so you can run:
# nixos-rebuild switch --flake .#traefik --target-host root@<traefik-IP>
# nixos-rebuild switch --flake .#sandbox --target-host root@<sandbox-IP>
# nixos-rebuild switch --flake .#dockerHost --target-host root@<dockerHost-IP>
################################################################################
nixosConfigurations = liveVMs;
################################################################################
# 2) Export Proxmox template images under packages.x86_64-linux:
#
# • proxmox → `nix build .#proxmox` (generic base)
# • docker → `nix build .#docker` (docker template)
################################################################################
packages.x86_64-linux = {
proxmoxTemplate = proxmoxTemplate;
docker = docker;
};
};
}