patos/flake.nix
Daniel Lundin 3f347427ed
Some checks failed
ci/woodpecker/push/ci Pipeline failed
Add experimental installer script
2024-10-23 22:06:39 +02:00

139 lines
4.2 KiB
Nix

{
description = "PatOS is a minimal, immutable Linux distribution specialized for the Patagia Platform.";
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
patagia-agent.url = "git+ssh://git@patagia.dev/patagia/patagia-agent?ref=main";
patagia-agent.inputs.nixpkgs.follows = "nixpkgs";
};
outputs =
{
self,
flake-utils,
nixpkgs,
patagia-agent,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
(import ./overlays)
];
};
# Prepare an update package for the system.
mkUpdate =
nixos:
let
config = nixos.config;
in
pkgs.runCommand "update-${config.system.image.version}"
{
nativeBuildInputs = with pkgs; [
erofs-utils
zstd
];
}
''
mkdir -p $out
cp ${config.system.build.image}/${config.boot.uki.name}_${config.system.image.version}.store.raw $out/
zstd -9 ${config.system.build.uki}/${config.system.boot.loader.ukiFile} \
-o $out/${config.system.boot.loader.ukiFile}.zst
zstd -9 ${config.system.build.image}/${config.boot.uki.name}_${config.system.image.version}.store.raw \
-o $out/${config.boot.uki.name}_${config.system.image.version}.img.zst
'';
# Prepare a ready-to-boot disk image.
mkInstallImage =
nixos:
let
config = nixos.config;
in
pkgs.runCommand "update-${config.system.image.version}"
{
nativeBuildInputs = with pkgs; [
qemu
zstd
];
}
''
mkdir -p $out
cp ${config.system.build.image}/${config.boot.uki.name}_${config.system.image.version}.raw $out/
qemu-img convert -f raw -O qcow2 -C ${config.system.build.image}/${config.boot.uki.name}_${config.system.image.version}.raw $out/disk.qcow2
zstd -9 ${config.system.build.image}/${config.boot.uki.name}_${config.system.image.version}.store.raw \
-o $out/${config.boot.uki.name}_${config.system.image.version}.img.zst
zstd -9 ${config.system.build.uki}/${config.system.boot.loader.ukiFile} \
-o $out/${config.system.boot.loader.ukiFile}.zst
'';
in
{
devShell = pkgs.mkShell {
packages = with pkgs; [
erofs-utils
just
self.packages.${system}.qemu-efi
];
};
packages = {
default = self.packages.${system}.patos_image;
patos_image = mkInstallImage self.nixosConfigurations.${system}.patos;
patos_update = mkUpdate self.nixosConfigurations.${system}.patos;
image = system.build;
# FIXME: only do for x86_64
# A helper script to run the disk images above.
qemu-efi = pkgs.writeShellApplication {
name = "qemu-efi";
runtimeInputs = [ pkgs.qemu_kvm ];
# -snapshot \
text = ''
set -ex
qemu-system-x86_64 \
-smp 4 -m 4096 -machine q35,accel=kvm \
-bios ${pkgs.OVMF.fd}/FV/OVMF.fd \
-display none \
-serial stdio "$@"
'';
};
};
nixosConfigurations = rec {
patos = nixpkgs.lib.nixosSystem {
specialArgs.pkgs = pkgs;
system = system;
modules = [
{
_module.args = {
inherit patagia-agent;
};
}
./modules/kernel
./modules/filesystems.nix
./modules/generic.nix
./modules/minimize.nix
./modules/network.nix
# ./modules/patagia-agent.nix
./modules/partitions.nix
./modules/system_overrides.nix
./modules/sysupdate.nix
./modules/utils.nix
];
};
};
}
);
}