14 Commits

5 changed files with 168 additions and 61 deletions
+4 -1
View File
@@ -1,2 +1,5 @@
result*
pocketblue*
pocketblue*
mnt
output.txt
*.img
+4 -13
View File
@@ -1,5 +1,3 @@
default: build-all
default_flags := ""
build flags=default_flags:
@@ -8,18 +6,11 @@ build flags=default_flags:
build-kernel flags=default_flags:
nix run nixpkgs#nix-output-monitor -- build .#nixosConfigurations.pipa.config.boot.kernelPackages.kernel {{flags}} -o result-kernel
build-kernel-image flags=default_flags:
nix run nixpkgs#nix-output-monitor -- build .#nixosConfigurations.pipa.config.system.build.android-bootimg {{flags}} -o result-boot
build-rawImg flags=default_flags:
nix run nixpkgs#nix-output-monitor -- build .#nixosConfigurations.pipa.config.system.build.rawImage {{flags}} -o result-raw
build-image flags=default_flags:
nix run nixpkgs#nix-output-monitor -- build .#nixosConfigurations.pipa.config.system.build.sdImage {{flags}} -o result-image
build-all flags=default_flags:
just build-image {{flags}}
just build-kernel-image {{flags}}
build-partitions flags=default_flags:
nix run nixpkgs#nix-output-monitor -- build .#nixosConfigurations.pipa.config.system.build.separated-images -o result-partitions {{flags}}
build-flashable flags=default_flags:
nix run nixpkgs#nix-output-monitor -- build .#nixosConfigurations.pipa.config.system.build.flashableImages -o result-flashable {{flags}}
format:
alejandra .
+19 -2
View File
@@ -3,11 +3,10 @@
pkgs,
...
}: {
system.stateVersion = "26.05"; # Matches our 2026 build timeline
system.stateVersion = "26.05";
networking.hostName = "pipa-nixos";
# Basic environment setup
environment.systemPackages = with pkgs; [
git
vim
@@ -21,4 +20,22 @@
extraGroups = ["wheel" "networkmanager"];
initialPassword = "nixos";
};
time.timeZone = "Europe/Prague";
i18n = {
defaultLocale = "en_US.UTF-8";
extraLocaleSettings = {
LC_ADDRESS = "cs_CZ.UTF-8";
LC_IDENTIFICATION = "cs_CZ.UTF-8";
LC_MEASUREMENT = "cs_CZ.UTF-8";
LC_MONETARY = "cs_CZ.UTF-8";
LC_NAME = "cs_CZ.UTF-8";
LC_NUMERIC = "cs_CZ.UTF-8";
LC_PAPER = "cs_CZ.UTF-8";
LC_TELEPHONE = "cs_CZ.UTF-8";
LC_TIME = "cs_CZ.UTF-8";
};
};
}
+66 -3
View File
@@ -3,8 +3,6 @@
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/25.11";
# The exact working 6.18.2 vendor source tree from your spec file
pipa-kernel-src = {
url = "https://github.com/pipa-mainline/linux/archive/576f7cb3848179b36ef92420a1ab4c910b53b357.tar.gz";
flake = false;
@@ -16,7 +14,66 @@
nixpkgs,
pipa-kernel-src,
...
} @ inputs: {
} @ inputs: let
# Define our host platform for the tools
pkgs = nixpkgs.legacyPackages."x86_64-linux";
# Grab the compiled system closure directly from our configuration
toplevel = self.nixosConfigurations.pipa.config.system.build.toplevel;
buildImagesScript = pkgs.writeShellScriptBin "build-pipa-images" ''
set -e
MNT_DIR="$PWD/mnt"
OUT_DIR="$PWD/images"
# We encapsulate your exact script logic inside a function
run_isolated_install() {
echo "=> Creating output directory..."
mkdir -p "$OUT_DIR"
echo "=> Creating blank images (1GB ESP, 8GB RootFS)..."
rm -f "$OUT_DIR/esp.img" "$OUT_DIR/rootfs.img"
# 1GB ESP to comfortably hold loose kernels/initrd generations, 8GB Rootfs
dd if=/dev/zero of="$OUT_DIR/esp.img" bs=1M count=1024 status=none
dd if=/dev/zero of="$OUT_DIR/rootfs.img" bs=1M count=8192 status=none
echo "=> Formatting images natively..."
${pkgs.dosfstools}/bin/mkfs.vfat -F 32 -n NIX_ESP "$OUT_DIR/esp.img"
${pkgs.e2fsprogs}/bin/mkfs.ext4 -L NIX_ROOT "$OUT_DIR/rootfs.img" -q
echo "=> Mounting images in traditional sequence..."
mkdir -p "$MNT_DIR"
mount "$OUT_DIR/rootfs.img" "$MNT_DIR"
# Single large ESP maps straight to /boot
mkdir -p "$MNT_DIR/boot"
mount "$OUT_DIR/esp.img" "$MNT_DIR/boot"
echo "=> Injecting the ARM64 OS and native Bootloader..."
# Relaxed checks are kept so systemd-boot will install onto the loopback file
SYSTEMD_RELAX_ESP_CHECKS=1 nixos-install \
--root "$MNT_DIR" \
--system ${toplevel} \
--no-root-passwd \
--no-channel-copy
echo " Done! esp.img and rootfs.img are ready in the 'images/' directory."
}
# Export variables and the function so the sudo unshare shell can see them
export -f run_isolated_install
export MNT_DIR OUT_DIR toplevel
echo "=> Spawning private mount namespace..."
# This runs the function inside a completely blank mount tracking space.
# Sudo inside the script handles the namespace creation.
sudo unshare --mount bash -c 'run_isolated_install'
# Clean up the local mount anchor point on your host filesystem
rmdir "$MNT_DIR" 2>/dev/null || true
'';
in {
nixosConfigurations.pipa = nixpkgs.lib.nixosSystem {
modules = [
./hardware-configuration.nix
@@ -24,5 +81,11 @@
];
specialArgs = {inherit inputs;};
};
# Expose the script as a runnable Flake App
apps."x86_64-linux".default = {
type = "app";
program = "${buildImagesScript}/bin/build-pipa-images";
};
};
}
+75 -42
View File
@@ -5,53 +5,86 @@
inputs,
...
}: {
boot.kernelPackages = let
# 1. Patch the vendor code natively (Fast, zero QEMU)
patchedSrc = pkgs.buildPackages.runCommand "pipa-kernel-src-patched" {} ''
cp -r ${inputs.pipa-kernel-src} $out
chmod -R +w $out
# Fix keyboard driver headers
sed -i '1i #include <linux/gpio/consumer.h>' $out/drivers/input/keyboard/nanosic_803.c
sed -i '1i #include <linux/hex.h>' $out/drivers/input/keyboard/nanosic_803.c
# Fix charger driver dead SIMD header
sed -i 's|#include <asm/neon.h>|/* #include <asm/neon.h> safely removed */|' $out/drivers/power/supply/bq25970_charger.c
# Fix touchscreen driver MediaTek artifact (Deletes lines 1243 and 1244)
sed -i '1243,1244d' $out/drivers/input/touchscreen/nt36523/nt36xxx.c
'';
# 2. Cross-compile using the patched source
customKernel = pkgs.buildLinux {
version = "6.18.2-pipa";
modDirVersion = "6.18.2";
src = patchedSrc;
configfile = ./pipa.config;
dtbTarget = "qcom/sm8250-xiaomi-pipa.dtb";
ignoreConfigErrors = true;
structuredExtraConfig = with lib.kernel; {
FW_LOADER = lib.mkForce yes;
RUST = lib.mkForce no;
DRM_NOVA = lib.mkForce no;
};
};
in
lib.recurseIntoAttrs (pkgs.linuxPackagesFor customKernel);
# -------------------------------------------------------------------
# Native cross-compilation speeds (x86_64 -> ARM64)
# -------------------------------------------------------------------
nixpkgs.buildPlatform = "x86_64-linux";
nixpkgs.hostPlatform = "aarch64-linux";
boot.loader.grub.enable = false;
boot.loader.generic-extlinux-compatible.enable = true;
boot = {
kernelPackages = let
patchedSrc = pkgs.buildPackages.runCommand "pipa-kernel-src-patched" {} ''
cp -r ${inputs.pipa-kernel-src} $out
chmod -R +w $out
# Fix keyboard driver headers
sed -i '1i #include <linux/gpio/consumer.h>' $out/drivers/input/keyboard/nanosic_803.c
sed -i '1i #include <linux/hex.h>' $out/drivers/input/keyboard/nanosic_803.c
# Fix charger driver dead SIMD header
sed -i 's|#include <asm/neon.h>|/* #include <asm/neon.h> safely removed */|' $out/drivers/power/supply/bq25970_charger.c
# Fix touchscreen driver MediaTek artifact (Deletes lines 1243 and 1244)
sed -i '1243,1244d' $out/drivers/input/touchscreen/nt36523/nt36xxx.c
'';
customKernel = pkgs.buildLinux {
version = "6.18.2-pipa";
modDirVersion = "6.18.2";
src = patchedSrc;
configfile = ./pipa.config;
dtbTarget = "qcom/sm8250-xiaomi-pipa.dtb";
ignoreConfigErrors = true;
structuredExtraConfig = with lib.kernel; {
FW_LOADER = lib.mkForce yes;
RUST = lib.mkForce no;
DRM_NOVA = lib.mkForce no;
};
};
in
lib.recurseIntoAttrs (pkgs.linuxPackagesFor customKernel);
loader = {
efi = {
canTouchEfiVariables = true;
efiSysMountPoint = "/boot";
};
systemd-boot = {
enable = true;
};
generic-extlinux-compatible.enable = false;
};
initrd = {
kernelModules = [
# Core USB Stack
"usb_storage"
"dwc3"
"dwc3-qcom"
"xhci-pci"
"xhci-plat-hcd"
# Snapdragon PHY / Type-C Drivers
"phy_qcom_qmp"
"phy_qcom_qusb2"
"typec"
"usbhid"
"hid_generic"
];
};
};
hardware.enableRedistributableFirmware = true;
fileSystems."/boot" = {
device = "/dev/disk/by-label/NIX_ESP";
fsType = "vfat";
};
fileSystems."/" = {
device = "/dev/disk/by-label/root";
device = "/dev/disk/by-label/NIX_ROOT";
fsType = "ext4";
};
}