Last active
January 18, 2019 22:49
-
-
Save petersjt014/b52dfaf91762e4b889035e4535cb67ec to your computer and use it in GitHub Desktop.
meant to build an aarch64 image with the much flash-friendlier nilfs2 filesystem for root
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ nixpkgs ? <nixpkgs>, system ? "aarch64-linux" } : | |
let | |
myisoconfig = { pkgs, config, ...}: { | |
imports = [ | |
"${nixpkgs}/nixos/modules/installer/cd-dvd/sd-image-aarch64.nix" | |
]; | |
boot = { | |
kernelParams = [ "cma=32M" ]; | |
# for this and every other instance of the string 'nilfs', there may be a 2 at the end--not sure | |
supportedFilesystems = [ "nilfs" ]; | |
# pretty sure 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) | |
# I don't know how nilfs's resizing utils are meant to work; see also: | |
# https://github.com/NixOS/nixpkgs/pull/42183 | |
# https://github.com/NixOS/nixpkgs/issues/42242 | |
# also, resizing to only half capacity to leave room for swap may be ideal--nilfs supports online resize anyway | |
# 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; [ nilfs-utils lynx vim w3m ]; | |
initialPassword = "nixos"; | |
}; | |
fileSystems = { | |
"/boot" = { | |
# commented out because this seems to be inherited, | |
# might be better of simply removed for that reason | |
#device = "/dev/disk/by-label/NIXOS_BOOT"; | |
#fsType = "vfat"; | |
}; | |
"/" = { | |
#device = "/dev/disk/by-label/NIXOS_SD"; | |
fsType = pkgs.lib.mkForce "nilfs"; | |
}; | |
}; | |
}; | |
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