flake: create generator for aarch64 sdcard image
This commit is contained in:
parent
a4294aefbc
commit
2c733de3b3
6 changed files with 133 additions and 20 deletions
|
|
@ -1,4 +1,4 @@
|
|||
{ config, inputs, modules, overlays, pkgs, ... }: {
|
||||
{ config, inputs, modules, modulesPath, overlays, pkgs, ... }: {
|
||||
networking.hostName = "caramel";
|
||||
system.stateVersion = "21.11";
|
||||
time.timeZone = "Asia/Phnom_Penh";
|
||||
|
|
@ -12,6 +12,7 @@
|
|||
};
|
||||
imports =
|
||||
(with modules.system; [
|
||||
"${builtins.toString modulesPath}/installer/sd-card/sd-image-aarch64.nix"
|
||||
inputs.home-manager-porcupine.nixosModule
|
||||
|
||||
base
|
||||
|
|
@ -23,15 +24,16 @@
|
|||
|
||||
./filesystem.nix
|
||||
./kernel.nix
|
||||
./image.nix
|
||||
./networking.nix
|
||||
./packages.nix
|
||||
|
||||
../../users/hana
|
||||
]) ++
|
||||
(with modules.services; [
|
||||
nginx
|
||||
postgres
|
||||
synapse
|
||||
# nginx
|
||||
# postgres
|
||||
# synapse
|
||||
tmptsync
|
||||
unbound
|
||||
vaultwarden
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
{ config, ... }:
|
||||
{ config, lib, ... }:
|
||||
let
|
||||
bind = src: {
|
||||
depends = [ "/persist" ];
|
||||
|
|
@ -9,16 +9,31 @@ let
|
|||
};
|
||||
in {
|
||||
fileSystems = {
|
||||
"/" = {
|
||||
"/" = lib.mkForce {
|
||||
device = "rootfs";
|
||||
fsType = "tmpfs";
|
||||
options = [ "defaults" "size=2G" "mode=755" ];
|
||||
options = [ "defaults" "size=1G" "mode=755" ];
|
||||
};
|
||||
|
||||
"/nix" = {
|
||||
# "/nix" = {
|
||||
# device = "overlayfs";
|
||||
# fsType = "overlay";
|
||||
# options = [
|
||||
# "lowerdir=/mnt/image/nix"
|
||||
# "upperdir=/persist/nix-overlay"
|
||||
# "workdir=/persist/.overlaytmp"
|
||||
# ];
|
||||
# noCheck = true;
|
||||
# depends = [ "/mnt/image" "/persist" ];
|
||||
# };
|
||||
|
||||
"/nix" = (bind "/mnt/image/nix") // { depends = [ "/mnt/image" ]; };
|
||||
|
||||
"/mnt/image" = {
|
||||
device = "/dev/disk/by-label/NIXOS_SD";
|
||||
fsType = "ext4";
|
||||
options = [ "defaults" "noatime" ];
|
||||
neededForBoot = true;
|
||||
};
|
||||
|
||||
"/persist" = {
|
||||
|
|
@ -31,6 +46,6 @@ in {
|
|||
"/var/persist" = bind "/persist";
|
||||
"/var/lib/acme" = bind "/persist/acme";
|
||||
"/var/log/journal" = bind "/persist/journal";
|
||||
"/boot" = (bind "/nix/persist/boot") // { depends = [ "/nix" ]; };
|
||||
"/boot" = (bind "/mnt/image/boot") // { depends = [ "/mnt/image" ]; };
|
||||
};
|
||||
}
|
||||
|
|
|
|||
29
hosts/caramel/image.nix
Normal file
29
hosts/caramel/image.nix
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
{ config, lib, pkgs, ... }: {
|
||||
sdImage.expandOnBoot = false;
|
||||
boot.postBootCommands = ''
|
||||
# On the first boot do some maintenance tasks
|
||||
if [ -f /mnt/image/nix-path-registration ]; then
|
||||
set -euo pipefail
|
||||
set -x
|
||||
# Figure out device names for the boot device and root filesystem.
|
||||
rootPart=$(${pkgs.util-linux}/bin/findmnt -n -o SOURCE /mnt/image)
|
||||
bootDevice=$(lsblk -npo PKNAME $rootPart)
|
||||
partNum=$(lsblk -npo MAJ:MIN $rootPart | ${pkgs.gawk}/bin/awk -F: '{print $2}')
|
||||
|
||||
# Resize the root partition and the filesystem to fit the disk
|
||||
echo ",+," | sfdisk -N$partNum --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 < /mnt/image/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 /mnt/image/nix-path-registration
|
||||
fi
|
||||
'';
|
||||
}
|
||||
|
|
@ -1,11 +1,15 @@
|
|||
{ config, inputs, pkgs, ... }: {
|
||||
{ config, inputs, lib, pkgs, ... }: {
|
||||
imports = [
|
||||
inputs.nixos-hardware.nixosModules.raspberry-pi-4
|
||||
];
|
||||
hardware.raspberry-pi."4".fkms-3d.enable = true;
|
||||
|
||||
boot.kernel.sysctl = {
|
||||
"kernel.core_pattern" = "|/bin/false";
|
||||
"kernel.sysrq" = 1;
|
||||
boot = {
|
||||
initrd.kernelModules = [ "overlay" ];
|
||||
supportedFilesystems = lib.mkForce [ "btrfs" "vfat" ];
|
||||
kernel.sysctl = {
|
||||
"kernel.core_pattern" = "|/bin/false";
|
||||
"kernel.sysrq" = 1;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue