feat-mkupdate #1

Merged
dln merged 3 commits from feat-mkupdate into main 2024-09-27 20:33:42 +02:00
4 changed files with 128 additions and 70 deletions
Showing only changes of commit 16427e5fe3 - Show all commits

33
.woodpecker/ci.yaml Normal file
View file

@ -0,0 +1,33 @@
when:
- event: pull_request
- event: push
branch:
- ${CI_REPO_DEFAULT_BRANCH}
steps:
check:
image: alpine
volumes:
- nix:/nix
commands:
# install nix
- |
test -f /nix/installer || wget -O /nix/installer https://github.com/DeterminateSystems/nix-installer/releases/download/v0.18.0/nix-installer-x86_64-linux
chmod +x /nix/installer
rm -f /nix/receipt.json /nix/nix-installer
/nix/installer install linux --init=none --no-confirm
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
# configure nix
- |
mkdir -p /etc/nix
cat <<EOF > /etc/nix/nix.conf
sandbox = false
experimental-features = nix-command flakes
EOF
# build
- nix build .#patos_image
# check
- nix flake check

View file

@ -1,3 +1,5 @@
# PatOS - Patagia OS
[![status-badge](https://ci.patagia.dev/api/badges/42/status.svg)](https://ci.patagia.dev/repos/42)
PatOS is a minimal, immutable Linux distribution specialized for the Patagia Platform.

147
flake.nix
View file

@ -5,84 +5,91 @@
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
};
outputs = { self, nixpkgs }: {
lib = {
# Prepare an update package for the system.
mkUpdate = nixos:
let
config = nixos.config;
pkgs = nixpkgs.legacyPackages.x86_64-linux.pkgs;
in
nixos.pkgs.runCommand "update-${config.system.image.version}"
{
nativeBuildInputs = with pkgs; [ 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
'';
outputs =
{ self, nixpkgs }:
{
lib = {
# Prepare an update package for the system.
mkUpdate =
nixos:
let
config = nixos.config;
pkgs = nixpkgs.legacyPackages.x86_64-linux.pkgs;
in
nixos.pkgs.runCommand "update-${config.system.image.version}"
{
nativeBuildInputs = with pkgs; [ 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;
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
];
# 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;
patos_update = self.lib.mkUpdate 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;
patos_update = self.lib.mkUpdate 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