refactor names for customs and templates for more clarity. templates are self contained instead of depending on others
This commit is contained in:
parent
ad2092531c
commit
82513c0714
4 changed files with 101 additions and 88 deletions
|
|
@ -17,7 +17,7 @@
|
|||
name = "playfulness";
|
||||
};
|
||||
|
||||
nixmox = customizeImage images.debian.v12.proxmox (images.debian.customs.rooted // {
|
||||
nixmox = customizeImage images.debian.v12.proxmox (images.debian.templates.rooted // {
|
||||
name = "nixmox";
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,63 +1,27 @@
|
|||
# ready to use customizations to apply on images
|
||||
{ pkgs, lib, system, commons, ... }:
|
||||
# create additional useful customized images from templates and upstream images
|
||||
{ pkgs, lib, system, commons, upstreamImages, templates, ... }:
|
||||
with commons;
|
||||
with scriptsNFiles;
|
||||
let
|
||||
upstreamImageName = "v12";
|
||||
in
|
||||
{
|
||||
# essential functionalities like ssh, networking etc
|
||||
essentials = {
|
||||
install = [ "htop" "openssh-server" "inetutils-ping" "dnsutils" "cloud-guest-utils" "qemu-guest-agent" ];
|
||||
commands = ''
|
||||
upload ${grub-ifnames-0}:/etc/default/grub.d/90-ifnames-0.cfg
|
||||
upload ${grub-disable-microcode}:/etc/default/grub.d/00-disable-microcode.cfg
|
||||
run-command mount /boot/efi && update-grub
|
||||
upload ${eth0-dhcp-network}:/etc/systemd/network/00-eth0-dhcp.network
|
||||
run ${ssh-service-override-conf-create}
|
||||
upload ${grow-root-sh}:/usr/local/sbin/grow-root.sh
|
||||
upload ${grow-root-service}:/etc/systemd/system/grow-root.service
|
||||
run-command systemctl enable grow-root.service
|
||||
'';
|
||||
${upstreamImageName} = rec {
|
||||
# default image with essential functionalities like ssh, networking etc
|
||||
default = customizeImage upstreamImages.${upstreamImageName} (templates.essentials // {
|
||||
name = "default";
|
||||
hostname = "debian";
|
||||
});
|
||||
|
||||
# playground with easy root access
|
||||
play = customizeImage default (templates.rooted // {
|
||||
name = "play";
|
||||
nameToHostname = false;
|
||||
});
|
||||
|
||||
# proxmox
|
||||
proxmox = customizeImage default (templates.proxmoxOnDebian12 // {
|
||||
name = "proxmox";
|
||||
});
|
||||
};
|
||||
|
||||
# set easy root access
|
||||
rooted = {
|
||||
run = ''
|
||||
# set root password and ssh access
|
||||
echo "root:root" | chpasswd
|
||||
sed -i '/PasswordAuthentication no/d' "/etc/ssh/sshd_config"
|
||||
echo "PasswordAuthentication yes\nPermitRootLogin yes" >> "/etc/ssh/sshd_config"
|
||||
'';
|
||||
};
|
||||
|
||||
# install proxmox
|
||||
proxmoxOnDebian12 = {
|
||||
diskSize = "+2G";
|
||||
smp = 4;
|
||||
memSize = 4096;
|
||||
run = ''
|
||||
# script originally taken from https://pve.proxmox.com/wiki/Install_Proxmox_VE_on_Debian_12_Bookworm
|
||||
# exit if error
|
||||
set -e
|
||||
|
||||
# grow root partition - script installed in "base" image
|
||||
/usr/local/sbin/grow-root.sh
|
||||
|
||||
# mount efi for grub changes
|
||||
mount /boot/efi
|
||||
|
||||
# add proxmox repo
|
||||
echo "deb [arch=amd64] http://download.proxmox.com/debian/pve bookworm pve-no-subscription" > /etc/apt/sources.list.d/pve-install-repo.list
|
||||
wget https://enterprise.proxmox.com/debian/proxmox-release-bookworm.gpg -O /etc/apt/trusted.gpg.d/proxmox-release-bookworm.gpg
|
||||
apt-get update && apt full-upgrade -y --no-install-recommends;
|
||||
|
||||
# necessary precursors
|
||||
echo "0.0.0.0\t\t`cat /etc/hostname`" >> /etc/hosts; # necessary for SSL certificate creation
|
||||
mkdir -p /run/network; # bug https://github.com/CumulusNetworks/ifupdown2/issues/276
|
||||
|
||||
# install
|
||||
apt install -y proxmox-default-kernel proxmox-ve postfix open-iscsi chrony --no-install-recommends;
|
||||
|
||||
# remove previous kernels
|
||||
apt remove -y os-prober linux-image-amd64 'linux-image-6.*';
|
||||
'';
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -3,14 +3,14 @@ let
|
|||
# upstream distro images
|
||||
upstreamImagesJSON = lib.importJSON ./upstream.json;
|
||||
upstreamImages = lib.mapAttrs (name: src: pkgs.fetchurl src) upstreamImagesJSON.${system};
|
||||
customs = (import ./customs.nix) { inherit pkgs lib system commons; };
|
||||
templates = (import ./templates.nix) { inherit pkgs lib system commons upstreamImages customs; };
|
||||
mergeUpstreamImageAndTemplates =
|
||||
name: image:
|
||||
templates = (import ./templates.nix) { inherit pkgs lib system commons; };
|
||||
customs = (import ./customs.nix) { inherit pkgs lib system commons upstreamImages templates; };
|
||||
mergeUpstreamAndCustomImages =
|
||||
name: upstreamImage:
|
||||
let
|
||||
imageTemplates = lib.optionalAttrs (lib.hasAttr "${name}" templates) templates.${name};
|
||||
customImages = lib.optionalAttrs (lib.hasAttr "${name}" customs) customs.${name};
|
||||
in
|
||||
imageTemplates // { upstream = image; };
|
||||
customImages // { upstream = upstreamImage; };
|
||||
|
||||
images = lib.mapAttrs mergeUpstreamImageAndTemplates upstreamImages;
|
||||
in images // { inherit customs; }
|
||||
images = lib.mapAttrs mergeUpstreamAndCustomImages upstreamImages;
|
||||
in images // { inherit templates; }
|
||||
|
|
@ -1,24 +1,73 @@
|
|||
# create additional useful template images from upstream images
|
||||
{ pkgs, lib, system, commons, upstreamImages, customs, ... }:
|
||||
# ready to use customization templates to apply on images
|
||||
{ pkgs, lib, system, commons, ... }:
|
||||
with commons;
|
||||
with scriptsNFiles;
|
||||
{
|
||||
v12 = rec {
|
||||
# default image with essential functionalities like ssh, networking etc
|
||||
default = customizeImage upstreamImages.v12 (customs.essentials // {
|
||||
name = "default";
|
||||
hostname = "debian";
|
||||
});
|
||||
|
||||
# playground with easy root access
|
||||
play = customizeImage default (customs.rooted // {
|
||||
name = "play";
|
||||
nameToHostname = false;
|
||||
});
|
||||
|
||||
# proxmox
|
||||
proxmox = customizeImage default (customs.proxmoxOnDebian12 // {
|
||||
name = "proxmox";
|
||||
});
|
||||
# essential functionalities like ssh, networking etc
|
||||
essentials = {
|
||||
install = [ "htop" "openssh-server" "inetutils-ping" "dnsutils" "cloud-guest-utils" "qemu-guest-agent" ];
|
||||
commands = ''
|
||||
upload ${grub-ifnames-0}:/etc/default/grub.d/90-ifnames-0.cfg
|
||||
upload ${grub-disable-microcode}:/etc/default/grub.d/00-disable-microcode.cfg
|
||||
run-command mount /boot/efi && update-grub
|
||||
upload ${eth0-dhcp-network}:/etc/systemd/network/00-eth0-dhcp.network
|
||||
run ${ssh-service-override-conf-create}
|
||||
upload ${grow-root-sh}:/usr/local/sbin/grow-root.sh
|
||||
upload ${grow-root-service}:/etc/systemd/system/grow-root.service
|
||||
run-command systemctl enable grow-root.service
|
||||
'';
|
||||
};
|
||||
}
|
||||
|
||||
# set easy root access
|
||||
rooted = {
|
||||
install = [ "openssh-server" ];
|
||||
commands = ''
|
||||
run ${ssh-service-override-conf-create}
|
||||
'';
|
||||
run = ''
|
||||
# set root password and ssh access
|
||||
echo "root:root" | chpasswd
|
||||
sed -i '/PasswordAuthentication no/d' "/etc/ssh/sshd_config"
|
||||
echo "PasswordAuthentication yes\nPermitRootLogin yes" >> "/etc/ssh/sshd_config"
|
||||
'';
|
||||
};
|
||||
|
||||
# install proxmox
|
||||
proxmoxOnDebian12 = {
|
||||
diskSize = "+2G";
|
||||
smp = 4;
|
||||
memSize = 4096;
|
||||
install = [ "cloud-guest-utils" ];
|
||||
commands = ''
|
||||
upload ${grow-root-sh}:/usr/local/sbin/grow-root.sh
|
||||
upload ${grow-root-service}:/etc/systemd/system/grow-root.service
|
||||
run-command systemctl enable grow-root.service
|
||||
'';
|
||||
run = ''
|
||||
# script originally taken from https://pve.proxmox.com/wiki/Install_Proxmox_VE_on_Debian_12_Bookworm
|
||||
# exit if error
|
||||
set -e
|
||||
|
||||
# grow root partition
|
||||
/usr/local/sbin/grow-root.sh
|
||||
|
||||
# mount efi for grub changes
|
||||
mount /boot/efi
|
||||
|
||||
# add proxmox repo
|
||||
echo "deb [arch=amd64] http://download.proxmox.com/debian/pve bookworm pve-no-subscription" > /etc/apt/sources.list.d/pve-install-repo.list
|
||||
wget https://enterprise.proxmox.com/debian/proxmox-release-bookworm.gpg -O /etc/apt/trusted.gpg.d/proxmox-release-bookworm.gpg
|
||||
apt-get update && apt full-upgrade -y --no-install-recommends;
|
||||
|
||||
# necessary precursors
|
||||
echo "0.0.0.0\t\t`cat /etc/hostname`" >> /etc/hosts; # necessary for SSL certificate creation
|
||||
mkdir -p /run/network; # bug https://github.com/CumulusNetworks/ifupdown2/issues/276
|
||||
|
||||
# install
|
||||
apt install -y proxmox-default-kernel proxmox-ve postfix open-iscsi chrony --no-install-recommends;
|
||||
|
||||
# remove previous kernels
|
||||
apt remove -y os-prober linux-image-amd64 'linux-image-6.*';
|
||||
'';
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue