From 16427e5fe328cce8dda5b0ae315a6629baff6b85 Mon Sep 17 00:00:00 2001 From: Daniel Lundin Date: Tue, 17 Sep 2024 23:02:53 +0200 Subject: [PATCH] merge from main --- .woodpecker/ci.yaml | 33 ++++++++++ README.md | 2 + flake.nix | 147 +++++++++++++++++++++++--------------------- justfile | 16 +++++ 4 files changed, 128 insertions(+), 70 deletions(-) create mode 100644 .woodpecker/ci.yaml create mode 100644 justfile diff --git a/.woodpecker/ci.yaml b/.woodpecker/ci.yaml new file mode 100644 index 0000000..5fdfe80 --- /dev/null +++ b/.woodpecker/ci.yaml @@ -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 < /etc/nix/nix.conf + sandbox = false + experimental-features = nix-command flakes + EOF + + # build + - nix build .#patos_image + + # check + - nix flake check diff --git a/README.md b/README.md index 708b90e..3fea9bd 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/flake.nix b/flake.nix index 6cdc6f5..408623d 100644 --- a/flake.nix +++ b/flake.nix @@ -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 + ]; + }; }; }; - }; } diff --git a/justfile b/justfile new file mode 100644 index 0000000..cd8f0fd --- /dev/null +++ b/justfile @@ -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