Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
aarch64 image with f2fs as main filesystem
{ nixpkgs ? <nixpkgs>, system ? "aarch64-linux" } :
let
myisoconfig = { pkgs, config, ...}: {
imports = [
"${nixpkgs}/nixos/modules/installer/cd-dvd/sd-image-aarch64.nix"
];
boot = {
kernelParams = [ "cma=32M" ];
supportedFilesystems = [ "f2fs" ];
# I think this is how mkForce works
postBootCommands = pkgs.lib.mkForce ''
# On the first boot do some maintenance tasks
if [ -f /nix-path-registration ]; then
# Figure out device names for the boot device and root filesystem.
rootPart=$(readlink -f /dev/disk/by-label/NIXOS_SD)
bootDevice=$(lsblk -npo PKNAME $rootPart)
# Not resizing because f2fs's resize tools are different (?), see also:
# https://github.com/NixOS/nixpkgs/pull/42183
# https://github.com/NixOS/nixpkgs/issues/42242
# Resize the root partition and the filesystem to fit the disk
# echo ",+," | sfdisk -N2 --no-reread $bootDevice
# ${pkgs.parted}/bin/partprobe
# ${pkgs.e2fsprogs}/bin/resize2fs $rootPart
# Register the contents of the initial Nix store
${config.nix.package.out}/bin/nix-store --load-db < /nix-path-registration
# nixos-rebuild also requires a "system" profile and an /etc/NIXOS tag.
touch /etc/NIXOS
${config.nix.package.out}/bin/nix-env -p /nix/var/nix/profiles/system --set /run/current-system
# Prevents this from running on later boots.
rm -f /nix-path-registration
fi
'';
};
environment.systemPackages = with pkgs; [ vim ];
users.extraUsers.root = {
packages = with pkgs; [ f2fs-tools lynx vim w3m ];
initialPassword = "nixos";
};
fileSystems = {
"/boot" = {
#device = "/dev/disk/by-label/NIXOS_BOOT";
#fsType = "vfat";
};
"/" = {
#device = "/dev/disk/by-label/NIXOS_SD";
fsType = pkgs.lib.mkForce "f2fs";
};
};
};
evalNixos = configuration: import "${nixpkgs}/nixos" {
inherit system configuration;
};
in { sd = (evalNixos myisoconfig).config.system.build.sdImage; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment