This commit is contained in:
phaer 2024-09-05 11:43:41 +02:00
parent 7c60ba4bc8
commit 409f3e6e38
7 changed files with 43 additions and 33 deletions

View File

@ -30,25 +30,27 @@
allConfigs = lib.mapAttrs (formatName: evalFormat) config.formatConfigs; allConfigs = lib.mapAttrs (formatName: evalFormat) config.formatConfigs;
# adds an evaluated `config` to the derivation attributes of a format for introspection # adds an evaluated `config` to the derivation attributes of a format for introspection
exposeConfig = conf: output: output.overrideAttrs (old: { exposeConfig = conf: output:
passthru.config = conf.config; output.overrideAttrs (old: {
}); passthru.config = conf.config;
});
# attrset of formats to be exposed under config.system.formats # attrset of formats to be exposed under config.system.formats
formats = lib.flip lib.mapAttrs allConfigs ( formats = lib.flip lib.mapAttrs allConfigs (
formatName: conf: exposeConfig conf ( formatName: conf:
pkgs.runCommand "${conf.config.system.build.${conf.config.formatAttr}.name}" {} '' exposeConfig conf (
set -efu pkgs.runCommand "${conf.config.system.build.${conf.config.formatAttr}.name}" {} ''
target=$(find '${conf.config.system.build.${conf.config.formatAttr}}' -name '*${conf.config.fileExtension}' -xtype f -print -quit) set -efu
if [ -z "$target" ]; then target=$(find '${conf.config.system.build.${conf.config.formatAttr}}' -name '*${conf.config.fileExtension}' -xtype f -print -quit)
echo "No target file found for ${conf.config.formatAttr} format" if [ -z "$target" ]; then
echo "Check the content of this build path: ${conf.config.system.build.${conf.config.formatAttr}}" echo "No target file found for ${conf.config.formatAttr} format"
exit 1 echo "Check the content of this build path: ${conf.config.system.build.${conf.config.formatAttr}}"
fi exit 1
mkdir $out fi
ln -s "$target" "$out/$(basename "$target")" mkdir $out
'' ln -s "$target" "$out/$(basename "$target")"
) ''
)
); );
in { in {
_file = ./all-formats.nix; _file = ./all-formats.nix;

View File

@ -1,7 +1,4 @@
{ {lib, ...}: {
lib,
...
}: {
services.sshd.enable = true; services.sshd.enable = true;
services.nginx.enable = true; services.nginx.enable = true;

View File

@ -11,7 +11,8 @@ in {
]; ];
hyperv.baseImageSize = hyperv.baseImageSize =
if diskSize == "auto" then "auto" if diskSize == "auto"
then "auto"
else lib.strings.toIntBase10 diskSize; else lib.strings.toIntBase10 diskSize;
formatAttr = "hypervImage"; formatAttr = "hypervImage";

View File

@ -13,14 +13,14 @@ in {
]; ];
system.build = rec { system.build = rec {
image = pkgs.runCommand "image" { buildInputs = [ pkgs.nukeReferences ]; } '' image = pkgs.runCommand "image" {buildInputs = [pkgs.nukeReferences];} ''
mkdir $out mkdir $out
cp ${config.system.build.kernel}/${config.system.boot.loader.kernelFile} $out/kernel cp ${config.system.build.kernel}/${config.system.boot.loader.kernelFile} $out/kernel
cp ${config.system.build.netbootRamdisk}/initrd $out/initrd cp ${config.system.build.netbootRamdisk}/initrd $out/initrd
echo "init=${builtins.unsafeDiscardStringContext config.system.build.toplevel}/init ${toString config.boot.kernelParams}" > $out/cmdline echo "init=${builtins.unsafeDiscardStringContext config.system.build.toplevel}/init ${toString config.boot.kernelParams}" > $out/cmdline
nuke-refs $out/kernel nuke-refs $out/kernel
''; '';
kexec_script = pkgs.writeTextFile { kexec_script = pkgs.writeTextFile {
executable = true; executable = true;
name = "kexec-nixos"; name = "kexec-nixos";
@ -44,7 +44,7 @@ in {
sync sync
echo "executing kernel, filesystems will be improperly umounted" echo "executing kernel, filesystems will be improperly umounted"
kexec -e kexec -e
''; '';
}; };
kexec_tarball = maybe.mkForce (pkgs.callPackage "${toString modulesPath}/../lib/make-system-tarball.nix" { kexec_tarball = maybe.mkForce (pkgs.callPackage "${toString modulesPath}/../lib/make-system-tarball.nix" {

View File

@ -1,4 +1,8 @@
{lib, modulesPath, ...}: { {
lib,
modulesPath,
...
}: {
imports = [ imports = [
"${toString modulesPath}/virtualisation/proxmox-lxc.nix" "${toString modulesPath}/virtualisation/proxmox-lxc.nix"
]; ];

View File

@ -1,5 +1,10 @@
{ config, lib, pkgs, modulesPath, ... }:
{ {
config,
lib,
pkgs,
modulesPath,
...
}: {
# for virtio kernel drivers # for virtio kernel drivers
imports = [ imports = [
"${toString modulesPath}/profiles/qemu-guest.nix" "${toString modulesPath}/profiles/qemu-guest.nix"
@ -8,17 +13,18 @@
options = { options = {
boot = { boot = {
consoles = lib.mkOption { consoles = lib.mkOption {
default = [ "ttyS0" ] ++ default =
(lib.optional (pkgs.stdenv.hostPlatform.isAarch) "ttyAMA0,115200") ++ ["ttyS0"]
(lib.optional (pkgs.stdenv.hostPlatform.isRiscV64) "ttySIF0,115200"); ++ (lib.optional (pkgs.stdenv.hostPlatform.isAarch) "ttyAMA0,115200")
++ (lib.optional (pkgs.stdenv.hostPlatform.isRiscV64) "ttySIF0,115200");
description = "Kernel console boot flags to pass to boot.kernelParams"; description = "Kernel console boot flags to pass to boot.kernelParams";
example = [ "ttyS2,115200" ]; example = ["ttyS2,115200"];
}; };
diskSize = lib.mkOption { diskSize = lib.mkOption {
default = "auto"; default = "auto";
description = "The disk size in megabytes of the system disk image."; description = "The disk size in megabytes of the system disk image.";
type = with lib.types; oneOf [ ints.positive (enum [ "auto" ])]; type = with lib.types; oneOf [ints.positive (enum ["auto"])];
}; };
}; };
}; };
@ -54,4 +60,3 @@
fileExtension = ".qcow2"; fileExtension = ".qcow2";
}; };
} }

View File

@ -11,7 +11,8 @@ in {
]; ];
vmware.baseImageSize = vmware.baseImageSize =
if diskSize == "auto" then "auto" if diskSize == "auto"
then "auto"
else lib.strings.toIntBase10 diskSize; else lib.strings.toIntBase10 diskSize;
formatAttr = "vmwareImage"; formatAttr = "vmwareImage";