homelab/nixos/flake.nix
2025-06-03 23:07:46 +02:00

96 lines
3.5 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 ];
};
monitoring = nixpkgs.lib.nixosSystem {
inherit system;
modules = [ ./hosts/monitoring/host.nix ];
};
forgejo = nixpkgs.lib.nixosSystem {
inherit system;
modules = [ ./hosts/forgejo/host.nix sops-nix.nixosModules.sops ];
};
# 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
base = nixos-generators.nixosGenerate {
system = "x86_64-linux";
modules = [ ./templates/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 = {
base = base;
docker = docker;
};
};
}