2024-09-12 21:57:01 +02:00
|
|
|
{
|
|
|
|
description = "PatOS is a minimal, immutable Linux distribution specialized for the Patagia Platform.";
|
|
|
|
|
|
|
|
inputs = {
|
2024-10-05 17:19:30 +02:00
|
|
|
flake-utils.url = "github:numtide/flake-utils";
|
2024-09-12 21:57:01 +02:00
|
|
|
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
|
2024-10-05 17:19:30 +02:00
|
|
|
patagia-agent.url = "git+ssh://git@patagia.dev/patagia/patagia-agent?ref=main";
|
|
|
|
patagia-agent.inputs.nixpkgs.follows = "nixpkgs";
|
2024-09-12 21:57:01 +02:00
|
|
|
};
|
|
|
|
|
2024-09-17 23:02:53 +02:00
|
|
|
outputs =
|
|
|
|
{
|
2024-10-05 17:19:30 +02:00
|
|
|
self,
|
|
|
|
flake-utils,
|
|
|
|
nixpkgs,
|
|
|
|
patagia-agent,
|
|
|
|
}:
|
|
|
|
flake-utils.lib.eachDefaultSystem (
|
|
|
|
system:
|
|
|
|
let
|
|
|
|
|
|
|
|
pkgs = import nixpkgs {
|
|
|
|
inherit system;
|
|
|
|
overlays = [
|
|
|
|
(import ./overlays)
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2024-09-17 23:02:53 +02:00
|
|
|
# Prepare an update package for the system.
|
|
|
|
mkUpdate =
|
|
|
|
nixos:
|
|
|
|
let
|
|
|
|
config = nixos.config;
|
|
|
|
in
|
2024-10-05 17:19:30 +02:00
|
|
|
pkgs.runCommand "update-${config.system.image.version}"
|
2024-09-17 23:02:53 +02:00
|
|
|
{
|
2024-10-05 17:19:30 +02:00
|
|
|
nativeBuildInputs = with pkgs; [
|
|
|
|
erofs-utils
|
|
|
|
xz
|
|
|
|
];
|
2024-09-17 23:02:53 +02:00
|
|
|
}
|
|
|
|
''
|
|
|
|
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
|
2024-10-05 17:19:30 +02:00
|
|
|
pkgs.runCommand "update-${config.system.image.version}"
|
2024-09-17 23:02:53 +02:00
|
|
|
{
|
2024-10-05 17:19:30 +02:00
|
|
|
nativeBuildInputs = with pkgs; [
|
|
|
|
erofs-utils
|
|
|
|
qemu
|
|
|
|
];
|
2024-09-17 23:02:53 +02:00
|
|
|
}
|
|
|
|
''
|
|
|
|
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
|
|
|
|
'';
|
2024-10-05 17:19:30 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
devShell = pkgs.mkShell {
|
2024-09-17 23:02:53 +02:00
|
|
|
packages = [
|
2024-10-05 17:19:30 +02:00
|
|
|
pkgs.erofs-utils
|
2024-09-17 23:02:53 +02:00
|
|
|
pkgs.just
|
2024-10-05 17:19:30 +02:00
|
|
|
self.packages.${system}.qemu-efi
|
2024-09-17 23:02:53 +02:00
|
|
|
];
|
|
|
|
};
|
2024-09-12 21:57:01 +02:00
|
|
|
|
2024-10-05 17:19:30 +02:00
|
|
|
packages = {
|
|
|
|
default = self.packages.${system}.patos_image;
|
|
|
|
patos_image = mkInstallImage self.nixosConfigurations.${system}.patos;
|
|
|
|
patos_update = mkUpdate self.nixosConfigurations.${system}.patos;
|
2024-09-12 21:57:01 +02:00
|
|
|
|
2024-10-05 17:19:30 +02:00
|
|
|
# FIXME: only do for x86_64
|
|
|
|
# A helper script to run the disk images above.
|
|
|
|
qemu-efi = pkgs.writeShellApplication {
|
2024-09-17 23:02:53 +02:00
|
|
|
name = "qemu-efi";
|
2024-09-12 21:57:01 +02:00
|
|
|
|
2024-09-17 23:02:53 +02:00
|
|
|
runtimeInputs = [ pkgs.qemu_kvm ];
|
2024-09-12 21:57:01 +02:00
|
|
|
|
2024-09-17 23:02:53 +02:00
|
|
|
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 "$@"
|
|
|
|
'';
|
|
|
|
};
|
2024-10-05 17:19:30 +02:00
|
|
|
};
|
2024-09-12 21:57:01 +02:00
|
|
|
|
2024-10-05 17:19:30 +02:00
|
|
|
nixosConfigurations = rec {
|
|
|
|
patos = nixpkgs.lib.nixosSystem {
|
|
|
|
specialArgs.pkgs = pkgs;
|
|
|
|
system = system;
|
|
|
|
modules = [
|
|
|
|
{
|
|
|
|
_module.args = {
|
|
|
|
inherit patagia-agent;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
./base.nix
|
|
|
|
# ./modules/patagia-agent.nix
|
|
|
|
];
|
|
|
|
};
|
2024-09-12 21:57:01 +02:00
|
|
|
};
|
2024-09-18 00:00:34 +02:00
|
|
|
|
2024-10-05 17:19:30 +02:00
|
|
|
}
|
|
|
|
);
|
2024-09-12 21:57:01 +02:00
|
|
|
}
|