patos/flake.nix

76 lines
2 KiB
Nix
Raw Normal View History

2024-09-12 21:57:01 +02:00
{
description = "PatOS is a minimal, immutable Linux distribution specialized for the Patagia Platform.";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
};
2024-09-12 22:34:19 +02:00
outputs =
{ self, nixpkgs }:
{
lib = {
# Prepare a ready-to-boot disk image.
mkInstallImage =
nixos:
let
config = nixos.config;
pkgs = nixpkgs.legacyPackages.x86_64-linux.pkgs;
in
nixos.pkgs.runCommand "update-${config.system.image.version}"
{
nativeBuildInputs = with pkgs; [ 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
'';
};
devShells.x86_64-linux.default =
2024-09-12 21:57:01 +02:00
let
2024-09-12 22:34:19 +02:00
pkgs = nixpkgs.legacyPackages.x86_64-linux;
2024-09-12 21:57:01 +02:00
in
2024-09-12 22:34:19 +02:00
pkgs.mkShell {
packages = [
pkgs.just
self.packages.x86_64-linux.qemu-efi
];
};
2024-09-12 21:57:01 +02:00
2024-09-12 22:34:19 +02:00
packages.x86_64-linux = {
default = self.packages.x86_64-linux.patos_image;
2024-09-12 21:57:01 +02:00
2024-09-12 22:34:19 +02:00
patos_image = self.lib.mkInstallImage self.nixosConfigurations.patos;
2024-09-12 21:57:01 +02:00
2024-09-12 22:34:19 +02:00
# A helper script to run the disk images above.
qemu-efi =
let
pkgs = nixpkgs.legacyPackages.x86_64-linux;
in
pkgs.writeShellApplication {
name = "qemu-efi";
2024-09-12 21:57:01 +02:00
2024-09-12 22:34:19 +02:00
runtimeInputs = [ pkgs.qemu_kvm ];
2024-09-12 21:57:01 +02:00
2024-09-12 22:34:19 +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-09-12 21:57:01 +02:00
2024-09-12 22:34:19 +02:00
nixosConfigurations = {
patos = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
./base.nix
];
2024-09-12 21:57:01 +02:00
};
};
};
}