flake: create generator for aarch64 sdcard image

This commit is contained in:
LavaDesu 2022-08-08 18:18:18 +07:00
parent a4294aefbc
commit 2c733de3b3
Signed by: cilly
GPG key ID: 6500251E087653C9
6 changed files with 133 additions and 20 deletions

37
flake.lock generated
View file

@ -351,6 +351,42 @@
"type": "github" "type": "github"
} }
}, },
"nixlib": {
"locked": {
"lastModified": 1636849918,
"narHash": "sha256-nzUK6dPcTmNVrgTAC1EOybSMsrcx+QrVPyqRdyKLkjA=",
"owner": "nix-community",
"repo": "nixpkgs.lib",
"rev": "28a5b0557f14124608db68d3ee1f77e9329e9dd5",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixpkgs.lib",
"type": "github"
}
},
"nixos-generators": {
"inputs": {
"nixlib": "nixlib",
"nixpkgs": [
"nixpkgs-porcupine"
]
},
"locked": {
"lastModified": 1657748715,
"narHash": "sha256-WecDwDY/hEcDQYzFnccCNa+5Umht0lfjx/d1qGDy/rQ=",
"owner": "nix-community",
"repo": "nixos-generators",
"rev": "3323b944d99b026aebfd8de439e001409dde067d",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixos-generators",
"type": "github"
}
},
"nixos-hardware": { "nixos-hardware": {
"locked": { "locked": {
"lastModified": 1654057797, "lastModified": 1654057797,
@ -610,6 +646,7 @@
"multitask": "multitask", "multitask": "multitask",
"neovim-nightly": "neovim-nightly", "neovim-nightly": "neovim-nightly",
"nix-gaming": "nix-gaming", "nix-gaming": "nix-gaming",
"nixos-generators": "nixos-generators",
"nixos-hardware": "nixos-hardware", "nixos-hardware": "nixos-hardware",
"nixpkgs": "nixpkgs_2", "nixpkgs": "nixpkgs_2",
"nixpkgs-porcupine": "nixpkgs-porcupine", "nixpkgs-porcupine": "nixpkgs-porcupine",

View file

@ -7,11 +7,13 @@
neovim-nightly.url = "github:nix-community/neovim-nightly-overlay"; neovim-nightly.url = "github:nix-community/neovim-nightly-overlay";
nixos-hardware.url = "github:NixOS/nixos-hardware"; nixos-hardware.url = "github:NixOS/nixos-hardware";
agenix.url = "github:ryantm/agenix"; agenix.url = "github:ryantm/agenix";
nixos-generators.url = "github:nix-community/nixos-generators";
agenix.inputs.nixpkgs.follows = "nixpkgs"; agenix.inputs.nixpkgs.follows = "nixpkgs";
home-manager.inputs.nixpkgs.follows = "nixpkgs"; home-manager.inputs.nixpkgs.follows = "nixpkgs";
home-manager-porcupine.inputs.nixpkgs.follows = "nixpkgs-porcupine"; home-manager-porcupine.inputs.nixpkgs.follows = "nixpkgs-porcupine";
neovim-nightly.inputs.nixpkgs.follows = "nixpkgs"; neovim-nightly.inputs.nixpkgs.follows = "nixpkgs";
nixos-generators.inputs.nixpkgs.follows = "nixpkgs-porcupine";
nix-gaming.url = "github:fufexan/nix-gaming"; nix-gaming.url = "github:fufexan/nix-gaming";
powercord-overlay.url = "github:LavaDesu/powercord-overlay"; powercord-overlay.url = "github:LavaDesu/powercord-overlay";
@ -61,7 +63,7 @@
zelk = { url = "github:schnensch0/zelk"; flake = false; }; zelk = { url = "github:schnensch0/zelk"; flake = false; };
}; };
outputs = { self, agenix, nixpkgs, nixpkgs-porcupine, ... } @ inputs: outputs = { self, agenix, nixos-generators, nixpkgs, nixpkgs-porcupine, ... } @ inputs:
let let
overlays = (import ./overlays) overlays = (import ./overlays)
++ [inputs.powercord-overlay.overlay] ++ [inputs.powercord-overlay.overlay]
@ -71,13 +73,13 @@
mkSystem = mkSystem =
if !(self ? rev) then throw "Dirty git tree detected." else if !(self ? rev) then throw "Dirty git tree detected." else
nixpkgs: name: arch: enableGUI: nixpkgs.lib.nixosSystem { nixpkgs: name: arch: enableGUI: extraModules: nixpkgs.lib.nixosSystem {
system = arch; system = arch;
modules = [ modules = [
{ nixpkgs.overlays = overlays; } { nixpkgs.overlays = overlays; }
agenix.nixosModules.age agenix.nixosModules.age
(./hosts + "/${name}") (./hosts + "/${name}")
]; ] ++ extraModules;
specialArgs = { specialArgs = {
inherit inputs enableGUI; inherit inputs enableGUI;
modules = import ./modules { lib = nixpkgs.lib; }; modules = import ./modules { lib = nixpkgs.lib; };
@ -85,10 +87,10 @@
}; };
in in
{ {
nixosConfigurations."blossom" = mkSystem nixpkgs "blossom" "x86_64-linux" true; nixosConfigurations."blossom" = mkSystem nixpkgs "blossom" "x86_64-linux" true [];
nixosConfigurations."caramel" = mkSystem nixpkgs-porcupine "caramel" "aarch64-linux" false; nixosConfigurations."caramel" = mkSystem nixpkgs-porcupine "caramel" "aarch64-linux" false [];
nixosConfigurations."sugarcane" = mkSystem nixpkgs-porcupine "sugarcane" "x86_64-linux" false; nixosConfigurations."sugarcane" = mkSystem nixpkgs-porcupine "sugarcane" "x86_64-linux" false [];
packages."x86_64-linux" = packages."x86_64-linux" =
let let
@ -104,12 +106,36 @@
packages."aarch64-linux" = packages."aarch64-linux" =
let let
pkgs = import nixpkgs-porcupine { pkgs = import nixpkgs-porcupine {
inherit overlays; overlays = overlays ++ [
# See https://github.com/NixOS/nixpkgs/issues/126755#issuecomment-869149243
];
system = "aarch64-linux"; system = "aarch64-linux";
}; };
caramel-sys = mkSystem nixpkgs-porcupine "caramel" "aarch64-linux" false [{
nixpkgs.overlays = [
(self: super: {
makeModulesClosure = x: super.makeModulesClosure (x // { allowMissing = true; });
})
];
}];
in in
{ {
inherit (pkgs) nixUnstable; inherit (pkgs) nixUnstable;
caramel-iso2 = caramel-sys.config.system.build.sdImage;
caramel-iso = nixos-generators.nixosGenerate {
inherit pkgs;
format = "sd-aarch64";
modules = [
agenix.nixosModules.age
./hosts/caramel
];
specialArgs = {
inherit inputs;
modules = import ./modules { lib = nixpkgs-porcupine.lib; };
};
};
}; };
# TODO: currently broken # TODO: currently broken

View file

@ -1,4 +1,4 @@
{ config, inputs, modules, overlays, pkgs, ... }: { { config, inputs, modules, modulesPath, overlays, pkgs, ... }: {
networking.hostName = "caramel"; networking.hostName = "caramel";
system.stateVersion = "21.11"; system.stateVersion = "21.11";
time.timeZone = "Asia/Phnom_Penh"; time.timeZone = "Asia/Phnom_Penh";
@ -12,6 +12,7 @@
}; };
imports = imports =
(with modules.system; [ (with modules.system; [
"${builtins.toString modulesPath}/installer/sd-card/sd-image-aarch64.nix"
inputs.home-manager-porcupine.nixosModule inputs.home-manager-porcupine.nixosModule
base base
@ -23,15 +24,16 @@
./filesystem.nix ./filesystem.nix
./kernel.nix ./kernel.nix
./image.nix
./networking.nix ./networking.nix
./packages.nix ./packages.nix
../../users/hana ../../users/hana
]) ++ ]) ++
(with modules.services; [ (with modules.services; [
nginx # nginx
postgres # postgres
synapse # synapse
tmptsync tmptsync
unbound unbound
vaultwarden vaultwarden

View file

@ -1,4 +1,4 @@
{ config, ... }: { config, lib, ... }:
let let
bind = src: { bind = src: {
depends = [ "/persist" ]; depends = [ "/persist" ];
@ -9,16 +9,31 @@ let
}; };
in { in {
fileSystems = { fileSystems = {
"/" = { "/" = lib.mkForce {
device = "rootfs"; device = "rootfs";
fsType = "tmpfs"; 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"; device = "/dev/disk/by-label/NIXOS_SD";
fsType = "ext4"; fsType = "ext4";
options = [ "defaults" "noatime" ]; options = [ "defaults" "noatime" ];
neededForBoot = true;
}; };
"/persist" = { "/persist" = {
@ -31,6 +46,6 @@ in {
"/var/persist" = bind "/persist"; "/var/persist" = bind "/persist";
"/var/lib/acme" = bind "/persist/acme"; "/var/lib/acme" = bind "/persist/acme";
"/var/log/journal" = bind "/persist/journal"; "/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
View 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
'';
}

View file

@ -1,11 +1,15 @@
{ config, inputs, pkgs, ... }: { { config, inputs, lib, pkgs, ... }: {
imports = [ imports = [
inputs.nixos-hardware.nixosModules.raspberry-pi-4 inputs.nixos-hardware.nixosModules.raspberry-pi-4
]; ];
hardware.raspberry-pi."4".fkms-3d.enable = true; hardware.raspberry-pi."4".fkms-3d.enable = true;
boot.kernel.sysctl = { boot = {
"kernel.core_pattern" = "|/bin/false"; initrd.kernelModules = [ "overlay" ];
"kernel.sysrq" = 1; supportedFilesystems = lib.mkForce [ "btrfs" "vfat" ];
kernel.sysctl = {
"kernel.core_pattern" = "|/bin/false";
"kernel.sysrq" = 1;
};
}; };
} }