{ 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 xz ]; } '' mkdir -p $out xz -1 -cz ${config.system.build.uki}/${config.system.boot.loader.ukiFile} \ > $out/${config.system.boot.loader.ukiFile}.xz xz -1 -cz ${config.system.build.image}/${config.boot.uki.name}_${config.system.image.version}.store.raw \ > $out/${config.boot.uki.name}_${config.system.image.version}.img.xz ''; # Prepare a ready-to-boot disk image. mkInstallImage = nixos: let config = nixos.config; in pkgs.runCommand "update-${config.system.image.version}" { nativeBuildInputs = with pkgs; [ erofs-utils qemu ]; } '' mkdir -p $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 ''; in { devShell = pkgs.mkShell { packages = [ pkgs.erofs-utils pkgs.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; # 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 ]; text = '' qemu-system-x86_64 \ -smp 2 -m 2048 -machine q35,accel=kvm \ -bios ${pkgs.OVMF.fd}/FV/OVMF.fd \ -snapshot \ -display none \ -serial stdio "$@" ''; }; }; nixosConfigurations = rec { patos = nixpkgs.lib.nixosSystem { specialArgs.pkgs = pkgs; system = system; modules = [ { _module.args = { inherit patagia-agent; }; } ./base.nix # ./modules/patagia-agent.nix ]; }; }; } ); }