Add justfile

This commit is contained in:
Daniel Lundin 2024-09-12 22:34:19 +02:00
parent ebc7d5420b
commit 7b480f285f
Signed by: dln
SSH key fingerprint: SHA256:dQy1Xj3UiqJYpKR5ggQ2bxgz4jCH8IF+k3AB8o0kmdI
2 changed files with 74 additions and 53 deletions

111
flake.nix
View file

@ -5,66 +5,71 @@
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
};
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 =
let
pkgs = nixpkgs.legacyPackages.x86_64-linux;
in
pkgs.mkShell {
packages = [
self.packages.x86_64-linux.qemu-efi
];
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
'';
};
packages.x86_64-linux = {
default = self.packages.x86_64-linux.patos_image;
patos_image = self.lib.mkInstallImage self.nixosConfigurations.patos;
# A helper script to run the disk images above.
qemu-efi =
devShells.x86_64-linux.default =
let
pkgs = nixpkgs.legacyPackages.x86_64-linux;
in
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 "$@"
'';
pkgs.mkShell {
packages = [
pkgs.just
self.packages.x86_64-linux.qemu-efi
];
};
};
nixosConfigurations = {
patos = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
./base.nix
];
packages.x86_64-linux = {
default = self.packages.x86_64-linux.patos_image;
patos_image = self.lib.mkInstallImage self.nixosConfigurations.patos;
# A helper script to run the disk images above.
qemu-efi =
let
pkgs = nixpkgs.legacyPackages.x86_64-linux;
in
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 = {
patos = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
./base.nix
];
};
};
};
};
}

16
justfile Normal file
View file

@ -0,0 +1,16 @@
set shell := ["/usr/bin/env", "bash", "-euo", "pipefail", "-c"]
[private]
default:
@just --list
# Update nix flake
update:
nix flake update
# Build all targets
build: build-image
# Build PatOS image
build-image:
nix build .#patos_image