refactor: Module to ugaif and readme update
This commit is contained in:
committed by
Hunter Halloran
parent
c46b0aa685
commit
205f03337a
@@ -1,4 +1,9 @@
|
||||
{ inputs, hosts, self, system }:
|
||||
{
|
||||
inputs,
|
||||
hosts,
|
||||
self,
|
||||
system,
|
||||
}:
|
||||
# This file defines the logic for generating various build artifacts (ISOs, Netboot, LXC, etc.)
|
||||
# It exports a set of packages that can be built using `nix build .#<artifact-name>`
|
||||
let
|
||||
@@ -9,7 +14,8 @@ let
|
||||
|
||||
# Creates a self-installing ISO for a specific host configuration
|
||||
# This ISO will automatically partition the disk (using disko) and install the system
|
||||
mkInstaller = hostName:
|
||||
mkInstaller =
|
||||
hostName:
|
||||
let
|
||||
targetConfig = self.nixosConfigurations.${hostName}.config;
|
||||
targetSystem = targetConfig.system.build.toplevel;
|
||||
@@ -18,7 +24,12 @@ let
|
||||
nixpkgs.lib.nixosSystem {
|
||||
inherit system;
|
||||
specialArgs = {
|
||||
inherit inputs hostName targetSystem diskoScript;
|
||||
inherit
|
||||
inputs
|
||||
hostName
|
||||
targetSystem
|
||||
diskoScript
|
||||
;
|
||||
hostPlatform = system;
|
||||
};
|
||||
modules = [
|
||||
@@ -29,7 +40,8 @@ let
|
||||
};
|
||||
|
||||
# Uses nixos-generators to create artifacts like LXC containers, Proxmox VMA, or Live ISOs
|
||||
mkGenerator = hostName: format:
|
||||
mkGenerator =
|
||||
hostName: format:
|
||||
nixos-generators.nixosGenerate {
|
||||
inherit system;
|
||||
specialArgs = { inherit inputs; };
|
||||
@@ -44,7 +56,8 @@ let
|
||||
|
||||
# Creates Netboot (iPXE) artifacts using the native NixOS netboot module
|
||||
# Returns a system configuration that includes the netboot module
|
||||
mkNetboot = hostName:
|
||||
mkNetboot =
|
||||
hostName:
|
||||
nixpkgs.lib.nixosSystem {
|
||||
inherit system;
|
||||
specialArgs = { inherit inputs; };
|
||||
@@ -60,66 +73,110 @@ let
|
||||
hostNames = builtins.attrNames hosts.nixosConfigurations;
|
||||
|
||||
# Generate installer ISOs for hosts that have "installer-iso" in their buildMethods
|
||||
installerPackages = lib.listToAttrs (lib.concatMap (name:
|
||||
let cfg = hosts.nixosConfigurations.${name}; in
|
||||
if lib.elem "installer-iso" cfg.config.host.buildMethods then [{
|
||||
name = "installer-iso-${name}";
|
||||
value = (mkInstaller name).config.system.build.isoImage;
|
||||
}] else []
|
||||
) hostNames);
|
||||
installerPackages = lib.listToAttrs (
|
||||
lib.concatMap (
|
||||
name:
|
||||
let
|
||||
cfg = hosts.nixosConfigurations.${name};
|
||||
in
|
||||
if lib.elem "installer-iso" cfg.config.ugaif.host.buildMethods then
|
||||
[
|
||||
{
|
||||
name = "installer-iso-${name}";
|
||||
value = (mkInstaller name).config.system.build.isoImage;
|
||||
}
|
||||
]
|
||||
else
|
||||
[ ]
|
||||
) hostNames
|
||||
);
|
||||
|
||||
# Generate Live ISOs for hosts that have "iso" in their buildMethods
|
||||
isoPackages = lib.listToAttrs (lib.concatMap (name:
|
||||
let cfg = hosts.nixosConfigurations.${name}; in
|
||||
if lib.elem "iso" cfg.config.host.buildMethods then [{
|
||||
name = "iso-${name}";
|
||||
value = mkGenerator name "iso";
|
||||
}] else []
|
||||
) hostNames);
|
||||
isoPackages = lib.listToAttrs (
|
||||
lib.concatMap (
|
||||
name:
|
||||
let
|
||||
cfg = hosts.nixosConfigurations.${name};
|
||||
in
|
||||
if lib.elem "iso" cfg.config.ugaif.host.buildMethods then
|
||||
[
|
||||
{
|
||||
name = "iso-${name}";
|
||||
value = mkGenerator name "iso";
|
||||
}
|
||||
]
|
||||
else
|
||||
[ ]
|
||||
) hostNames
|
||||
);
|
||||
|
||||
# Generate iPXE artifacts (kernel, initrd, script) for hosts that have "ipxe" in their buildMethods
|
||||
ipxePackages = lib.listToAttrs (lib.concatMap (name:
|
||||
let cfg = hosts.nixosConfigurations.${name}; in
|
||||
if lib.elem "ipxe" cfg.config.host.buildMethods then [{
|
||||
name = "ipxe-${name}";
|
||||
value =
|
||||
let
|
||||
build = (mkNetboot name).config.system.build;
|
||||
in
|
||||
pkgs.symlinkJoin {
|
||||
name = "netboot-artifacts-${name}";
|
||||
paths = [
|
||||
build.netbootRamdisk
|
||||
build.kernel
|
||||
build.netbootIpxeScript
|
||||
];
|
||||
};
|
||||
}] else []
|
||||
) hostNames);
|
||||
ipxePackages = lib.listToAttrs (
|
||||
lib.concatMap (
|
||||
name:
|
||||
let
|
||||
cfg = hosts.nixosConfigurations.${name};
|
||||
in
|
||||
if lib.elem "ipxe" cfg.config.ugaif.host.buildMethods then
|
||||
[
|
||||
{
|
||||
name = "ipxe-${name}";
|
||||
value =
|
||||
let
|
||||
build = (mkNetboot name).config.system.build;
|
||||
in
|
||||
pkgs.symlinkJoin {
|
||||
name = "netboot-artifacts-${name}";
|
||||
paths = [
|
||||
build.netbootRamdisk
|
||||
build.kernel
|
||||
build.netbootIpxeScript
|
||||
];
|
||||
};
|
||||
}
|
||||
]
|
||||
else
|
||||
[ ]
|
||||
) hostNames
|
||||
);
|
||||
|
||||
# Generate LXC tarballs for hosts that have "lxc" in their buildMethods
|
||||
lxcPackages = lib.listToAttrs (lib.concatMap (name:
|
||||
let cfg = hosts.nixosConfigurations.${name}; in
|
||||
if lib.elem "lxc" cfg.config.host.buildMethods then [{
|
||||
name = "lxc-${name}";
|
||||
value =
|
||||
if cfg.config.boot.isContainer then
|
||||
cfg.config.system.build.tarball
|
||||
else
|
||||
mkGenerator name "lxc";
|
||||
}] else []
|
||||
) hostNames);
|
||||
lxcPackages = lib.listToAttrs (
|
||||
lib.concatMap (
|
||||
name:
|
||||
let
|
||||
cfg = hosts.nixosConfigurations.${name};
|
||||
in
|
||||
if lib.elem "lxc" cfg.config.ugaif.host.buildMethods then
|
||||
[
|
||||
{
|
||||
name = "lxc-${name}";
|
||||
value =
|
||||
if cfg.config.boot.isContainer then cfg.config.system.build.tarball else mkGenerator name "lxc";
|
||||
}
|
||||
]
|
||||
else
|
||||
[ ]
|
||||
) hostNames
|
||||
);
|
||||
|
||||
proxmoxPackages = lib.listToAttrs (lib.concatMap (name:
|
||||
let cfg = hosts.nixosConfigurations.${name}; in
|
||||
if lib.elem "proxmox" cfg.config.host.buildMethods then [{
|
||||
name = "proxmox-${name}";
|
||||
value =
|
||||
if cfg.config.boot.isContainer then
|
||||
cfg.config.system.build.tarball
|
||||
else
|
||||
mkGenerator name "proxmox";
|
||||
}] else []
|
||||
) hostNames);
|
||||
proxmoxPackages = lib.listToAttrs (
|
||||
lib.concatMap (
|
||||
name:
|
||||
let
|
||||
cfg = hosts.nixosConfigurations.${name};
|
||||
in
|
||||
if lib.elem "proxmox" cfg.config.ugaif.host.buildMethods then
|
||||
[
|
||||
{
|
||||
name = "proxmox-${name}";
|
||||
value =
|
||||
if cfg.config.boot.isContainer then cfg.config.system.build.tarball else mkGenerator name "proxmox";
|
||||
}
|
||||
]
|
||||
else
|
||||
[ ]
|
||||
) hostNames
|
||||
);
|
||||
in
|
||||
installerPackages // isoPackages // ipxePackages // lxcPackages // proxmoxPackages
|
||||
|
||||
@@ -1,7 +1,17 @@
|
||||
# This module defines a systemd service that automatically installs NixOS to the disk.
|
||||
# It is intended to be used in an installation ISO.
|
||||
# It expects `targetSystem` (the closure to install) and `diskoScript` (the partitioning script) to be passed as arguments.
|
||||
{ config, lib, pkgs, inputs, hostName, hostPlatform, targetSystem, diskoScript, ... }:
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
inputs,
|
||||
hostName,
|
||||
hostPlatform,
|
||||
targetSystem,
|
||||
diskoScript,
|
||||
...
|
||||
}:
|
||||
{
|
||||
environment.systemPackages = [
|
||||
pkgs.git
|
||||
@@ -14,7 +24,10 @@
|
||||
|
||||
systemd.services.auto-install = {
|
||||
description = "Automatic NixOS install for ${hostName}";
|
||||
after = [ "network-online.target" "systemd-udev-settle.service" ];
|
||||
after = [
|
||||
"network-online.target"
|
||||
"systemd-udev-settle.service"
|
||||
];
|
||||
wants = [ "network-online.target" ];
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user