Skip to content

Commit

Permalink
roles/iso: allow squashfs compression to be overriden
Browse files Browse the repository at this point in the history
  • Loading branch information
NotAShelf committed Jul 6, 2024
1 parent e20c572 commit 55829c1
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions modules/core/roles/iso/image/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,29 @@
lib,
...
}: let
inherit (lib) cleanSource mkImageMediaOverride;
inherit (builtins) substring;
inherit (lib.sources) cleanSource;
inherit (lib.modules) mkDefault mkImageMediaOverride;
in {
# the ISO image must be completely immutable in the sense that we do not
# want the user to be able modify the ISO image after booting into it
# the below option will disable rebuild switches (i.e nixos-rebuild switch)
system.switch.enable = false;

isoImage = let
# hostname will be set as a "top-level" attribute in hosts.nix, per-host.
# therefore we can use the networking.hostName to get the hostname of the live
# system without defining it explicitly in the system-agnostic ISO role module
# `hostname` will always be defined as a "top-level" attribute in hosts.nix
# while the host is being "constructed" so to speak. Therefore we can use
# networking.hostName (instead of `meta.hostname`) to get the hostname
# of the system we are building the ISO for without hardcoding anything
# in this role module, since this is meant to be system-agnostic. Though
# at the off chance that networking.hostName is not defined, we default to
# "nixos" as the hostname to avoid errors or empty strings.
hostname = config.networking.hostName or "nixos";

# if the system is built from a git repository, we want to include the git revision
# in the ISO name. If the tree is dirty, we use the term "dirty" to make it explicit
# and include the date in the ISO name.
rev = self.shortRev or "${builtins.substring 0 8 self.lastModifiedDate}-dirty";
rev = self.shortRev or "${substring 0 8 self.lastModifiedDate}-dirty";

# the format of the iso will always be uniform:
# $hostname-$release-$rev-$arch
Expand All @@ -36,8 +42,11 @@ in {
# volumeID is used is used by stage 1 of the boot process, so it must be distintctive
volumeID = mkImageMediaOverride "${name}";

# maximum compression, in exchange for build speed
squashfsCompression = "zstd -Xcompression-level 19"; # default uses gzip
# Maximum compression in exchange for speed, assuming ISOs to be built on GHA CI
# which has a 2GB limit for uploaded artifacts. Use mkDefault to allow hosts that
# import this role to override the compression options, potentially for faster builds
# or if the build host has space to spare.
squashfsCompression = mkDefault "zstd -Xcompression-level 19"; # default uses gzip

# ISO image should be an EFI-bootable volume
makeEfiBootable = true;
Expand All @@ -48,12 +57,13 @@ in {
# is this supposed to make the ISO image bootable from *CD* instead of USB?
makeUsbBootable = true;

# Get rid of "installer" suffix in boot menu
# Get rid of "installer" suffix in boot menu. Not all ISO images are
# installers.
appendToMenuLabel = "";

contents = [
{
# my module system already contains an option to add memtest86+
# My module system already contains an option to add memtest86+
# to the boot menu at will but in case our system is unbootable
# lets include memtest86+ in the ISO image
# so that we may test the memory of the system
Expand All @@ -62,10 +72,10 @@ in {
target = "/boot/memtest.bin";
}
{
# link this flake to /etc/nixos/flake so that the user can
# Link system flake to /root/nyx so that the user can
# can initiate a rebuild without having to clone and wait
# useful if this installer is meant to be used on a system
# that cannot access github
# that cannot access GitHub.
source = cleanSource self;
target = "/root/nyx";
}
Expand Down

0 comments on commit 55829c1

Please sign in to comment.