Skip to main content

Follow Me

Join Viktor, a proud nerd and seasoned entrepreneur, whose academic journey at Santa Clara University in Silicon Valley sparked a career marked by innovation and foresight. From his college days, Viktor embarked on an entrepreneurial path, beginning with YippieMove, a groundbreaking email migration service, and continuing with a series of bootstrapped ventures.

Nerding out about Nix and NixOS with Jon Seager

Play On Listen to podcast on YouTube Listen to podcast on Spotify Listen to podcast on Apple Listen to podcast on Amazon music
29 JAN • 2024 57 mins
Share:

In this episode, I’m joined by Jon Seager, VP of Enterprise Engineering at Canonical, to explore the fascinating world of Nix. Jon’s experience with automation tools like JuJu and charms offers unique insights into how Nix is transforming software development and system management.

We start with the dual nature of Nix as both a functional programming language and a package manager. What particularly caught my attention was Nix’s ability to create truly reproducible systems - a feature that sets it apart in the software development landscape. Jon’s explanation of how NixOS combines the Nix package manager with its module system reveals the elegant simplicity of immutable system configuration.

The conversation gets especially interesting when Jon shares his home setup. His integration of NixOS with TailScale for a zero-trust environment demonstrates the practical power of Nix’s declarative approach. The way he maintains his system configuration shows how Nix can make complex setups both secure and manageable.

I was particularly intrigued by the resources Jon has curated for the Nix community. For those wanting to dive deeper into the Nix ecosystem, here are some invaluable resources:

If you’re interested in system configuration, reproducible builds, or the future of package management, you’ll find plenty of practical insights here. Jon brings both deep technical knowledge and hands-on experience to the discussion, making complex Nix concepts accessible while maintaining their technical depth.

Transcript

Show/Hide Transcript
[00:00] Viktor Petersson
Hi, welcome to this episode of Nerding up with Victor.
[00:03] Viktor Petersson
Today I got a special guest with me, a friend of mine.
[00:06] Viktor Petersson
His name is John and he's from Canonical.
[00:09] Viktor Petersson
Hi, John.
[00:10] Viktor Petersson
Do you want to say a few words to introduce yourself to the listeners?
[00:13] Jon Seager
Yeah, indeed.
[00:14] Jon Seager
So thanks for having me.
[00:15] Jon Seager
I'm VP of Engineering at Canonical for what we call Enterprise Engineering.
[00:19] Jon Seager
So in my day job I look after a good portion of Canonical's automation tooling, so juju and the World of Charms, which kind of provide operators for popular open source software.
[00:30] Jon Seager
So in my kind of sphere of influence is things like Postgres and MySQL and Prometheus and Loki and Grafana.
[00:38] Jon Seager
We have a 5G core kind of suite of automation that we can deploy some machine learning tools, one named kubeflow.
[00:45] Jon Seager
And so I spent most of my day kind of in the Canonical and Ubuntu ecosystem, working on cloud automation for enterprises, essentially.
[00:53] Jon Seager
But my history with open source is relatively long.
[00:56] Jon Seager
I was a early days Arch Linux user and kind of even before that, lots of kind of early versions of Ubuntu and Gentoo and various things like that.
[01:06] Viktor Petersson
Yeah, amazing.
[01:07] Viktor Petersson
Yeah.
[01:08] Viktor Petersson
There's a lot of interesting stuff that you've been talking about, particularly about juju, which I think we should dive into in a future episode because there's some really cool stuff brewing in the juju space, I think.
[01:20] Viktor Petersson
Cool.
[01:21] Viktor Petersson
Interesting enough.
[01:22] Viktor Petersson
In today's episode we will not speak about anything Canonical, but rather about something completely different, which is Nix.
[01:29] Viktor Petersson
And you really got me excited about Nix a few months ago.
[01:34] Viktor Petersson
Actually it was last year at the Buddha summit, I think you started to really pitching the idea of Nix.
[01:39] Viktor Petersson
And in today's episode we're going to cover Nix and we're going to cover a Nix OS Nixon and kind of tie it all together with how you do a dev environment and how you run your, well, local machines really.
[01:54] Viktor Petersson
So maybe we can start with Nix and what is Nix and why should we care?
[02:00] Jon Seager
Yeah, indeed.
[02:01] Jon Seager
So while I kind of professionally work for Canonical and Ubuntu, I took on the challenge last year of learning Nix and nixos.
[02:08] Jon Seager
I'd been kind of hearing a lot about it on podcasts and reading lobsters and such and decided to kind of dive into it.
[02:14] Jon Seager
And I'm quite captivated by it.
[02:16] Jon Seager
So the one thing I would note is that it's probably one of the like most dense technical ecosystems I've ever tried to get into.
[02:23] Jon Seager
The documentation situation is getting better, but there's quite a lot of movement and so Just trying to get a footing to get started can be quite tough.
[02:31] Jon Seager
So firstly, Nix is actually two things.
[02:33] Jon Seager
So Nix firstly is a functional programming language.
[02:36] Jon Seager
I've heard it described as a bit like JSON, but with pure functions.
[02:41] Jon Seager
It has some similarities to something like Haskell.
[02:45] Jon Seager
And Nix is essentially the language that is used to describe packages and system configurations and CI checks and developer environments and kind of anything in the world of Nix.
[02:55] Jon Seager
Nix is also a package manager.
[02:57] Jon Seager
So probably the vast majority of Nix users are consuming the package manager rather than the operating system necessarily.
[03:04] Jon Seager
So it's been around for a good long time now, I want to say 12, 13 years that I could go wrong.
[03:11] Jon Seager
And Nix packages, which is the kind of GitHub repository which stores all of the definitions for the packages, is I believe, the largest Linux package repository in the world.
[03:20] Jon Seager
It's actually bigger than the Arch Repositories and the AUR combined.
[03:25] Jon Seager
So if you're looking for a piece of software, the chances of it being available with Nix is pretty high.
[03:30] Jon Seager
And similar to some of the things I do in my professional life, it's kind of operating system cross platform.
[03:36] Jon Seager
So you can install Nix on macOS, you can install it on any Linux, and that package collection sort of becomes automatically available to you.
[03:46] Jon Seager
So the way it kind of like loosely hangs together is that using the Nix language, you write derivations which output packages, right?
[03:55] Jon Seager
So derivations you can think of as like a blueprint for a package.
[04:00] Jon Seager
And one of the interesting things about Nix is it has this kind of feature of reproducibility by default.
[04:05] Jon Seager
So it will do that trickery, you see, in the file system where everything was, you know, starting at the UNIX epoch and such.
[04:12] Jon Seager
And the idea is that a derivation should build exactly the same on any given machine, right?
[04:17] Jon Seager
So it's a very portable way to build packages for different systems.
[04:20] Viktor Petersson
Are they fully reproducible or are they.
[04:24] Jon Seager
That's a great question.
[04:25] Jon Seager
I guess it depends on how far down the rabbit hole you go.
[04:27] Jon Seager
I mean, they're pretty reproducible in the sense that.
[04:30] Jon Seager
I don't know, I don't know.
[04:33] Jon Seager
In fact, they must be to an extent.
[04:35] Jon Seager
So part of the package building process is you have to define a hash for the sources of the package.
[04:41] Jon Seager
And in cases for things like Node JS packages or Rust packages or Go packages, you not only have to define a hash for the source code that you're fetching to build the package with, you then define a sort of intermediate hash of all of the vendor dependencies, whether that's Node Modules or the Cargo Packages or go modules, whatever it is.
[05:01] Jon Seager
So I'm pretty sure, yes, I, I, I, I'm sure I have read somewhere on a NIX forum an effort to make it even more reproducible.
[05:09] Jon Seager
I can't claim to be an expert on exactly what that nuance is, but to all intents and purposes, yes, packages are reproducible.
[05:16] Viktor Petersson
Fair enough.
[05:16] Viktor Petersson
And I, that's, I mean, I don't want to derail the introduction too much to nix, but it definitely sound like it solves some of the SBOM issues and supply chain issues by doing that level of pinning as well.
[05:29] Jon Seager
It does.
[05:30] Jon Seager
And it also solves the kind of dependency hell issues that we've seen for kind of years with different Linux distributions.
[05:38] Jon Seager
So Canonical tried to solve this or are solving this to an extent with snapd and snaps, right, where you might have 10 different pieces of software that depend on 10 different versions of Glibc.
[05:48] Jon Seager
And in the times of old that was difficult, right?
[05:51] Jon Seager
Like you had to do lots of trickery in your file system and lots of different build environments and compilation.
[05:55] Jon Seager
Nix kind of makes that a first class problem that it will solve.
[06:00] Jon Seager
So the way it works is every single package, every dependency, can exist in multiple forms on your machine at a given path, right?
[06:07] Jon Seager
So all of the packages and libraries and things that you download with nix going to a place in the file system called the Nix store, and they have these kind of unique names.
[06:16] Jon Seager
So each revision, each version of a package, whether that contains a library or an application, has kind of a long hash and then the name and version of the thing, which means you could have 10 versions of glibc 2.38, all with slightly different hashes because they've perhaps been built slightly differently, perhaps with a different set of compiler flags or whatever it is.
[06:35] Jon Seager
And then the applications that depend on those kind of are patched automatically to link to the right versions that were specified in its derivation.
[06:42] Jon Seager
And the kind of magic of nix is in taking care of that automatic patching of applications and making sure that libraries are all resolved from the right places and that kind of thing.
[06:53] Viktor Petersson
So, so it's very different than.
[06:56] Viktor Petersson
It just brings me down memory lane of Gen 2 in the early days where they solved that kind of by compiling everything from source, which is, I guess they still do, I guess it's still active and people are still using it, but they solve it, they solve that by compiling everything.
[07:11] Viktor Petersson
So you compile from scratch and then here you start link versus link against specific hashes and yes and no, right?
[07:19] Jon Seager
So with Nix you can build all of the packages from source, so you can go get yourself a Nixos machine and build all of the package.
[07:26] Jon Seager
So the derivations that exist in Nix packages, you can elect to build them yourself.
[07:31] Jon Seager
They also run a thing called the binary cache, which means that if your machine, if you allow it to, which most people probably do by default.
[07:38] Jon Seager
Right.
[07:38] Jon Seager
If you, if your machine looks for a given dependency, it will first check the binary cache and say, okay, do I have something that looks like that Nix store path in the binary cache?
[07:46] Jon Seager
And if so, it'll download the right version for your kind of processor architecture and operating system and just unpack it.
[07:52] Jon Seager
If it can't find something in the binary cache, then it will build it from source by default.
[07:56] Viktor Petersson
So, similar to how, and I was going to ask you like, about comparing it to Homebrew or Brew, it's similar in that sense as well.
[08:04] Viktor Petersson
I believe Homebrew has a very similar logic.
[08:07] Viktor Petersson
It tries to pull binaries and if it doesn't have one, it then.
[08:10] Jon Seager
Yeah, indeed.
[08:10] Viktor Petersson
Back to compare.
[08:11] Viktor Petersson
Compiling.
[08:12] Jon Seager
Yeah.
[08:12] Viktor Petersson
Okay, perfect.
[08:14] Viktor Petersson
So let's go through some of the core concepts in Nix.
[08:18] Viktor Petersson
I think there are Flakes and then there are some other things you want to go through some of the core building blocks.
[08:24] Jon Seager
Yeah.
[08:24] Jon Seager
So I think flakes are kind of a new and they are defined as an experimental feature at the moment.
[08:30] Jon Seager
They've been around for years as far as I can tell, but there's no.
[08:34] Jon Seager
The community has yet to reach consensus on exactly what that experience should be and the features it should have.
[08:40] Jon Seager
Safe to say I've been using flakes to run or all of my machines and build my software for the last year and nothing has changed to the extent where I've had to make any changes to my code.
[08:49] Jon Seager
And I would say if you're going to get into Nix today, my opinion is that you should invest in that ecosystem.
[08:56] Jon Seager
There are a couple of kind of small corporate entities around Nix and nixos who are peddling it quite hard and I think for good reason.
[09:03] Jon Seager
So flakes, I mean at a very fundamental level, a flake is really just a directory that has a flake mix file and a flake lock file.
[09:12] Jon Seager
And Flakes essentially outputs Nix expressions that others can use for building packages, building modules, accessing developer shells, all sorts of things.
[09:22] Jon Seager
So it's basically a mechanism to share code, share Nix code.
[09:26] Jon Seager
Right.
[09:26] Jon Seager
And so if you're the developer of some open source application, you could include a flake nix file and anyone would be able to point their nix Package Manager at your GitHub repo with the flake nix in it.
[09:37] Jon Seager
And it would then learn how to build the package, get a developer shell, perhaps there's a nixos module that you've included.
[09:44] Jon Seager
It just makes it very easy to kind of use things from around the Nix ecosystem.
[09:49] Jon Seager
And the other thing it brings is this concept of a lock file, which is very similar to your kind of package lock, cargo, lock file, go, some file.
[09:56] Jon Seager
Right.
[09:57] Jon Seager
It's a way of saying this set of NIX expressions expects, you know, NIX packages at this SHA hash as an input.
[10:06] Jon Seager
Right?
[10:06] Jon Seager
And so that's, you know, towards kind of reproducibility.
[10:09] Jon Seager
Right.
[10:09] Jon Seager
You're not going to get, okay, well know IAPPED installed on this day and the version changed and now my build doesn't work.
[10:14] Jon Seager
You can kind of say, no.
[10:15] Jon Seager
Like this flake expects exactly this slice of the NIX packages history to build, and thus it should be reproducible.
[10:21] Jon Seager
Right?
[10:22] Viktor Petersson
Okay.
[10:23] Viktor Petersson
And one thing that I guess I spoke to some people about this a little bit about is obviously there are some shared features that with Docker in the sense of how you can run it in some ways, but it's also very different.
[10:38] Viktor Petersson
So maybe we can zoom in a little bit on how it compares to Docker.
[10:42] Viktor Petersson
And then perhaps a more interesting one is how we could use NIX inside of Docker to build Docker images to make them more reproducible and more tightly controlled, I guess.
[10:55] Jon Seager
Yeah.
[10:55] Jon Seager
So there are some parallels.
[10:57] Jon Seager
I mean, Docker is primarily used these days as a means for packaging applications with their dependencies.
[11:02] Jon Seager
And certainly you can do that with a Flake or with a NIX package.
[11:05] Jon Seager
What you don't get by default with a NIX package is containerization.
[11:08] Jon Seager
Right.
[11:08] Jon Seager
Which clearly you get with Docker.
[11:11] Jon Seager
Certainly the way I run a little home server with Nix, and the way I that used to be Docker Compose, and then it was microk8s for a while, and now it is just Nix running a bunch of nixos modules that are either available publicly or that I maintain as part of my flake.
[11:25] Jon Seager
So you don't get the containerization by default, though there are ways to kind of declaratively define containers that you want to run as part of a NIX system.
[11:34] Jon Seager
The other thing you can do is you can use NIX derivations to build other artifacts from NIX packages.
[11:41] Jon Seager
Right?
[11:41] Jon Seager
So an example of that is you can use a NIX derivation to build a Docker image.
[11:46] Jon Seager
Right?
[11:46] Jon Seager
So literally the output of that derivation is an OCI image which is built, which has only the paths in it needed to Run the things that you want to put in it.
[11:56] Jon Seager
Right.
[11:56] Jon Seager
So a little bit like the distroless type containers, right?
[11:59] Jon Seager
You could have just the, you know, inside that image, it would have just the bits of the NIX store that are needed to run your package, right.
[12:06] Jon Seager
And then your package itself.
[12:08] Jon Seager
Or you can use a Docker file as normal and you could start from a Ubuntu based image and install the NIX package manager in that image and then do your work in there and do multi stage builders.
[12:18] Jon Seager
Right.
[12:18] Jon Seager
So you can kind of docker images a couple of different ways.
[12:21] Jon Seager
With Nix, you can do it kind of from the outside or from the inside, if that makes sense.
[12:25] Viktor Petersson
Yeah.
[12:25] Viktor Petersson
So I guess if you were to do that in, if you thinking about it develop environment, you would probably use the Nix file to run things locally outside Docker.
[12:36] Viktor Petersson
But when you're pushing it in CI cd, you would output that to a Docker file, which then you can consume in your cluster.
[12:44] Jon Seager
I mean, one of the really nice things that I like, I personally enjoy about the Nix ecosystem is the Nix package manager has this concept of running a package without ever installing it.
[12:53] Jon Seager
So I did this just a couple of days ago.
[12:55] Jon Seager
I was listening to a podcast that was extolling the virtues of a process manager thing called bottom.
[13:00] Jon Seager
Like top, right, but bottom.
[13:02] Jon Seager
And I wanted to try it out.
[13:03] Jon Seager
I didn't necessarily want to install it.
[13:05] Jon Seager
And I literally typed nix space, run NIX packages bottom.
[13:10] Jon Seager
And it just went and fetched that thing into my Nix store and ran the program.
[13:14] Jon Seager
And when I press Ctrl C it's gone, right?
[13:17] Jon Seager
Like the files are still in the next store, but they'll get garbage collected on some interval or the next time I clean it.
[13:22] Jon Seager
And if I want to install it, I can then go and put that package in my system configuration if I never want to see it again.
[13:27] Jon Seager
No harm done, right?
[13:28] Jon Seager
And the same can be done with development shells.
[13:30] Jon Seager
So I set up as part of my, the flicks that I put in my projects, I'll have a development shell set up which says, actually I want a Z shell with, I don't know, the go toolchain built into it plus golang CI plus GO releaser.
[13:44] Jon Seager
And so when I CV into that directory, I type mix develop and it drops me into a shell that has all of those things good to go.
[13:49] Jon Seager
And when I'm done, I just exit that shell and those tools are no longer in my path.
[13:52] Jon Seager
Right.
[13:52] Jon Seager
And so you can have these nice kind of isolated developer environments.
[13:55] Jon Seager
You can have a rustic developer environment for your rust Project a GO developer environment for your GO project.
[14:00] Jon Seager
And that can include packages, dot files, environment variables, like whatever you can think of.
[14:04] Jon Seager
You can kind of package up these like portable developer environments for all of your projects.
[14:09] Viktor Petersson
That's, that's very beautiful in particular for Python, I guess it's a bit of notorious for versions and packages and you might, with even within your project, you might use different version of Python and definitely different sub module packages.
[14:24] Jon Seager
Right?
[14:25] Jon Seager
Yeah.
[14:25] Viktor Petersson
So having that package that way sounds like a very clean of doing it so you don't have to pollute your entire system.
[14:31] Viktor Petersson
And also sounds more manageable than VMs or virtual environments that Python is heavily leveraging.
[14:38] Jon Seager
Normally, yeah, the thing that you get.
[14:40] Jon Seager
And we'll come on to nixos a little bit later, but the thing that, the way that the Nix package manager manages things is you don't.
[14:45] Jon Seager
You end up with much less of this feeling of like craft accumulating on your machine over time.
[14:50] Jon Seager
Like if you ever managed a Debian system or Uvanti system or Arch system, even if you're really, you know, competent and careful and meticulous, if you install and uninstall a bunch of packages over a period of five years, there will inevitably be stuff lying around on the machine.
[15:03] Jon Seager
Right.
[15:03] Jon Seager
That you don't necessarily want.
[15:04] Jon Seager
You can kind of escape that with Nixos.
[15:06] Jon Seager
You don't really have that situation because of the way the next store is on the file system and the way it can be kind of garbage collected and cleaned out.
[15:13] Jon Seager
You, you kind of have this feeling of a very fresh machine which only has what you've asked for at any given moment.
[15:21] Viktor Petersson
Yeah, I love the concept of that because I can definitely relate to the problem.
[15:27] Viktor Petersson
But let's.
[15:28] Viktor Petersson
So you helped me out with getting the screenly CLI ported to Nix.
[15:35] Viktor Petersson
Do you want to do a bit of a show and tell of how it works and basically bootstrap a Nix setup from zero, really, to the screenly CLI installed and I'm going to perhaps unpack what that actually does.
[15:49] Jon Seager
Yeah, certainly.
[15:50] Jon Seager
So if you look at my screen now, I've started a fresh Ubuntu VM with a tool called Multipass, which is something that I look after in my day job.
[15:58] Jon Seager
So Multipass is just a nice quick way to get Ubuntu instance on any machine.
[16:03] Jon Seager
So if I just jump into that machine, I'm now on a fresh.
[16:08] Jon Seager
A fresh Ubuntu machine.
[16:09] Jon Seager
Right.
[16:11] Jon Seager
The first thing you'll want to do in order to use next is obviously install the package manager Itself.
[16:15] Jon Seager
I mentioned a couple of sort of commercial entities that work around Nix.
[16:19] Jon Seager
One of them is determinate systems who are relatively new player, and they've put out a Nix installer which is written in Rust, which is kind of opinionated and comes with a whole bunch of the defaults that I appreciate.
[16:29] Jon Seager
Like it enables flakes by default.
[16:31] Jon Seager
It, you know, does all the things that I would probably do myself.
[16:34] Jon Seager
So that's a single kind of cult of bash as ever.
[16:39] Jon Seager
But that will get you up and running with the nix package manager on a Mac, on a Steam Deck, on a Linux machine, in CI.
[16:44] Jon Seager
Doesn't matter what it is.
[16:45] Jon Seager
Like if nix can be installed on, this is probably the way that you want to get it.
[16:50] Jon Seager
So once it's installed, we're just going to source the nix daemon file, which just places the nix package manager in the path.
[16:55] Jon Seager
And now we have access to the nix command, right?
[17:00] Jon Seager
So this is just a plain, at this point, plain Ubuntu machine with the Nix package manager installed.
[17:05] Jon Seager
One of the things that you can do with Nix I mentioned about running packages that you don't have installed on your machine is I could just run the screenly clique.
[17:13] Jon Seager
So I happen to know the package name is screeny cli.
[17:15] Jon Seager
So nix run and then you kind of say like repository hash name of package.
[17:21] Jon Seager
The default is the nix packages repository.
[17:23] Jon Seager
So if I run that command, it's now going to go off and fetch the latest versions of nix packages, figure out what to do, go and get the latest version of that package and run it, right?
[17:31] Jon Seager
It'll run the default command.
[17:32] Jon Seager
So there you go, that's the screenly cli.
[17:34] Jon Seager
And I can do whatever that might be, right?
[17:36] Jon Seager
So I can pass help to it.
[17:38] Jon Seager
Like I can just use the screenly clique as if it was installed on my machine.
[17:42] Jon Seager
The other option is I could do nix shell, right?
[17:46] Jon Seager
So nix packages screenly cli.
[17:50] Jon Seager
So this is going to drop me into a shell where the screenly CLI is now in my path.
[17:54] Jon Seager
So now I can just be.
[17:56] Jon Seager
If I could remember what the name of the command is, it's just screen there.
[17:58] Viktor Petersson
Thanks.
[17:59] Jon Seager
There you go.
[17:59] Jon Seager
So now it's in my path, right?
[18:01] Jon Seager
So I can use screenly as normal.
[18:04] Jon Seager
And then when I'm done with this shell and I don't need access anymore, I can pop out the shell and you can see that screenly is gone.
[18:10] Jon Seager
The interesting thing is it does stick around in the file system, right?
[18:14] Jon Seager
So if I take a look at the NIX store, you can see that we still have the output of these derivations in the file system.
[18:24] Jon Seager
So this is essentially what was downloaded from the nix packages repository.
[18:28] Jon Seager
And if you were looking to there, you kind of see like a very minimal root file system that has like bin slash, user, whatever.
[18:35] Jon Seager
Like imagine like just a snap, a slice of the file system that contains the things that package needs, right?
[18:42] Viktor Petersson
So under the hood, what happens when you pop in to that environment?
[18:46] Viktor Petersson
Is it a chroot environment or actually what's technical mechanism that should happen?
[18:51] Jon Seager
It is basically a whole bunch of path, variable mangling and ldpreload and these sorts of things, right?
[18:57] Jon Seager
So these binaries, the screenly binary will have been built and patched at build time.
[19:02] Jon Seager
So it will already be pointing at the right versions of libc.
[19:05] Jon Seager
So if we look at the rest of the next store, just to give you an idea, you can see there's all kinds of stuff in here, right?
[19:10] Jon Seager
So you've got Python setup tools, you've got cargo, you've got all kinds of things in here, right?
[19:16] Jon Seager
Like this is essentially all of the packages you would need to run a very tiny little Linux distribution.
[19:21] Jon Seager
And the way when you build a nix derivation, it will take care of making sure that those packages know which other packages they depend on and point to them in the right places, whether that be through path.
[19:31] Jon Seager
And it also makes extensive uses of wrappers, right?
[19:34] Jon Seager
So they are some applications that you kind of have to wrap and kind of explicitly export the path to say like, okay, one of the things you depend on is over here and over there.
[19:44] Jon Seager
But the nix sort of package ecosystem provides tools that can build those wrappers for you.
[19:49] Jon Seager
I can show you an example of this in a little while.
[19:51] Viktor Petersson
Yeah, so because it's very different from LXC and Docker.
[19:56] Viktor Petersson
Why particularly Docker?
[19:58] Viktor Petersson
So it doesn't leverage C groups or anything like that or not at this level.
[20:02] Jon Seager
No, I mean those constructs will available to you in nixos.
[20:05] Jon Seager
Right?
[20:06] Jon Seager
But this is just about essentially going, getting, running the package.
[20:10] Jon Seager
The other thing we could do is we could talk a little bit about the development environment stuff I talked about.
[20:14] Jon Seager
Yes, so if we do, if we clone the screenly repository CLI and we jump into that directory.
[20:24] Jon Seager
So this is just the upstream repository and you can see in there's a flake lix and I can now just run if I just for the sake of argument, just show you that I don't have cargo installed on this machine, right?
[20:36] Jon Seager
I have none of the rust dependencies.
[20:38] Jon Seager
If I wanted to work on your project, I can now type mix, develop and that's going to read the Flake definition, which I'll show in a moment.
[20:44] Jon Seager
It's going to go figure out what all the packages are that are needed for the development shell for this project, download and or build them, and then drop me into a shell where they're all present.
[20:53] Jon Seager
So this is currently downloading Cargo and the Rust compiler and all the various other things which should be done relatively quick.
[20:59] Jon Seager
And now you can see I can run cargo build and it's going to go build your project for me.
[21:04] Jon Seager
And I've got all the stuff I need in my path.
[21:06] Jon Seager
Good to go.
[21:07] Viktor Petersson
That's very elegant.
[21:09] Jon Seager
And so you can imagine if you're a team of people who work on a project, you no longer have to have these kind of like protracted developer setup guides.
[21:16] Jon Seager
You just say install the Nix package manager, clone the thing and type next developer and you're good to go.
[21:21] Jon Seager
Right?
[21:21] Jon Seager
Like that's right.
[21:22] Jon Seager
That's the kind of deal.
[21:25] Jon Seager
So I won't let that build all the way through.
[21:26] Jon Seager
There's a couple of things that probably take a little while.
[21:29] Jon Seager
If I just take a quick look at what that actually looks like, I'll jump out because the VIM on my actual machine is a little bit nicer configured than that fresh Ubuntu.
[21:39] Jon Seager
So we look in here.
[21:42] Jon Seager
So this is that repository that we talked about.
[21:45] Jon Seager
And if we take a look at the Flake Lix, this is essentially how I package screenly, right?
[21:49] Jon Seager
So I chose to use Flake straight away.
[21:51] Jon Seager
So this is the kind of input specification I was talking about.
[21:54] Jon Seager
So this basically says this Flake is expecting to build against the Nixos 2311 release set of packages.
[22:03] Jon Seager
23.11 was just released a couple of weeks ago.
[22:07] Jon Seager
It has the kind of inbuilt notion of building for different packages in architectures that will handle cross compilation and all that for you.
[22:13] Jon Seager
You don't have to try and figure out what that means.
[22:15] Jon Seager
You just tell it the architect as you want and it'll make it happen.
[22:19] Jon Seager
And then this is the actual package derivation.
[22:21] Jon Seager
So I talked about derivations.
[22:24] Jon Seager
The next language can feel a little bit obtuse to start with, I will concede.
[22:29] Jon Seager
But you can see here the Nix community have provided this kind of wrapper for building Rust packages, which takes care of going and fetching cargo dependencies and putting them in the right place.
[22:38] Jon Seager
So essentially you just give it a package name.
[22:41] Jon Seager
I've told it the source is in this current directory.
[22:43] Jon Seager
I've told it where the cargo Lock file is.
[22:45] Jon Seager
So as part of the build process, it will go and download the exact version of all of the Rust dependencies it needs and vendor them into the next store so that they are good to go.
[22:53] Jon Seager
Your build happens to need package config and believe it or not, Perl, that's part of the open SSL cargo package, it turns out.
[23:01] Jon Seager
And then there's a whole bunch of extra stuff that's needed for the Apple variant, and that's essentially it.
[23:06] Jon Seager
You can run like all of the rest of it in terms of how to run cargo, build and patch the binaries to look for the right libraries in the next store is all done for you.
[23:13] Jon Seager
Right, that's it.
[23:14] Jon Seager
This is all just metadata, essentially.
[23:17] Jon Seager
And this is pretty much exactly word for word what it looks like in the upstream Nix packages repository, with the exception that the source block tells it to fetch from GitHub in that case and not from the current directory.
[23:28] Jon Seager
Right, very cool.
[23:29] Viktor Petersson
And if were hypothetically were to add Docker as a target rather than just a binary, how much work would.
[23:38] Jon Seager
That be in terms of probably two or three lines.
[23:42] Jon Seager
You essentially have another output for the flake, and there's some Docker tools that are part of the kind of Nix packages repository.
[23:48] Jon Seager
Basically say, like, build me a Docker image with that package and it will output you a Docker image.
[23:52] Viktor Petersson
Oh, wow.
[23:53] Viktor Petersson
That is really that simple?
[23:55] Jon Seager
Okay, I don't have an example of that to show you, but it really is like two or three lines of code tops.
[24:00] Jon Seager
The development shell.
[24:02] Jon Seager
This is the development shell I was talking about.
[24:04] Jon Seager
So this basically says the default development shell for this flake is called screenly cli.
[24:10] Jon Seager
Set some environment config to ensure that flakes are always enabled, and it basically will derive the set of packages it needs from the set of inputs that the package derivation takes.
[24:20] Jon Seager
So I've said give me a shell that has all of the packages that are needed to build that Nix package that we just defined up there.
[24:25] Jon Seager
And I can add other things in here, right?
[24:27] Jon Seager
Like I could say, I also want H top vim and I don't know, Proto Buff and all of the other stuff, whatever it is you might want.
[24:34] Jon Seager
And then anyone who ever type Nix developed would get those things automatically available in their path.
[24:38] Jon Seager
Right.
[24:39] Viktor Petersson
That's super clean and I presume dev shell and the default navshell, those are standard building blocks in Nix.
[24:47] Viktor Petersson
It's not something that is custom here, but it's actually why.
[24:50] Viktor Petersson
No.
[24:50] Viktor Petersson
So there's a.
[24:51] Jon Seager
There's essentially a.
[24:53] Jon Seager
There's a Schema for what a flake NIX can output.
[24:56] Jon Seager
So it can output, among other things, it can output packages, overlays, nixos modules, nixos machine configurations, development shells, checks, and so in each of those categories it can have a default.
[25:08] Jon Seager
So when you just say Nix develop and nothing else, you'll get the default shell.
[25:13] Jon Seager
If you type nix build and just point at the flake, it will build the default package.
[25:18] Jon Seager
Right?
[25:18] Jon Seager
But you can have other things, other packages.
[25:19] Jon Seager
And I have an example I can show in a moment, which has lots and lots of different packages in it.
[25:24] Jon Seager
Right?
[25:24] Jon Seager
Because there's only one application in here, it just makes sense to make the default screen cli.
[25:29] Jon Seager
Right?
[25:30] Viktor Petersson
Sure, sure.
[25:32] Viktor Petersson
No, that's really cool.
[25:33] Viktor Petersson
You, you mentioned Nix OS a few times.
[25:38] Viktor Petersson
Should we switch gear and talk a bit about Nix os?
[25:41] Jon Seager
Yeah, let's do that.
[25:42] Jon Seager
So Nix OS is fundamentally just a Linux distribution that is based upon the Nix package manager and the kind of principles that it enforces.
[25:52] Jon Seager
So it is what you would describe as an immutable operating system in that large portions of the file system are mounted, read only when it boots.
[25:59] Jon Seager
And you can't just go hacking around in etc or whatever, you have to.
[26:02] Jon Seager
The way you mutate the system configuration is by mutating a set of NIX files and then rebuilding the kind of system from that, like generating the system from that.
[26:12] Jon Seager
And Nix OS has these, has this concept of generation.
[26:14] Jon Seager
So every time you make a material change to the machine configuration, it will build a new generation and the old one will stick around, which means if you break something, you can revert back to it will just boot the last generation because it's all based on essentially a pile of symlinks.
[26:29] Jon Seager
So one of the weird things about nixos is it throws all of the rules of the standard kind of Unix file hierarchy system out of the window.
[26:37] Jon Seager
And so one of the challenges, and one of the reasons the Nix package manager has all of this magic for automatically patching binaries and injecting, you know, creating wrappers that set the path variable, is because on an XOS machine, like for example, User Bin Bash doesn't exist.
[26:54] Jon Seager
Like LIBC is not where you would expect it to be, it is in the next store and it is symlinked into place.
[27:00] Jon Seager
But as a result of that, you get really fine grained control.
[27:04] Jon Seager
So I can give you an example if I take a look at how my machines are defined, which we'll jump into in just a sec.
[27:16] Jon Seager
But essentially you have this declarative by nature operating system and that declarative kind of nature goes all the way down in my case to file systems bootloaders.
[27:27] Jon Seager
I have everything on all of my machines completely defined, literally how the disks are partitioned, how the bootloader is laid down, how the firmware is updated on the machine, right through to what fancy configuration do I want in Neo Fetch so I can post it on Reddit.
[27:43] Jon Seager
Right.
[27:43] Jon Seager
Like the dot files for Vim, the.
[27:46] Jon Seager
The extensions I have installed in Chrome, the packages I have available in various different environments.
[27:51] Jon Seager
Right.
[27:51] Jon Seager
All defined in code checked into Git.
[27:55] Viktor Petersson
That's cool.
[27:56] Jon Seager
Yeah, it's super cool.
[27:58] Jon Seager
There's no going back.
[28:01] Jon Seager
I mean, to give you an idea of what that looks like.
[28:04] Jon Seager
I mean, so this flake, one of the interesting things about flakes for system configuration is you can have multiple machines defined in a single flake and reuse code kind of modules like you would in any other programming language, right?
[28:16] Jon Seager
So this is a set of inputs that I use.
[28:19] Jon Seager
You can see it as kind of repositories that provide packages or modules I might want.
[28:23] Jon Seager
So I have NIX packages itself.
[28:25] Jon Seager
Agency is a package which provides kind of secrets management using the age package Lanza Booty is a community project that provides secure boot support for nix.
[28:35] Jon Seager
So the machine I'm on uses secure boot with automated full disk encryption unlock from the tpm, which is super nice.
[28:45] Jon Seager
And then these are actually projects that I maintain.
[28:47] Jon Seager
So Crafts is a repackaging of Carnival's craft tools.
[28:52] Jon Seager
There's snapcraft, charmcraft, Rock Craft, but available for Nixos because I have to build these artifacts every day and I prefer to do it natively on my machine that are vm.
[29:00] Jon Seager
Ember is a small project I wrote that uses Firecracker to launch Ubuntu VMs, really fast for 10 testing and libations is a very recent addition which is a little cocktail recipe app for my phone that I host on a server and browse to over tailscale.
[29:13] Jon Seager
And I have kind of multiple machines here, right?
[29:16] Jon Seager
So that's my laptop, that's my desktop, it's a little server in my in laws house and this is my home server.
[29:22] Jon Seager
And these all use a kind of common set of modules, if you will, that allow me to kind of reuse all of the complicated bits.
[29:31] Jon Seager
So for example, in services you'll see I have one set of configuration for example for pipewire, so services enablepipewire and I reuse this module in all my machines to make sure that I never have to worry about how to configure pipewire Again, I have various modules for bits of hardware.
[29:50] Jon Seager
I have these nice audio engine monitors on my desk, and pipewire likes to suspend inactive syncs after a given set of seconds.
[29:59] Jon Seager
And because they have their own DAC in them that makes them pop a bit like you're unplugging a 3.5mm jack and plugging it right in.
[30:05] Jon Seager
And so this piece of config I write, once I include it on all the machines that have audio NG monitors attached to them, and they stop popping on all those machines, it just solves the problem for me forever, basically.
[30:16] Jon Seager
So, yeah, it's interesting.
[30:19] Jon Seager
This is what you're seeing here is the nixos module system in action.
[30:22] Jon Seager
So you can think of nixos as the combination of the NIX package manager and the nixos module system.
[30:28] Jon Seager
And nixos modules are the thing that turns a pile of packages into a distribution.
[30:34] Jon Seager
So it says, okay, well, this package needs to be started with systemd before that package on this target, right?
[30:39] Jon Seager
This package requires a state directory in varlib Fu.
[30:42] Jon Seager
This package requires, you know, some configuration in Etsy, blah, blah, right?
[30:46] Jon Seager
And so that's kind of how they work if we look at the hardware side, Kara, this is the machine I'm on right now.
[30:55] Jon Seager
So I enable this new convention for kind of bootloaders and a declarative boot called Boot Spec.
[31:02] Jon Seager
And that's what enables me to use Secure Boot.
[31:05] Jon Seager
I then say which kernel modules are available in the INIT RD and which kernel modules I like enabled on the machine.
[31:11] Jon Seager
And I tell it I like to use the latest Linux kernel in this case.
[31:16] Jon Seager
This is my disk specification.
[31:18] Jon Seager
So this is with another community project called Disko.
[31:21] Jon Seager
So you can see I essentially specify two devices, NVMe Zero, which is my root file system, which has an ESP partition and a bunch of butterfs sub volumes.
[31:31] Jon Seager
And then I have a second disk which is just for data, and I specify kind of an encryption key for it and a whole bunch of other stuff.
[31:38] Jon Seager
And so when I point the next OS installer at this flake, it basically, the installation process for one of my machines is I boot the nixos LIVE ISO.
[31:48] Jon Seager
I clone.
[31:49] Jon Seager
I literally type essentially one or two commands, right?
[31:53] Jon Seager
I basically clone my repo and say nixos install and point it at this flake and give it the host name I want it to build, and it just drops the configuration on the machine.
[32:01] Jon Seager
I reboot and the machine is exactly as it was before, right?
[32:03] Jon Seager
So like the everything down to extensions installed in Chrome, plugins installed in Vim, the whole thing, theme that I want to set on my desktop.
[32:12] Jon Seager
Everything is entirely declarative, right?
[32:15] Viktor Petersson
So it's a bit like, what, cloud init on steroids in some ways, I guess.
[32:20] Jon Seager
Yeah.
[32:20] Jon Seager
And you can just kind of go.
[32:22] Jon Seager
So I use another project called Home Manager.
[32:24] Jon Seager
And Home Manager is.
[32:26] Jon Seager
You can think of it as kind of like a, I don't know, almost like a nix virtual environment for your home directory.
[32:32] Jon Seager
And so I use Home Manager to, for example, to configure vim.
[32:35] Jon Seager
So we could look them in, we could get meta here and look at like the.
[32:38] Jon Seager
The vim config of the vim that we're looking at.
[32:41] Jon Seager
So this is my vim config.
[32:43] Jon Seager
I use a Home Manager module and I basically say enable vim with this package.
[32:48] Jon Seager
Set up some aliases for me.
[32:49] Jon Seager
Here's a bunch of LUA config that I've written and here are the VIM plugins that I want.
[32:54] Jon Seager
And that means that on any machine I go to, vim is set up identically.
[32:58] Jon Seager
I never have to work out how to do it again.
[33:00] Jon Seager
Right?
[33:00] Jon Seager
Like I just.
[33:01] Jon Seager
And I actually use this Home Manager config to provision Ubuntu VMs.
[33:05] Jon Seager
So I not only does this manage my nix machines, but on Ubuntu now I download the nix package Manager and I use Home Manager to provision all my dot files.
[33:14] Jon Seager
Right?
[33:14] Jon Seager
So these, you know, each of these kind of nix statements will be translated in the background to whatever the format is required for this app.
[33:22] Jon Seager
So in this case tmux, it will write a tmux.com file based on the contents of this.
[33:25] Viktor Petersson
Right?
[33:26] Viktor Petersson
That's super cool.
[33:27] Viktor Petersson
So.
[33:28] Viktor Petersson
So you don't have to manage dot files in the traditional simulink git repo.
[33:32] Jon Seager
One example is git, right.
[33:34] Jon Seager
If you look here, this is essentially my what the sorts of thing you'd expect to find in your git config email name.
[33:42] Jon Seager
There's some rules about which of my identities I use, depending on which directory I'm in, my file system aliases.
[33:48] Jon Seager
And this will get rendered out into like a git config in your home directory, essentially.
[33:54] Viktor Petersson
That's super clever.
[33:55] Viktor Petersson
That's super clever.
[33:58] Viktor Petersson
So the way you bootstrap this machine is so you do a live cd essentially, and then you invoke by git repo.
[34:04] Viktor Petersson
You clone the git repo.
[34:05] Jon Seager
Yeah, I can actually show you.
[34:06] Jon Seager
I've scripted it to an extent, so let me just quickly show you what that looks like.
[34:12] Jon Seager
So I have this install with disco script, which I sort of collaborated on A bit with a chap called Martin Wimpress, who's quite well known in the Ubuntu community.
[34:22] Jon Seager
So this is basically a wrapper.
[34:24] Jon Seager
This is how I installed this machine.
[34:26] Jon Seager
I'm talking to you right now.
[34:26] Jon Seager
So I re.
[34:27] Jon Seager
I recently kind of redid it because I went down the whole secure boot and TPM backed FD root.
[34:33] Jon Seager
But the crux of this is basically I run disco and pass it the disk config for the host.
[34:40] Jon Seager
If you imagine target host would say Cara Freya Huggin.
[34:42] Jon Seager
Right.
[34:43] Jon Seager
The names of the machines I have.
[34:45] Jon Seager
And so I say nix run disco from the live ISO, it will go and essentially partition the disk from underneath me.
[34:52] Jon Seager
And then I say nixos install flake and give it the name of the host to build.
[34:56] Jon Seager
So in this case it would be Kara.
[34:58] Jon Seager
And then all this is just making sure the nixos config gets like asking to cross into the file system just so I don't have to re clone it when I boot up.
[35:05] Jon Seager
But essentially the install process is those two commands.
[35:08] Jon Seager
I run disco and then I run NIX install nixos install and point it to my flake and that's it.
[35:13] Jon Seager
And so I, like, it's really nice to not have to worry.
[35:18] Jon Seager
When I wanted to go through this process of.
[35:21] Jon Seager
I didn't used to use disco.
[35:22] Jon Seager
I had kind of did like a manual partitioning and install process the first time.
[35:26] Jon Seager
And I'd been using the machine for maybe three or four months.
[35:28] Jon Seager
I got it all set up exactly how I liked it.
[35:31] Jon Seager
And the entire process of like new compaving the machine and getting it back to exactly how it was before was like five or six minutes in total.
[35:40] Jon Seager
Okay.
[35:41] Jon Seager
It just becomes a total non issue.
[35:42] Jon Seager
Right, right.
[35:44] Viktor Petersson
Is this something that you would, I mean, you obviously use for your home lab.
[35:48] Viktor Petersson
Is it something that you would consider production ready for the cloud or is it still kind of far off from there?
[35:56] Viktor Petersson
Or how do you.
[35:57] Jon Seager
I think, yeah, like, I mean, depends on your use case.
[35:59] Jon Seager
Right.
[35:59] Jon Seager
Like, I mean, good luck finding big company.
[36:01] Jon Seager
You know, one of the reasons that people choose Canonical, for example, in my professional life is because we're a company that can provide professional support and security, maintenance and things like that.
[36:08] Jon Seager
And you know, there are certainly companies around that do consulting around Nix and will help you with that, but it's nowhere near as, you know, prolific as something like Canonical or Red Hat or Seuss or whatever.
[36:19] Jon Seager
Right.
[36:20] Jon Seager
But I know of companies who run entirely on Nix.
[36:22] Jon Seager
Right.
[36:23] Jon Seager
Like, and there's something nice from a security posture standpoint, you build these VMs that have exactly what you asked for and nothing more in them.
[36:29] Jon Seager
Right.
[36:30] Jon Seager
Attack Surface is very small.
[36:32] Jon Seager
I can give an example actually of a VM spec that I use just for testing some code.
[36:39] Jon Seager
So if I go to Flake.
[36:42] Jon Seager
So I mentioned earlier on the crafts.
[36:44] Jon Seager
Flake.
[36:45] Jon Seager
So this is essentially packaging snapcraft.
[36:47] Jon Seager
So for building Snap applications and interacting with the Snap store as a developer.
[36:50] Jon Seager
But for on Nix, it's a bit of a strange situation, but this repository provides all of the Python packages that they depend on and then the apps themselves, charmcraft, Rockcraft and snapcraft.
[37:03] Jon Seager
And I wanted a way of testing that these things functioned correctly on nixos in CI.
[37:09] Jon Seager
So before I merge a change, I want to make sure that I've bootstrapped an actual nixos machine, installed charmcraft and tried to build a real charm with it.
[37:16] Jon Seager
Right.
[37:17] Jon Seager
And so I did that by including a nixos configuration for the build VM in the repository.
[37:22] Jon Seager
So, which I can show you here.
[37:23] Jon Seager
So if we just take a quick look at VM Nix.
[37:26] Jon Seager
So this is the entire configuration for a NixOS machine.
[37:30] Jon Seager
There's a few shortcuts here because it's a QMU vm, so it's a little bit simpler in terms of, you know, as ever, it's a vm, but essentially you tell it what platform packages you want to get from Nix, it uses an overlay, which is provided by the Flake.
[37:44] Jon Seager
So the overlay is a way of essentially customizing your machine's view of Nix packages.
[37:51] Jon Seager
And this is super interesting because, for example, imagine that Nix packages provides version 1.2 of A thing foo, like some package on the Internet, but you are like Captain Bleeding Edge and you want to have 1.3.
[38:06] Jon Seager
It's just been released and it hasn't landed in Nix packages upstream yet, but you want it on your machine.
[38:11] Jon Seager
You can literally say, right, take all of Nix packages, except patch the attribute to say, 1.3 rather than 1.2, and rebuild the package with that attribute changed.
[38:19] Jon Seager
Nice.
[38:20] Jon Seager
So here this is basically saying make Nix packages look like it already has my packages in it.
[38:24] Jon Seager
Charmcraft, snapcraft, Rockcraft, you know, enable.
[38:28] Jon Seager
In this case, it's just a CI testing vm.
[38:30] Jon Seager
So I disable the firewall, enable open ssh, allow login with password and allow lexd, and that's it.
[38:37] Jon Seager
If I want to run that VM from any machine, I can do nix, run the test vm, and I'm going to tell it to demonize and go in the background.
[38:46] Jon Seager
So there you go.
[38:47] Jon Seager
It's pre built.
[38:48] Jon Seager
So all of the dependencies downloaded.
[38:49] Jon Seager
This would sometimes take a couple of minutes because we'd have to build an entire rootfs and I can now ssh into that vm.
[38:56] Jon Seager
Right.
[38:56] Jon Seager
So it's set up with a password that I've already set in the config.
[38:59] Jon Seager
And there we go.
[39:00] Jon Seager
We're now in a Mixos vm and inside this Nexus VM is not snapcraft, apparently.
[39:09] Jon Seager
So this is essentially a brand new.
[39:11] Jon Seager
A brand new Nexus vm.
[39:14] Jon Seager
So I should be able to do, for example, okay, it hasn't gone through the whole setup, I need to try again on this demo.
[39:25] Jon Seager
But essentially this is a brand new Nixos VM and when I come out of it's gone again.
[39:28] Jon Seager
And anyone could git clone the crafts flake and run this command and that VM would begin running on their machine with all the exact same set dependencies that we just spoke about.
[39:37] Jon Seager
Right, nice.
[39:39] Viktor Petersson
So one thing you mentioned security before about improving security because it's basically reducing or removing a lot of dependencies I.e.
[39:49] Viktor Petersson
potential attack vector, essentially.
[39:51] Viktor Petersson
But one thing that stood out to me is if you are keeping around so many different versions of various like let's say libc, for instance, would not the fact that you're not pinning into a system LIBC potentially increase the risk of you having a compromised version for that particular package?
[40:15] Viktor Petersson
You're maintaining like five different versions of libc, for instance.
[40:18] Jon Seager
Yeah, I mean, LIBC maybe wasn't a great example in the sense that I don't think there's a.
[40:22] Jon Seager
I could be wrong.
[40:22] Jon Seager
Maybe there are different versions for a given release of nixos.
[40:25] Jon Seager
I don't know off the top of my head.
[40:25] Jon Seager
But I mean, yes, it's like anything else.
[40:27] Jon Seager
Like you have to have a bit of good hygiene about it.
[40:29] Jon Seager
Right.
[40:29] Jon Seager
If you never update your machine, you're going to have out of date stuff.
[40:31] Jon Seager
Right?
[40:32] Jon Seager
Yeah, the.
[40:33] Jon Seager
There's a couple of different kind of channels.
[40:36] Jon Seager
They're known as in Nix.
[40:37] Jon Seager
So you can run.
[40:38] Jon Seager
They do six monthly releases, so normally in May and November.
[40:42] Jon Seager
So we just had 2305 in May and there's 2311 just happened and they'll be at 2405.
[40:47] Jon Seager
And so actually quite similar to Ubuntu in some ways.
[40:50] Jon Seager
Or you can find Unstable.
[40:52] Jon Seager
Right.
[40:52] Jon Seager
So I follow Unstable because I'm a lunatic and I like my machines breaking on me all the time, which is actually unfair.
[40:57] Jon Seager
They don't break often, but you know, it comes with a little bit more instability than the kind of, you know, six Months he releases.
[41:05] Jon Seager
So it's.
[41:07] Jon Seager
It's kind of up to you.
[41:08] Jon Seager
I have some machines that run on a stable release for the reason that, you know, I.
[41:13] Jon Seager
My little home server, for example, I don't want to have to fiddle with it all the time.
[41:17] Jon Seager
I want it to perform the.
[41:18] Jon Seager
I just want it to work.
[41:19] Viktor Petersson
Yeah.
[41:20] Jon Seager
My laptop and my desktop, I run a bit more bleeding edge because I want to play with all the new shiny pipewire and new shiny Hyperland and new shiny whatever else.
[41:26] Jon Seager
Right.
[41:27] Viktor Petersson
Okay, that makes sense.
[41:29] Viktor Petersson
So one thing I wanted to kind of wrap up this conversation with is I think you have probably some of the most.
[41:38] Viktor Petersson
Complicated might not be the best word, but sophisticated, perhaps home setup and developer environment setup with.
[41:47] Viktor Petersson
I know some of it is tailscale and there is a bunch of Envoy, I believe it is, and just want to walk me through a little bit of like your pet project, I guess, which is your.
[42:00] Viktor Petersson
Your home lab.
[42:01] Jon Seager
Yeah, certainly.
[42:02] Jon Seager
So, I mean, it's not actually.
[42:04] Jon Seager
I mean, in reality, not as complicated as it probably sounds.
[42:07] Jon Seager
So let me.
[42:08] Jon Seager
I can sort of demonstrate some of it.
[42:10] Jon Seager
So I use.
[42:11] Jon Seager
I use Tailscale really heavily.
[42:12] Jon Seager
I probably beginning to sound like a paid shill for Tailscale, but I'm not.
[42:16] Jon Seager
I just think it's absolutely great tech.
[42:18] Jon Seager
I just think they do a wonderful job.
[42:19] Jon Seager
I maintained my own WireGuard server on DigitalOcean for years and for some reason resisted going to Tailscale.
[42:25] Jon Seager
And the first day I tried it, I was like, oh my God, why have I been so.
[42:30] Jon Seager
I mean, it's not that complicated.
[42:31] Jon Seager
I have all my machines on tailscale, so my phone, my laptop, my desktop, my home server, my Apple TV, my iPad, like everything is on tailscale.
[42:39] Jon Seager
And that takes the problem of connectivity out of the picture.
[42:42] Jon Seager
All of my machines can talk to all of my machines all of the time, irrespective of what network I'm on, which makes life pretty easy.
[42:50] Jon Seager
I have a honking great desktop under my desk with a big 32 core Ryzen chip in it.
[42:54] Jon Seager
And then I have a relatively tiny kind of ultrabook laptop.
[42:58] Jon Seager
And the way I.
[42:58] Jon Seager
When I travel for work, I take my little tiny laptop and it runs a web browser and a terminal.
[43:04] Jon Seager
And I basically connect over my tailscale network to my big desktop.
[43:07] Jon Seager
So if I'm ever doing any technical work, it's all happening on the desktop.
[43:10] Jon Seager
And I use things like Visual Studio code Remote.
[43:12] Jon Seager
Right.
[43:13] Jon Seager
Just a remote VS code.
[43:15] Viktor Petersson
Which is, by the way, like you showed me that.
[43:18] Viktor Petersson
And I was.
[43:19] Viktor Petersson
I've been never been A big fan of VS code but that is a game changer.
[43:24] Viktor Petersson
Like the developer environment, you just have.
[43:26] Jon Seager
The local window, the machine.
[43:27] Jon Seager
It looks like it's running locally on your machine, but actually when you open a terminal, it's a terminal on the remote machine.
[43:32] Jon Seager
You open a file, it's a file on the remote machine.
[43:35] Jon Seager
Right?
[43:35] Jon Seager
It's a super nice way to do your work.
[43:37] Viktor Petersson
In particular with tailscale.
[43:39] Viktor Petersson
It's such a clean developer experience.
[43:41] Jon Seager
Obviously if you're into I use Vim.
[43:43] Jon Seager
So if I'm in the terminal, I use vim.
[43:45] Jon Seager
If I'm not, you know, forced to be in the terminal because I'm not an SSH or whatever.
[43:48] Jon Seager
Like my editor of choice for day to day work is versus Code.
[43:52] Jon Seager
And it just to me that just is a super nice benefit is I can carry this super lightweight laptop with a nice long battery life and you know, doesn't break my back carrying it around, but I can get access to my ridiculous desktop and my server at home without thinking about it.
[44:07] Viktor Petersson
And with VIM binding on versus code it makes it more sensible as well.
[44:10] Jon Seager
Yeah, told.
[44:12] Jon Seager
I mean but I mean the server setup is not.
[44:14] Jon Seager
Not super crazy, right?
[44:16] Jon Seager
So the server is called Thor because back when I bought it I thought it was quite powerful.
[44:20] Jon Seager
These days, not so much.
[44:21] Jon Seager
It's just an old NUC.
[44:22] Jon Seager
It's literally an i7 NUC.
[44:25] Jon Seager
And it's a pretty simple config, right?
[44:27] Jon Seager
It has the boot stuff set up as per my other machine.
[44:31] Jon Seager
I specify the disks with disko and in extra.
[44:36] Jon Seager
I also back this thing up with Borg Backup.
[44:38] Jon Seager
So this is an example of how you can back up like you can declaratively set up Borg backup.
[44:43] Jon Seager
So here I'm using the Nixos module system to say services Borg backup and I create a job called Borg Base.
[44:48] Jon Seager
I throw it some paths that I want to back up and some paths I want to exclude.
[44:52] Jon Seager
I give it the repo and I am using agency here to kind of bring the secrets in.
[44:56] Jon Seager
So the secrets are all in the git repository, encrypted, using nice modern cryptography and that goes away every evening and backs my stuff up to board base.
[45:04] Jon Seager
And I don't really think about it in terms of services.
[45:08] Jon Seager
Again, this is all so the way I like to run it is it runs a whole bunch of media server stuff, Jellyfin and that sort of stuff.
[45:16] Jon Seager
And that is all run kind of bare Nixos modules, right?
[45:20] Jon Seager
They're just like installed as Nixos modules services.
[45:23] Jon Seager
Jellyfin Enable equals true and it appears and I have traffic in front of that, but I've got traffic configured to pull TLS certificates from tailscale.
[45:34] Jon Seager
So tailscale has this neat feature where it can issue you internal HTTPs certificates.
[45:39] Jon Seager
So it uses the DNS challenge, I believe, to basically, when you use tailscale, each of your machines gets a DNS name with a thing they called Magic DNS.
[45:48] Jon Seager
And they can basically do all of the plumbing for you to make sure that you get a cert from let's encrypt that's valid inside your tailnet.
[45:54] Jon Seager
Right.
[45:54] Jon Seager
And so there's this nice feature in Traefik 3, and in fact, this is an interesting kind of illustration of overlays.
[46:03] Jon Seager
Right.
[46:03] Jon Seager
So Traefik 3 is in beta, so it's not in the Nix packages repository at the moment, but I want it.
[46:09] Jon Seager
Right.
[46:09] Jon Seager
And so what I say is, on my systems there is a package called traffic3 which takes the existing traffic definition from nix packages and just overrides the version number and the hash of the source code and builds it otherwise exactly the same.
[46:24] Jon Seager
So it keeps all the same.
[46:25] Jon Seager
All the knowledge about how to build traffic is all in Nix packages.
[46:28] Jon Seager
And I'm just saying do that, but do it with that version of the source code instead.
[46:33] Viktor Petersson
Very nice.
[46:34] Jon Seager
So that just means that traffic on my machine happens to be, in this case 300 beta 5.
[46:40] Jon Seager
I'll do this kind of periodically.
[46:41] Jon Seager
Like maybe there's a bug in a package and there was a bug in LEXD for nixos a few weeks ago, and I use LEXD every day for work.
[46:48] Jon Seager
And so I patched it in an overlay to make it work on my machine, submitted the patch to nixos and then when it landed in nixos, I removed the overlay and pulled it down from the Nix package repository.
[46:58] Jon Seager
Right.
[46:58] Jon Seager
So it's a really nice.
[46:59] Jon Seager
Like you can just kind of patch things on your system there and then if you want to, either indefinitely or until it gets fixed.
[47:06] Viktor Petersson
So the beautiful structure of this setup is essentially you got a zero trust environment almost that, largely thanks to tailscale and traffic, you have a beautiful secure environment that.
[47:22] Viktor Petersson
Well, it is vpn, I guess, but it's zero trust in the sense of like using proper sign certs, using proper set of setups between routing between devices.
[47:33] Jon Seager
Yep.
[47:34] Jon Seager
So, I mean, if you.
[47:35] Jon Seager
For example.
[47:36] Jon Seager
So my latest project is a little cocktail recipe app.
[47:40] Jon Seager
It's called Libations, it's on my GitHub and that is really interesting.
[47:43] Jon Seager
Tailscale provide a library called tsnet which allows you to essentially embed the idea of joining a tail scale network into an application.
[47:51] Jon Seager
This application knows how to join a telnet.
[47:53] Jon Seager
Essentially I set an environment variable which has a key and I run libations and it will join my telnet as if it's like a machine.
[48:01] Jon Seager
It'll just appear on my tailnet as an application that exposes a service and that's deployed on my server.
[48:06] Jon Seager
If we look at, for example, so if I just break down this a little bit.
[48:16] Jon Seager
So each person's tailscale network, Tailnet gets like a, an ID, right?
[48:22] Jon Seager
Mine is Tailnet D5DA.
[48:24] Jon Seager
You can choose it and change it and mess around.
[48:26] Jon Seager
I've just left it as the default.
[48:27] Jon Seager
And so my kind of tailscale network is tailnet d5da ts.net and then each of my machines are, you know, hostname.
[48:34] Jon Seager
So Cara, Thor, Plugin, whatever.
[48:37] Jon Seager
And if I look, if I try to grab this thing now, you'll see it's HTTP.
[48:41] Jon Seager
And I was hoping to get the certificate there as well.
[48:45] Jon Seager
You can see here it's done a TLS 1.3 handshake with a certificate that was issued by.
[48:51] Jon Seager
Let's encrypt based on the tailscale certificate name.
[48:55] Jon Seager
Right.
[48:56] Jon Seager
And this app is only ever available on my telnet.
[48:58] Jon Seager
It doesn't exist on the public Internet, so to speak.
[49:01] Jon Seager
But all of my machines, or critically my phone can see it.
[49:04] Jon Seager
Right.
[49:04] Jon Seager
and that's it.
[49:06] Jon Seager
I use tailscale acls so I limit which machines can talk to which other machines.
[49:11] Jon Seager
but yeah, it's looks really complicated but in reality is super low maintenance because all the machines are declaratively configured and all the networking is taken care of by tailscale.
[49:22] Jon Seager
It really like is.
[49:24] Jon Seager
It's the lowest maintenance kind of home lap situation I've had in a long time.
[49:28] Viktor Petersson
And you could treat everything like a DMZ essentially on your network.
[49:32] Jon Seager
Yeah, with the caveat that the learning curve for Nix and Nixos is steep.
[49:38] Jon Seager
Like, it took me, I ran what the machine that is now running as a little home server.
[49:42] Jon Seager
I ran on my desk alongside my desktop for maybe three months.
[49:45] Jon Seager
I watched a whole bunch of videos and I just kind of iteratively built this machine up and blew it up a bunch of times and broke it and kind of slowly iterated towards a point where I thought, actually now I think I could probably install this.
[49:56] Jon Seager
I think I went to my laptop next and then after I'd used it on my laptop for a bit, I was then like, all right, the next Way to level up is just to put this on my desktop and suffer through it every day.
[50:04] Jon Seager
And now I think I'm pretty converted.
[50:09] Viktor Petersson
Yeah, I mean I.
[50:10] Viktor Petersson
I was initially starting to working with porting our CLI to.
[50:14] Viktor Petersson
To nix myself an evening and I figured well, how hard can it be?
[50:19] Viktor Petersson
Well, it turns out that it's slightly steeper loading curve than waking up a docker file or something.
[50:25] Jon Seager
Yeah, it's one of those things like it's a lot of investment up front, but it is super powerful.
[50:30] Jon Seager
Like I now for all the, for all of the things that I work on, I do a flight Linux.
[50:35] Jon Seager
I mean I can show you that libations thing that I was just talking about, right.
[50:39] Jon Seager
This is so this is the flake nix for that and it has a package, I mean that's literally all of the code to package that go project as you know, as a NIX package for any system.
[50:52] Jon Seager
Right.
[50:53] Jon Seager
So I literally say the source is this directory.
[50:55] Jon Seager
Here's the hash for all of the dependencies.
[50:57] Jon Seager
It needs Hugo because it serves a static site built with Hugo and that's it, that's the whole thing.
[51:01] Jon Seager
That is the build recipe for that package on any Nix machine.
[51:06] Jon Seager
And then I also provide a Nixos module.
[51:08] Jon Seager
So if anyone caught onto the modules thing, this is basically saying on a Nixos machine if you've got this kind of set up in your environment, you can do, you know, services libations enable equals true and it will set up this systemd unit for you with this environment and like these settings.
[51:25] Jon Seager
Right.
[51:25] Jon Seager
So it's a way of providing kind of very similar to snaps.
[51:30] Jon Seager
Right.
[51:30] Jon Seager
You work in the Snap where snaps have SNAP services.
[51:32] Jon Seager
Right.
[51:32] Jon Seager
So you've got the actual package and then the ability to run something as a daemon.
[51:35] Jon Seager
This is very similar to that in some respects.
[51:38] Viktor Petersson
Interesting.
[51:38] Viktor Petersson
So do you need to do that for.
[51:43] Viktor Petersson
I guess you do that for your traffic setup as well where you need to renew certificates, you define them in a similar sense.
[51:49] Viktor Petersson
Wow.
[51:49] Jon Seager
I can show you the traffic setup.
[51:51] Jon Seager
It's not soup.
[51:53] Jon Seager
Interesting because a lot of it is taken care of by traffic.
[51:56] Jon Seager
Ultimately that is not what I wanted.
[52:00] Jon Seager
So if we look at.
[52:07] Jon Seager
So so this is set up in a slightly more modular fashion.
[52:10] Jon Seager
So this kind of just basically says enable traffic, enable the traffic module.
[52:16] Jon Seager
But instead of using the package in upstream, use my Traffic 3.
[52:19] Jon Seager
Right.
[52:19] Jon Seager
So this is saying use exactly what the Nixos folks, the find Nixos folks have defined but don't install their Traefik package.
[52:25] Jon Seager
Install mine and then on Thor I have this config where I essentially say, you can see again, like this is defined in the NIX language, but will get rendered out to a config YAML or config toml.
[52:39] Jon Seager
Right.
[52:39] Jon Seager
So this will become a config that Thor, that Traefik knows how to build.
[52:44] Jon Seager
Right.
[52:44] Jon Seager
So you can see here, if you're familiar with Traefik, I don't know.
[52:46] Jon Seager
But here are the routers.
[52:47] Jon Seager
Right.
[52:48] Jon Seager
That I have.
[52:49] Jon Seager
Here are the services that back those and they point to all the different ports of all the different things that are running on the machine.
[52:54] Jon Seager
And I have a couple of, you know, where is it?
[52:57] Jon Seager
Here's the let's encrypt config that tells it how to use.
[53:01] Jon Seager
What's this?
[53:02] Jon Seager
So yes, this machine has some stuff on the external Internet and uses distillations.
[53:06] Jon Seager
Let's encrypt provider.
[53:07] Jon Seager
And some stuff is in tailscale.
[53:09] Jon Seager
And that's it.
[53:09] Jon Seager
Like, that's all the.
[53:11] Jon Seager
So there's 108 lines of nix, including a couple of helper functions.
[53:14] Jon Seager
Right, nice.
[53:15] Viktor Petersson
And behind the scenes on NIX os, I presume it relies on systemd to manage services.
[53:23] Jon Seager
Yeah, exactly, it is.
[53:26] Jon Seager
I mean, to the extent that, you know, if I just take a look at.
[53:32] Jon Seager
If you look in here, you can kind of see some of the nix magic at play.
[53:36] Jon Seager
Right.
[53:36] Jon Seager
So I don't know if you.
[53:38] Jon Seager
This is Etsy systemd system where you'd expect to find system units.
[53:42] Jon Seager
And you can see each of them is kind of a symlink to somewhere in the next store.
[53:46] Jon Seager
Right?
[53:46] Jon Seager
Right.
[53:47] Jon Seager
We could take a look at traffic on my server if you wanted.
[53:50] Jon Seager
Right.
[53:50] Jon Seager
So if I jump onto my server.
[54:00] Jon Seager
So you can see Traefik service is symlinked to this thing in the NIX store.
[54:05] Jon Seager
So if we take a look at that file, that's the systemd unit that was written by the NIX OS module.
[54:11] Jon Seager
And you can see that it is running Traefik 3.00 beta 5 as I declared in my overlay.
[54:17] Jon Seager
And it's running from this config file.
[54:19] Jon Seager
So if I grab that and cut that out.
[54:23] Jon Seager
You can see this is a valid traffic config but generated from the.
[54:28] Jon Seager
The kind of nix language stuff.
[54:30] Jon Seager
Right.
[54:30] Jon Seager
And then it kind of goes, you know, it's got a providers thing here which again, you can kind of follow all the.
[54:36] Jon Seager
Down there's all the routers that have been translated from my NIX code into something that traffic can understand with all the different kind of host names and paths and various things.
[54:43] Jon Seager
It needs.
[54:43] Jon Seager
Right.
[54:45] Jon Seager
Wow.
[54:45] Jon Seager
But obviously the nice thing about NIX is while it's a little bit terse and not everyone loves the language, once you've learned it, the machinery behind the scenes then takes care of figuring out how to render a traffic file or a TOML file for traffic or a VIMRC or whatever it is.
[55:02] Jon Seager
Right.
[55:02] Viktor Petersson
Yeah, no, this is super interesting.
[55:06] Viktor Petersson
I wish I had enough time to play with this, but I definitely will try to carve out some time in the future and maybe we do another in person no doubt session and yeah, I'll.
[55:18] Jon Seager
I'll send over some links that you can chuck into your.
[55:20] Jon Seager
There's a couple of really good resources.
[55:21] Jon Seager
There's the people who make the NIX install I spoke about have a thing called Zero to Nix, which is this nice kind of getting started guide and I watched some videos from an Australian chap called Will Taylor, I think his name was.
[55:33] Jon Seager
I'll send you the link.
[55:34] Jon Seager
And that's like a nice little YouTube series that goes from kind of installing Nixos the kind of most primitive way right through to managing your system with a flake.
[55:43] Jon Seager
And that's how I started and then I just slowly kind of iterated.
[55:46] Jon Seager
And the nice thing is most like a huge number of people are sharing their configs on GitHub.
[55:51] Jon Seager
Mine is completely public.
[55:52] Jon Seager
I'll put a link to that too.
[55:53] Jon Seager
You can see it, right?
[55:54] Jon Seager
So you can kind of.
[55:55] Jon Seager
I spent a long time just kind of looking around at other people's flights going, oh, that's interesting.
[55:59] Jon Seager
Haven't seen that before.
[56:00] Jon Seager
Like oh, I'm going to steal that.
[56:03] Viktor Petersson
You know I'm very compelled into throwing up my proxmox Home Lab server in favor of.
[56:13] Viktor Petersson
Of this.
[56:14] Viktor Petersson
But yeah, it, yeah, I don't think it's something that should be taken lightly.
[56:18] Jon Seager
Like built in modules for managing systemd unspawn containers and managing VMs and like you can have all of that stuff just in a nix config checked into git somewhere and it'll just happen.
[56:28] Jon Seager
Yeah, we should also talk one day about LEXD UI as a Proxmox alternative.
[56:33] Jon Seager
That's super interesting.
[56:34] Viktor Petersson
Absolutely.
[56:34] Viktor Petersson
I think we need to do a follow up session about some other fun things we've been noting about in person over the last year or two and then we can yeah, pick that up in a future show.
[56:46] Viktor Petersson
But this been super helpful John, I much appreciate you coming on the show and I hope everybody on the.
[56:52] Viktor Petersson
On listening to this I found this as interesting as I have found.
[56:56] Viktor Petersson
So thank you so much John and have a day.
[56:59] Viktor Petersson
Cheers.
[57:00] Viktor Petersson
Bye.

Found an error or typo? File PR against this file or the transcript.