#nixstrap - declarative OS/distro bootstrapper

1 messages · Page 1 of 1 (latest)

rotund zealot
#

https://sr.ht/~asya/nixstrap/
nixstrap is a declarative OS/distro bootstrapper that makes use of the Nix ecosystem. It's built similarly to NixOS, home-manager and other nix-based systems, except its output is not a full system or a home directory but instead bootable disk images. It is modular, and several modules are provided by nixstrap itself, such as support for bootloaders including limine. It replaces Makefiles and other build systems for OS/distros. It is bootloader- and kernel-agnostic.

nixstrap builds everything as nix derivations, in the nix sandbox. It does not need root access for building. It can (and should) be used with nix flakes, with pinned dependencies, therefore providing a lockfile for the OS and ensuring reproducibility. nixstrap allows you to have multiple configurations for your OS, so you can have any amount of pre-customized images (e.g. a linux distro could have the following configurations: aarch64-plasma riscv64-xfce x86_64-minimal...). For huge OSes with many packages and a long build time, you can spin up a nix cache server and spare your contributors hours, thanks to the reproducibility guarantee.

Here's a basic guide to how to use nixstrap for an OS with a homebrew kernel and environment:

  • write nix packages for user software and the kernel. (not as complex as that sounds)
  • enable and configure modules (such as bootloaders) that your 🫵 OS needs and nixstrap already supports. yes you heard it right 🫵 nixstrap saves you from sketchy makefiles downloading dependencies with unpinned versions suddenly breaking everything when your dependencies update.
  • nix build .#nixstrapConfigurations.<configuration name>.config.build.artifacts TODO: CLI tool to not have this long command
  • your bootable images are now ready, with your 🫵 favourite bootloader installed, your 🫵 kernel & initramfs placed in the boot partition and every other file that your 🫵 VM images and installer ISOs need placed exactly where they need to be.
#

nixstrap currently supports x86_64, aarch64 & riscv64 (uefi only for all of them, for now)
limine is currently the only supported bootloader

grave skiff
#

nice

rotund zealot
grave skiff
#

np lol

rotund zealot
#

did you like the marketing talk

grave skiff
#

sure

stark ibex
#

nice introduction lol

rotund zealot
#

thanks

stone frigate
#

does it handle patching

#

and stuff

#

like is it an alternative to jinx

rotund zealot
#

for example I had to patch the freestanding-toolchain that limine 8.0.6 uses (I think mint fixed it in master but no idea)

#

this is from the limine package (built into nixstrap)

#

nix defaults to certain hardening options being enabled for gcc and clang btw

rotund zealot
#

it's supposed to replace any meta-build system or hell of shell scripts and makefiles that you might be using

rotund zealot
#

nixstrap hasn't been released yet tho

#

currently busy building llvm for the god-knows-how-th time

slate hollow
#

cool project.

#

I might have a go at using this in the future.

rotund zealot
rotund zealot
#

any idea why this happens?

#

it was a typo

#

lol

grave skiff
rotund zealot
#

yep

#

i just mean I won't need the patch on 8.0.7

#

currently upstreaming my nixpkgs OVMF one-line patch

#

someone introduced a regression that would make OVMF not build for riscv

grave skiff
#

really?

#

it works for the nightly

#

for me

rotund zealot
#

the nixpkgs package recipe is broken

grave skiff
#

i see

rotund zealot
# grave skiff it works for the nightly

what does your patches to ovmf contain? I saw the resolution changes and stuff but is there anything really important that maybe I would consider including in nixstrap?

grave skiff
#

nah it's just the timeout and resolution for rv64/aarch64/loong64

rotund zealot
#

ok

#

i will upstream nixstrap's limine package after 8.0.7 is released (so I can get rid of the patch

rotund zealot
#

edk2/OVMF loongarch64 support in nixpkgs

#

this was a blocker for loongarch64 in nixstrap

#

the main blocker is that there is no default cross target for embedded loongarch64

rotund zealot
grave skiff
#

🎉

rotund zealot
#

<arch>-release-<hdd/iso> or <arch>-<hdd/iso>-release?

#

which sounds better?

#

I decided to do the rust template differently to the C template

#

it's obviously not too different it's like a monorepo/not-monorepo thing

#

not specific to rust

#

but if I can showcase both, it would be awesome

#

so let's do the rust template differently

rotund zealot
#

rust template is close to being done

rotund zealot
#

update

#

rust template works and is somewhat clean

#

but I need to document it

rotund zealot
#

still working on releasing nixstrap

#

i don't think it's ready

#

but I do not really have the power to finish what I want it to have

rotund zealot
#

here's a question ❓

#

for people who are interested in potentially using nixstrap for their projects, what are some of your requirements?

#

at least for a first release

rotund zealot
#

I'm gonna work on "runners"

#

so nixstrap can do more than generate the image

#

and actually run it with qemu

rotund zealot
#

I've decided to refactor (and partly rewrite) my last kernel around nixstrap

#

nixstrap's release will be tightly coupled with it

#

I do not think I will release nixstrap this year unless anyone else wants to use nixstrap (then I can release it earlier but it would be a bit half-baked)

#

if you have name ideas for that project, tell me but I'm keeping the previous name for now

#

it's gearbox

rotund zealot
#

nixpkgs' limine is updated

#

one less blocker for nixstrap release

#

the biggest blocker rn is the fact that this is my exam year

#

also I'm a maintainer for the limine package in nixpkgs now :3

#

note to self: add a way to provide extra outputs in the build artifacts

#

maybe a new output so e.g. result has images and result-* has extras

grave skiff
#

thanks!

rotund zealot
#

well I did write a patch for it, but someone else improved it

#

really they should be thanked

grave skiff
#

i read the github thread

#

seems like someone really should open an issue to gcc to tell them they pointlessly don't support PIE on riscv-elf targets

#

plus i am not sure what is going on with darwin

rotund zealot
#

i don't understand what's wrong with darwin either

grave skiff
#

though i hope that they actually listen to such bug report and don't just ignore it and sweep it under the rug

#

(i have experience with that)

rotund zealot
#

limine 8.0.13 from upstream nixpkgs :3

grave skiff
#

awesome!!

rotund zealot
#

nixstrap is officially released

#

I released nixstrap late yesterday

#

I updated the templates today

#

have fun

grave skiff
#

very nice!

#

i'll test it later maybe

rotund zealot
#

it's very easy (albeit kinda slow, but at least it's cached :3) to build it

#

i think it would be faster if it wasn't on nixpkgs-unstable

#

even moving it to nixos-unstable could get more cache hits but limine 8.0.13 did not hit nixos-unstable the last time I checked

#

it's bootstrapping the compiler that compiles your compiler soo it's kinda ok but

#

cache hits are better :3

#

maybe one day they it will be on the latest stable

rotund zealot
sullen iron
#

rip nixstrap

#

😔

rotund zealot
#

will return to it in uhh

#

7 months or so

sullen iron
#

oki

rotund zealot
#

are you interested in it?

rotund zealot
#

centralized entrance exam is :(

sullen iron
rotund zealot
#

ok keep an eye on it

#

i have plans

#

i plan on dedicating my summer to osdev

rotund zealot
#

i really want to do osdev again

#

can't wait for everything to be over

#

hopefully nixstrap will be able to generate qemu runners when i work on it again

#

and sometime i should rework the image creation to not launch guestfish 3 times because as you can guess creating 3 ephemeral linux VMs per image is sloww

rotund zealot
#

idea: nix overlay (similar to NUR) for homebrew OSes

drifting scroll
#

owo this is very interesting

#

I had a similar-ish thing in mind but that never really got anywhere

rotund zealot
#

nixstrap is getting rewritten

#

this time I'm dropping disk images (for now) and doing ISOs

#

so no VM needed

rotund zealot
#

we're so back

digital shadow
#

🎉

rotund zealot
#

nixstrap linux is slowly becoming a thing

#

I have no idea why I can't get keyboard input to work lol

#

wait I need udev for that right?

rotund zealot
#

I got udev working

#

no udev rules tho

#

I just have a short list of kernel modules to load (not detected but always loaded) and then I start udev

rotund zealot
#

i don't like how this depends on systemd to build but thankfully it only copies udevadm from systemd (the rest is not built into the initrd

#

note this is not mlibc yet

#

this is glibc

#

I'll add add mlibc to this after it's merged to nixpkgs

#

but now building with musl for funsies

#

I want to try dracut or mkinitcpio for this too, nixos' make-initrd is too tightly integrated into nixos so I have to copy everything from nixos

rotund zealot
#

will be back soon :3

rotund zealot
#

qemu runners are a thing now

#

i will clean it up then release nixstrap rewrite

#

this is the same rewrite as last time i was just gone for exams

#
#!/nix/store/00zrahbb32nzawrmv9sjxn36h7qk9vrs-bash-5.2p37/bin/bash
exec /nix/store/w094gkcbv6w3n0c9q6ydgz73w1fx11j7-qemu-10.0.0/bin/qemu-system-x86_64 -machine accel=kvm:tcg -cpu max \
  -m 4096 \
  -smp 2 \
  -cdrom /nix/store/g956mqld4079hvc34g4ryx9r48qlbaal-cd.iso-x86_64-elf/iso/cd.iso \
  -drive if=pflash,format=raw,file=/nix/store/470q0bdhxmbqnb9zgq8wfyrsc35qbcdx-OVMF-x86_64-elf-202505-fd/FV/OVMF_CODE.fd,unit=0,readonly=on \
  -device qemu-xhci \
  -device usb-kbd \
  -serial mon:stdio
#

this was autogenerated by nixstrap

#

cd.iso is also autogenerated by nixstrap

#
{ pkgs, ... }: {
  # Timeout in seconds that Limine will use before automatically booting.
  boot.loader.timeout = 3;
  boot.loader.limine.enable = true;
  boot.entry."Limine Template" = {
    # We use the Limine boot protocol.
    protocol = "limine";
    # Path to the kernel to boot. boot():/ represents the partition on which
    # limine.conf is located.
    kernelPath = "boot():/kernel";
  };

  # This builds the kernel using ./kernel/default.nix, and places it in the ISO
  # image.
  isoImage.file."kernel".source = pkgs.callPackage ./kernel {};

  virtualisation.cores = 2;
  virtualisation.memorySize = 4096;
}
#

this is the nixstrap configuration that generated them

rotund zealot
#

wow 10 stars

fading spruce
#

That’s like… over 9 stars

rotund zealot
#

I'm rewriting nixstrap-limine-rust-template for the "new" nixstrap rewrite

#

i already had the c template ready

rotund zealot
#

should I add a crane (nix library for building and managing rust stuff) module to nixstrap?

#

it's kinda boilerplate-y to do it right now but not impossible, but I'm not sure how exactly I'd wrap crane

#

i mean a rust project would probably prefer to ship their own target jsons so I should probably not do that

#

nixstrap rewrite is out

digital shadow
#

yo, nice

#

also based usage of codeberg

rotund zealot
#

yea I'm not happy with sourcehut

#

it's good software but I don't want to use the sourcehut instance hosted by drew devault

#

i don't hate him but I don't like him either and i think it may scare away contributors

#

I should probably port the NixOS assertations module

#

NixOS assertos module

#

fuck OVMF failed to build for aarch64

#

well if it's a regression that's a free PR to nixpkgs

#

let me try with the older OVMF build i used

rotund zealot
#

loongarch is working

#

i had to fix nolibc support in nixpkgs

#

i've probably written more nixpkgs code than nixstrap code just to get nixstrap to work

#

which is good imo cuz it means this is upstreamable code - the core of nixstrap and its modules obviously cannot be upstreamed but packages and fixes can be

rotund zealot
#

proper nixstrap release (with templates) is soon

#

i have some nixpkgs patches I need to be merged

#

and I'm changing my email

drifting scroll
#

How's nixstrap going? :3

#

(@rotund zealot)

rotund zealot
#

i took a break to start uni and move

#

ill be back to nixstrap after some mlibc and nixpkgs work

nocturne comet
rotund zealot
#

not yet

#

finals month

rotund zealot
#

mlibc in nixpkgs is still not merged mostly due to me being slow