nixos-riscv/efi-image.nix

62 lines
2.0 KiB
Nix

{ config, pkgs, lib, inputs, modulesPath, ... }:
# prior art:
# https://github.com/NixOS/nixos-hardware/blob/master/starfive/visionfive/v2/sd-image.nix
# https://github.com/nix-community/nixos-generators/blob/master/formats/raw.nix
# https://github.com/nix-community/nixos-generators/blob/master/formats/raw-efi.nix
let
firmware = pkgs.callPackage "${inputs.nixos-hardware}/starfive/visionfive/v2/firmware.nix" { };
in {
options.efiImage = {
imageBaseName = lib.mkOption {
default = "nixos-efi-image";
description = lib.mdDoc "Prefix of the name of the generated image file.";
};
};
config = {
boot.loader.grub.device = config.fileSystems.${config.boot.loader.efi.efiSysMountPoint}.device; # hack for installBootLoader
fileSystems.${config.boot.loader.efi.efiSysMountPoint}.neededForBoot = true;
fileSystems."/".autoResize = true;
boot.growPartition = true;
#boot.loader.grub.device = "nodev";
#boot.loader.grub.efiSupport = true;
#boot.loader.grub.efiInstallAsRemovable = true;
system.build.efiImage = import "${modulesPath}/../lib/make-disk-image.nix" {
inherit config lib pkgs;
name = "${config.efiImage.imageBaseName}-${config.system.nixos.label}-${pkgs.stdenv.hostPlatform.system}-starfive-visionfive2.img";
#diskSize = 8*1024; # megabytes, defaults to "auto"
bootSize = "512M"; # nixos-install default
partitionTableType = "efi";
installBootLoader = true;
touchEFIVars = true;
#efiFirmware
#efiVariables
fsType = config.fileSystems."/".fsType;
# TODO: zstd
format = "raw"; # one of qcow2, qcow2-compressed, vdi, vpc, raw.
# TODO: make this thing able to rebuild
#configFile = pkgs.writeText "configuration.nix" ''
# {
# imports = [ <./machine-config.nix> ];
# }
#'';
};
assertions = [
{
assertion = config.boot.loader.systemd-boot.enable;
message = "Building EFI Image requires systemd-boot";
}
];
};
}