Meta(
    title: "Sortix: a hobby OS with potential",
    summary: None,
    published: None,
    tags: [
        "Unix",
        "Sortix",
        "programming",
    ],
)
---
I like perriodically checking out hobby OS projects and seeing what I can learn from them. Sortix is a small hobby OS with the goal of being a clean and modern POSIX implementation. It's been in development since 2011 and managed to go self hosting with it's 1.0 release in 2016, and is capable of running a fair amount of third party software now including Vim, Emacs, Nano, Python, and Perl, which makes it at this point a nice solid base on which to build. Expectations should be appropriate for a hobby system, however, as this is largely a one man project and is not production ready.

I've actually been using code from Sortix for a few years now in HitchHiker, as they have a nice cleaned up fork of Libz that went into the HitchHiker base system early on. It's pretty much a drop in replacement for the official Libz, but the code is missing a lot of the snarled mass of #ifdef..#else..#endif from the original, as support for long dead operatinig systems and platforms has been removed. This makes the code 1000% easier to follow and maintain. What I haven't done in quite a while is actually boot it up into a VM and check out what Sortix is like today.

## Sortix development environment (Linux)
As I mentioned earlier, Sortix is a self hosted system since 2016, but that is only for the base system. Ports are still being developed via cross compilation, as there are a lot of tools that developers take for granted which haven't made it into Sortix yet. So if you want to build master plus all of the ports you need to set up a cross development environment. Alternatively, you can download a nightly ISO and run that, but the nightlies aren't always up to date. Well, that and I like to poke at things and DIY, so I wanted to go the long route. There are official instructions on the website:
=> https://sortix.org/man/man7/cross-development.7.html

I got my cross toolchain set up on Linux but would suggest the following additional instructions.
* Run a clean shell, preferably Dash, by starting it with `env -i HOME=$HOME TERM=$TERM /bin/dash`
* If you have Isl installed it can confuse the gcc build. Manually disable Isl support by appending the arg `--without-isl` to the configure options

There was a small change I applied to the `gettext` port because it's build system got confused by the packages I had installed on my host system and attempted to compile in C# support. It's a common failure when authors use GNU autotools that their configure tests will run against the host libraries rather than the target libraries if you are cross compiling. In this case I just appended `--disable-csharp` to the args passed in to `configure`, which fixed the problem. I sent the tiny diff upstream in a pull request. After that, everything built without errors.

Sortix is a small system. The system itself (kernel and userland minus ports) compiles in about a minute or less. The bulk of the compoilation time is spent on Ports, but since there aren't a lot of ports it's still pretty quick.

## Sortix development environment (FreeBSD)
Cross compiling Sortix on FreeBSD requires more work because the author was obviously working from Linux using GNU tools. Rather than trying to patch all of the Linuxism's in his Makefiles I install GNU coreutils, GNU tar and GNU sed into the same prefix as the cross toolchain. Similar to building on Linux earlier, I started a clean shell, this time using `/bin/sh`.
