From 9470683ac726923efddb00ca67370d1797b6c9ff Mon Sep 17 00:00:00 2001 From: Daniel Lundin Date: Sun, 13 Oct 2024 23:39:56 +0200 Subject: [PATCH] More minimization work --- flake.lock | 6 +++--- flake.nix | 32 ++++++++++++++++++++++---------- justfile | 4 ++++ modules/generic.nix | 1 + modules/minimize.nix | 3 ++- modules/partitions.nix | 9 ++++++--- overlays/default.nix | 9 +++++++++ 7 files changed, 47 insertions(+), 17 deletions(-) diff --git a/flake.lock b/flake.lock index bc6244c..1c88e49 100644 --- a/flake.lock +++ b/flake.lock @@ -69,11 +69,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1728492678, - "narHash": "sha256-9UTxR8eukdg+XZeHgxW5hQA9fIKHsKCdOIUycTryeVw=", + "lastModified": 1728888510, + "narHash": "sha256-nsNdSldaAyu6PE3YUA+YQLqUDJh+gRbBooMMekZJwvI=", "owner": "nixos", "repo": "nixpkgs", - "rev": "5633bcff0c6162b9e4b5f1264264611e950c8ec7", + "rev": "a3c0b3b21515f74fd2665903d4ce6bc4dc81c77c", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 6ab9c7e..4aa710b 100644 --- a/flake.nix +++ b/flake.nix @@ -36,15 +36,18 @@ { nativeBuildInputs = with pkgs; [ erofs-utils - xz + zstd ]; } '' mkdir -p $out - xz -1 -cz ${config.system.build.uki}/${config.system.boot.loader.ukiFile} \ - > $out/${config.system.boot.loader.ukiFile}.xz - xz -1 -cz ${config.system.build.image}/${config.boot.uki.name}_${config.system.image.version}.store.raw \ - > $out/${config.boot.uki.name}_${config.system.image.version}.img.xz + cp ${config.system.build.image}/${config.boot.uki.name}_${config.system.image.version}.store.raw $out/ + + zstd -9 ${config.system.build.uki}/${config.system.boot.loader.ukiFile} \ + -o $out/${config.system.boot.loader.ukiFile}.zst + + zstd -9 ${config.system.build.image}/${config.boot.uki.name}_${config.system.image.version}.store.raw \ + -o $out/${config.boot.uki.name}_${config.system.image.version}.img.zst ''; # Prepare a ready-to-boot disk image. @@ -56,20 +59,27 @@ pkgs.runCommand "update-${config.system.image.version}" { nativeBuildInputs = with pkgs; [ - erofs-utils qemu + zstd ]; } '' mkdir -p $out + cp ${config.system.build.image}/${config.boot.uki.name}_${config.system.image.version}.raw $out/ qemu-img convert -f raw -O qcow2 -C ${config.system.build.image}/${config.boot.uki.name}_${config.system.image.version}.raw $out/disk.qcow2 + + zstd -9 ${config.system.build.image}/${config.boot.uki.name}_${config.system.image.version}.store.raw \ + -o $out/${config.boot.uki.name}_${config.system.image.version}.img.zst + + zstd -9 ${config.system.build.uki}/${config.system.boot.loader.ukiFile} \ + -o $out/${config.system.boot.loader.ukiFile}.zst ''; in { devShell = pkgs.mkShell { - packages = [ - pkgs.erofs-utils - pkgs.just + packages = with pkgs; [ + erofs-utils + just self.packages.${system}.qemu-efi ]; }; @@ -79,6 +89,8 @@ patos_image = mkInstallImage self.nixosConfigurations.${system}.patos; patos_update = mkUpdate self.nixosConfigurations.${system}.patos; + image = system.build; + # FIXME: only do for x86_64 # A helper script to run the disk images above. qemu-efi = pkgs.writeShellApplication { @@ -88,7 +100,7 @@ text = '' qemu-system-x86_64 \ - -smp 2 -m 2048 -machine q35,accel=kvm \ + -smp 4 -m 2048 -machine q35,accel=kvm \ -bios ${pkgs.OVMF.fd}/FV/OVMF.fd \ -snapshot \ -display none \ diff --git a/justfile b/justfile index 1a1b7a8..8fe9679 100644 --- a/justfile +++ b/justfile @@ -15,6 +15,10 @@ build: build-image build-image: nix build .#patos_image +# Build PatOS update image +build-update: + nix build .#patos_update + run: build-image qemu-efi -hda ./result/disk.qcow2 diff --git a/modules/generic.nix b/modules/generic.nix index ddf5fc6..dd4f547 100644 --- a/modules/generic.nix +++ b/modules/generic.nix @@ -9,6 +9,7 @@ boot = { enableContainers = false; initrd.systemd.enable = true; + initrd.compressor = "zstd"; kernelParams = [ "console=ttyS0" ]; diff --git a/modules/minimize.nix b/modules/minimize.nix index c9c537f..e679396 100644 --- a/modules/minimize.nix +++ b/modules/minimize.nix @@ -7,11 +7,12 @@ nix.enable = false; system.disableInstallerTools = true; system.etc.overlay.enable = true; - systemd.sysusers.enable = true; programs.less.lessopen = null; programs.command-not-found.enable = false; environment.defaultPackages = [ ]; + + security.sudo.enable = false; } diff --git a/modules/partitions.nix b/modules/partitions.nix index 13aa6de..b53513e 100644 --- a/modules/partitions.nix +++ b/modules/partitions.nix @@ -21,10 +21,13 @@ mkfsOptions = { erofs = [ - "-zzstd,6" # Zstd compression + # "-zzstd,6" # Zstd compression + # "-zlz4hc,12" "-T0" # Fixed timestamp for all files - "-C65536" # 64 KiB cluster size - # "-Efragments,dedupe,ztailpacking" # Extra features + "-C262144" # 256 KiB cluster size + # "-C65536" # 64 KiB cluster size + # "-C1048576" # 1 MiB cluster size + "-Efragments,dedupe,ztailpacking" # Extra features ]; }; diff --git a/overlays/default.nix b/overlays/default.nix index b84ffbb..dfc7ebb 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -7,4 +7,13 @@ final: prev: { "--enable-zstd" ]; }); + + util-linux = prev.util-linux.override { + ncursesSupport = false; + nlsSupport = false; + }; + + dbus = prev.dbus.override { + x11Support = false; + }; }