-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflake.nix
82 lines (75 loc) · 2.77 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
{
description = "A flake to bootstrap a KVM template for Proxmox";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05";
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
};
outputs = { self, nixpkgs, ... }@inputs: with inputs;
let
system = "x86_64-linux";
inherit (import ./vars.nix) user;
pkgs = (import nixpkgs) { inherit system; };
inherit (nixpkgs) lib;
specialArgs = { inherit inputs pkgs system user; };
# function to generate pre-commit-checks
genChecks = system: (pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
nixpkgs-fmt.enable = true; # formatter
statix.enable = true; # linter
deadnix.enable = true; # linter
};
});
in
{
# checks
checks.${system}.pre-commit-check = genChecks system;
# See for further options:
# https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/virtualisation/proxmox-image.nix
nixosConfigurations.proxmox-host = lib.nixosSystem {
inherit specialArgs;
modules = [
"${nixpkgs}/nixos/modules/virtualisation/proxmox-image.nix"
./host/configuration.nix
{
proxmox = {
# Reference: https://pve.proxmox.com/wiki/Qemu/KVM_Virtual_Machines#qm_virtual_machines_settings
qemuConf = {
# EFI support
bios = "ovmf";
cores = 4;
memory = 1024;
net0 = "virtio=00:00:00:00:00:00,bridge=vmbr0,firewall=1";
diskSize = "20480"; # 20g
};
qemuExtraConf = {
# start the VM automatically on boot
# onboot = "1";
cpu = "host";
tags = "nixos";
};
};
nix.nixPath = [ "nixpkgs=${nixpkgs}" ];
nix.registry.nixpkgs.flake = nixpkgs;
}
];
};
packages.${system} = {
# nix build .#proxmox-image
proxmox-image = self.nixosConfigurations.proxmox-host.config.system.build.VMA;
# nix build .#proxmox-image-uncompressed
proxmox-image-uncompressed = pkgs.stdenv.mkDerivation {
name = "proxmox-image-uncompressed";
dontUnpack = true;
installPhase = ''
# create output directory
mkdir -p $out/
# basename of the vma file (without .zst)
export filename=$(basename ${self.packages.${system}.proxmox-image}/vzdump-qemu-nixos-*.vma.zst .zst)
# decompress the vma file and write it to the output directory
${pkgs.zstd}/bin/zstd -d ${self.packages.${system}.proxmox-image}/vzdump-qemu-nixos-*.vma.zst -o $out/$filename
'';
};
};
};
}