WEBVTT

00:00.540 --> 00:01.540
All right, cool.

00:02.080 --> 00:02.740
All right.

00:03.180 --> 00:03.980
Hello, guys.

00:03.980 --> 00:04.700
I'm Alex.

00:04.700 --> 00:08.220
This is my first year at DEF CON and also my first time talking about Nix.

00:08.220 --> 00:09.200
So I'm a little nervous.

00:09.200 --> 00:11.280
If I stumble a little bit, bear with me.

00:11.640 --> 00:15.500
And my talk is Zero to Infra in 100 Days, a Nix Speedrun.

00:15.720 --> 00:20.040
And I'm going to start with a little story about how I got into it and then kind of go through this crash course.

00:20.040 --> 00:22.820
And it's funny, because Farid is actually the one that got me into it.

00:22.820 --> 00:25.400
I met him at his younger brother's wedding.

00:25.400 --> 00:27.040
Omar, he's one of my best friends.

00:27.480 --> 00:31.760
And he said, you should come with me to play Nix at scale 22.

00:31.980 --> 00:33.840
And I was like, I don't know what that is.

00:33.840 --> 00:35.240
But I like Linux, and I'm a nerd.

00:35.240 --> 00:36.880
And I have all my home lab stuff.

00:36.880 --> 00:38.640
So I'll just go and try it.

00:38.900 --> 00:40.680
And I was there.

00:40.680 --> 00:43.840
I set up a laptop in four days trying to learn Nix.

00:43.840 --> 00:46.080
Looking back, I didn't really have it.

00:46.120 --> 00:49.280
But I met a bunch of really smart people, and I learned a ton of stuff.

00:49.280 --> 00:50.380
And it was really awesome.

00:50.380 --> 00:52.240
And I'm just super Nix-billed now.

00:52.240 --> 00:54.560
So I'm going to try to get you to be the same way, maybe.

00:56.720 --> 00:59.460
So I'm going to get into it.

00:59.480 --> 01:05.240
My talk is pretty similar to Farid's in terms of like the beginner level.

01:05.240 --> 01:07.260
Mine's going to also kind of be a crash course.

01:07.260 --> 01:10.000
But I'm going to say mine's going to be even less academic.

01:10.000 --> 01:18.200
I'm going to try to give you what you need to know to get started as soon as possible without knowing all the theory behind it.

01:18.800 --> 01:23.040
And you can kind of pick that up as you go once you see the power and you start using it.

01:24.440 --> 01:29.760
So in most of these talks, people are always going to open with like what is Nix?

01:29.760 --> 01:32.400
And I think that that is not the right question.

01:32.400 --> 01:37.800
I think why Nix and showing what it is and how it works for you is more powerful.

01:37.800 --> 01:44.220
Because when people open with these talks, they'll say Nix is a package manager, a language, and an operating system.

01:44.220 --> 01:46.640
And when you say that, it just turns everyone off immediately.

01:47.540 --> 01:49.160
That's three different things.

01:49.160 --> 01:54.580
That's like saying C, Ubuntu, and APT.

01:54.780 --> 01:56.580
That's like what the hell?

01:57.400 --> 02:00.280
But with Nix, why Nix?

02:00.280 --> 02:04.640
It simplifies what you can get out of everything.

02:04.640 --> 02:09.960
So in a traditional sense, I'm going to use like kitchen recipes analogies a lot.

02:09.960 --> 02:12.060
At Planet Nix, somebody made that analogy and I really liked it.

02:12.060 --> 02:13.280
It clicked for me a lot.

02:13.280 --> 02:20.340
So the traditional is like if I'm making a tomato sauce, the traditional way would be like I got to add tomatoes and that's all I'm going to say.

02:20.360 --> 02:26.320
But the Nix sauce is going to say I'm going to add tomatoes from this farm at this acidity, stored at this ripeness level.

02:26.320 --> 02:32.080
And it's going to give you the precise same outputs every time because you are going to give it the same inputs every time.

02:33.940 --> 02:40.300
And actually, I guess, so I also made myself like a little cheat sheet here so I don't mess up, run any commands and stuff.

02:40.300 --> 02:46.380
And my talk is just going to, I'm going to run a lot of stuff live and just show you rather than talking about it.

02:46.560 --> 02:51.340
So just to show you some of the really cool stuff that Nix can do to kind of get you hooked, I'm going to talk about like Nix shell.

02:51.540 --> 03:01.780
So what I'm going to do is something that probably isn't normally allowed where I'm going to make an environment with Python 2 and 3 at the same time.

03:01.780 --> 03:04.020
And when I run this, it's actually going to throw a fit.

03:04.040 --> 03:06.180
And that's good because it's actually Nix protecting us.

03:06.180 --> 03:11.780
It's saying, you know, Python 2 isn't actually marked as like secure anymore.

03:11.920 --> 03:15.080
And we can just get by this by allowing to run insecure.

03:17.880 --> 03:19.880
But what it's going to do is it's going to put me into a shell.

03:19.880 --> 03:21.760
So this is like my own little environment.

03:21.920 --> 03:27.000
And Free talked about this a little bit where it's just referencing store paths.

03:27.000 --> 03:28.300
And I'll talk more about that in a second.

03:28.300 --> 03:32.920
But it's just making path variables for your shell.

03:32.920 --> 03:39.890
So I can run and you can see like I have Python 2.7.

03:39.890 --> 03:45.090
And I can also do the same command for Python 3.

03:45.090 --> 03:46.430
I have 2 and 3 in the same shell.

03:46.430 --> 03:47.790
I can use either one if I want.

03:49.330 --> 03:50.890
So that's pretty cool.

03:54.780 --> 03:56.840
And then a couple more.

03:56.840 --> 04:02.060
You can run things that are packaged by others and put up without actually having it on your system.

04:02.060 --> 04:02.840
And this is super useful.

04:02.840 --> 04:06.200
I use this all the time through a different command like comma.

04:06.420 --> 04:11.200
So just as an example of that, I don't have this.

04:14.540 --> 04:15.260
Yeah.

04:15.400 --> 04:17.860
It's like a little like 2E terminal game.

04:17.980 --> 04:19.140
2048 in terminal.

04:19.140 --> 04:19.840
I don't have it.

04:19.840 --> 04:21.620
But I can just run it.

04:21.620 --> 04:22.500
I can nix run.

04:22.500 --> 04:25.820
And what it's going to do is it's going to grab it from the magic world.

04:25.820 --> 04:28.140
And it's going to just run it on my machine.

04:28.140 --> 04:29.160
I don't have it on my machine.

04:29.160 --> 04:30.840
But now I have it on my machine.

04:30.840 --> 04:32.900
And now I'm playing this game.

04:34.000 --> 04:37.700
So that's kind of like why use Nix.

04:37.700 --> 04:42.680
So those are a couple examples of what it is, how you can use it, why you should care a little bit.

04:42.860 --> 04:45.300
And now this is the whole funny thing.

04:45.300 --> 04:48.440
Why does Nix seem to have such an infamous learning curve?

04:48.440 --> 04:54.560
This is the graph that I found on one of the most popular discourse pages for this is one of the best lectures about Nix.

04:54.560 --> 04:58.480
And it was a 30-minute dense lecture about using the language.

04:58.860 --> 05:01.840
And that one of the people commented this on it.

05:01.840 --> 05:02.720
And I think that makes sense.

05:02.720 --> 05:07.260
It's like the learning curve is infamously super steep and treacherous.

05:07.260 --> 05:09.040
And I don't think it has to be that way.

05:09.040 --> 05:13.460
I don't think you actually need to learn all the theory right now.

05:13.460 --> 05:18.260
I think all you need to know is just a couple commands I'll show you and the environment.

05:18.260 --> 05:21.420
So Nix run, Nix develop, and how do you encode the people shit.

05:21.420 --> 05:22.440
That's all you need to know.

05:22.640 --> 05:25.100
You can be productive today using it.

05:25.100 --> 05:27.620
You don't need to know like you can say that's a car.

05:27.620 --> 05:30.340
You don't need to know about how to put the engine together inside of it yet.

05:30.340 --> 05:32.980
You'll probably be interested and want to learn about that later.

05:33.080 --> 05:39.560
I will get into some of the inner workings because I think it's important for you to have a baseline understanding of how it works.

05:39.560 --> 05:44.280
So you're not just looking in this magical wizard orb and not knowing how the magic works.

05:44.280 --> 05:48.980
But as a general guideline for all of it, don't fight immutability.

05:48.980 --> 05:56.360
That this was the biggest rule for me to like start using Nix without fighting myself on it.

05:56.360 --> 06:03.280
So one of the first mistakes I made was I needed to make an alias in my shell.

06:03.280 --> 06:05.660
And I set my shell up with Nix.

06:05.660 --> 06:09.140
So I build it and it gets put on my machine in the state that it is.

06:09.140 --> 06:14.680
And I went into my ZSHRC and I added the alias and it worked for a while.

06:14.680 --> 06:16.180
But the next time I rebuilt, it was gone.

06:16.180 --> 06:18.320
Because it rebuilds it every time.

06:18.320 --> 06:24.720
So you're not thinking of, you're not opening settings menus and trying to find the setting and setting it there.

06:24.720 --> 06:27.180
You're gonna go into the configuration file for it.

06:27.180 --> 06:32.340
You're gonna set the option there and just rebuild to a state where that is the state of things.

06:32.480 --> 06:38.940
You'll avoid most of the roadblocks, I think, to just getting started immediately with a Nix system just by following this rule.

06:38.940 --> 06:40.020
Just don't fight immutability.

06:40.020 --> 06:43.320
Keep in mind, like, I'm not following steps.

06:43.320 --> 06:50.460
And this gets into the whole notion of imperative versus declarative, which I'm gonna get into like what the heck does that even mean?

06:50.640 --> 07:00.200
But like manually going and doing a setting would be something that's imperative and just doing it in your configuration and then rebuilding, that's gonna be declarative.

07:00.640 --> 07:03.920
So declarative versus imperative, like, what the heck does this even mean?

07:03.920 --> 07:07.700
So this is like the Wikipedia definition for it.

07:08.200 --> 07:11.500
I'm not gonna read it because this is like my crash course talk.

07:11.500 --> 07:12.680
Like, who cares?

07:12.740 --> 07:14.120
This is my analogy.

07:14.720 --> 07:16.860
For imperative, I want a sandwich.

07:17.140 --> 07:18.320
Do I order it?

07:18.320 --> 07:19.060
Do I make it?

07:19.060 --> 07:21.540
I need to do XYZ to get my sandwich somehow.

07:21.540 --> 07:22.400
Okay, I'm gonna make it.

07:22.400 --> 07:25.900
I'm gonna, like, I'm gonna get the bread, I'm gonna put the meat on it, mustard, mayo, blah, blah, blah.

07:25.900 --> 07:28.440
I did all these things and now I've got my sandwich.

07:29.020 --> 07:34.440
So in a declarative approach, all I do is I want a sandwich, I declare I have a sandwich.

07:34.440 --> 07:36.160
And now I just have a sandwich.

07:36.380 --> 07:40.300
All the stuff to get to the sandwich, I don't care about.

07:40.380 --> 07:42.180
That can be, Nix can do that for me.

07:42.180 --> 07:43.980
Nix can be my sandwich guy.

07:44.240 --> 07:45.780
But me, I have the sandwich.

07:45.780 --> 07:47.120
I declare I have it, so now I have it.

07:47.120 --> 07:48.420
That's my analogy.

07:48.420 --> 07:51.440
And this is like the whole food thing I'm gonna keep going into more.

07:53.780 --> 07:54.420
Yeah.

07:54.900 --> 07:58.320
So this is like an example of setting up a web server imperatively.

07:58.320 --> 08:00.380
You gotta run a crap load of commands.

08:00.840 --> 08:10.140
You're running curl commands, you're adding PPAs, you gotta add systemd services, you gotta add a user for it, you're running all these commands one at a time, one after the other.

08:10.180 --> 08:16.340
If one of those links is broken, like, stuff's busted, and then by the end of it, like, what did you even install?

08:17.140 --> 08:18.740
Like, can you do this again?

08:18.740 --> 08:22.260
Like, you can make a script, but what if something else is broken?

08:22.380 --> 08:24.980
And this is like my, this is the point of it.

08:25.460 --> 08:28.160
Do you even know all the stuff on your system, on your computer?

08:28.160 --> 08:30.780
Do you actually know all the stuff installed on your computer right now?

08:30.780 --> 08:31.740
I bet you don't.

08:31.740 --> 08:34.460
Like, unless you use Nix, then you do.

08:34.460 --> 08:39.960
But, like, you just, like, it's following, like, a medium article to set something up.

08:39.960 --> 08:43.640
You copy a link, and you run some curl command, and it puts something on your computer.

08:43.640 --> 08:45.180
Two months later, you don't even remember doing that.

08:45.180 --> 08:46.280
It's on there somewhere.

08:46.280 --> 08:49.440
Maybe you're, like, refreshing your repository, but you have no idea.

08:49.540 --> 09:02.620
The declarative approach to this, this is the same thing set up, but with Nix, and I'm going to break this down a little bit in a second, but you're declaring each service, and this is going to give you the same results every time, no matter what.

09:02.720 --> 09:11.760
And we're doing everything from setting up the services, like Nginx, PostgreSQL, and the systemd service, and even setting up the user to run this.

09:11.760 --> 09:15.440
And so, when I look at this, this can be kind of, like, intimidating to look at at first.

09:15.440 --> 09:19.700
It kind of, there's a lot of brackets, and this is how I look at it.

09:19.700 --> 09:20.540
I break it down.

09:20.540 --> 09:21.480
I do my scribble.

09:21.600 --> 09:33.020
Just look for the, like, top-level attributes, the curlies, and when you actually look inside each of them as, like, a chunk, it actually makes it a lot easier to understand what's even going on.

09:33.020 --> 09:34.780
So, like, just look at the first one.

09:34.980 --> 09:36.520
It's a service, Nginx.

09:36.520 --> 09:39.920
We're enabling it, and then we're just doing settings for that specifically.

09:39.920 --> 09:40.840
Same thing for the other ones.

09:40.840 --> 09:45.980
The systemd one, that's the same syntax you're writing to, like, write your own systemd service.

09:45.980 --> 09:48.880
You're just doing it through Nginx, and it's going to end up on your system after you rebuild it.

09:48.880 --> 09:50.080
Even the same thing with the user.

09:50.080 --> 09:52.600
I'm making a user called MyApp.

09:55.460 --> 10:08.380
So, DevShells and Durand are your gateway drug into getting into Nginx, and if you take nothing else away from this talk, it's just start using DevShells to do development of whatever you're working on.

10:08.380 --> 10:14.140
It makes stuff super easy, and it makes collaborating with other people really, really easy, too.

10:14.420 --> 10:19.160
Your directory becomes your full custom environment.

10:20.380 --> 10:28.060
So, just to show this, I, like, and this is all the stuff you need to do a Durand and DevShell.

10:28.060 --> 10:39.820
You need the envrc, which is for Durand, and flakes, which I'll get into a little bit later, but just as a top level, that's just the thing packaged reproducibly monolith.

10:39.820 --> 10:55.920
So, just to show this, I did a web server in Rust, super simple, and I'm going to show, like, this is the flake, the whole thing, and, like, this kind of ties into yoinking other people's stuff.

10:55.920 --> 11:10.220
You can yoink this and replace it with the stuff you need for your project, but all I'm doing is I need Rusty, I need cargo, I need Rust analyzer, and I'm spitting this stuff out when I enter it, and I have the inputs, and you'll see, like, once I enter the shell,

11:10.220 --> 11:11.100
you see all this stuff.

11:11.100 --> 11:15.420
Like, I loaded it, I loaded the flake, and then it spits that stuff out that was inside the flake.

11:16.240 --> 11:20.580
So, if I exit now, if I go out of this, you see it says unloading.

11:20.580 --> 11:22.600
If I run Rust C, I don't have it.

11:22.600 --> 11:23.680
It's not on my system.

11:23.680 --> 11:29.600
But as soon as I just enter that DevShell, I have Rust C now, magically.

11:29.880 --> 11:32.740
I'm inside of this new environment.

11:32.780 --> 11:36.440
And the same thing, I can just do cargo run.

11:36.440 --> 11:41.300
All my stuff was together, and now I just, like, I have this little private web page below from Nix.

11:41.300 --> 11:42.220
It just works.

11:42.220 --> 11:43.940
I have it on the DevShell.

11:43.940 --> 11:50.780
And for a lot of the projects I've been working on, I've repackaged them to use DevShells, and it makes sharing the setup super easy.

11:50.780 --> 12:03.040
Like, if you're trying to collaborate on something with someone, they can clone your project, and then they just enter the DevShell, as long as they have Nix on their system, and they have the exact same environment that you have for working on something.

12:03.040 --> 12:10.080
It makes it really easy to, like, have the same stuff on all the machines for your whole team, all working on the same stuff.

12:15.760 --> 12:16.600
Okay.

12:16.600 --> 12:21.700
So now is my slightly dense part of this, like, lecture part.

12:21.700 --> 12:23.300
This is my speedrun lecture.

12:24.000 --> 12:25.580
How does the stuff actually work?

12:25.580 --> 12:34.200
I think it's important for you to have some base knowledge of what's going on under the hood, so it doesn't all seem like some mystical orb that you're pondering.

12:34.200 --> 12:35.180
You're like a wizard.

12:35.360 --> 12:47.540
So I think all you really need to know to get jump-started and feel not confused by what you're doing every day is derivations, what's the store, what is Nix packages, and what are flakes.

12:47.540 --> 12:53.160
And I'm going to go through, like, a blitz explanation of all these, and I'm going to give some examples as I go.

12:53.400 --> 12:58.620
So basically, and this goes back to my food thing, derivations, how stuff gets built.

12:58.620 --> 13:01.080
A derivation is a recipe to do something.

13:01.080 --> 13:03.940
For example, let's do the GNU hello program.

13:03.940 --> 13:05.720
All it does is just print out hello world.

13:05.980 --> 13:10.960
And this is basically, this is the stuff that's inside of that derivation.

13:10.960 --> 13:16.840
It's going to say, I need this hello tar.gz source code stuff, I need GCC, and I need make.

13:16.840 --> 13:18.460
And these are the recipe inputs.

13:18.500 --> 13:24.120
And if I do this, if I put all these together, I'm going to get this same output every time.

13:25.020 --> 13:28.020
And just to show this,

13:36.880 --> 13:40.020
this is what a derivation actually looks like.

13:40.100 --> 13:45.940
We showed this a little bit earlier, but so you don't actually need to read too far into it.

13:45.940 --> 13:47.280
It looks like JSON.

13:47.280 --> 13:48.120
It is JSON.

13:48.120 --> 13:57.580
And you can see it's spitting out that hash stuff and the output where it's going to end up on the machine.

13:57.940 --> 13:59.480
But this is what's inside of it.

13:59.480 --> 14:00.080
It's not scary.

14:00.080 --> 14:00.960
It's just JSON.

14:00.960 --> 14:03.180
It's showing all the inputs.

14:03.180 --> 14:06.320
You can see this is the, these are the inputs.

14:06.320 --> 14:07.640
This is how it's being built.

14:07.640 --> 14:08.920
These are all the flags.

14:08.920 --> 14:11.620
You see CMake flags for make stuff.

14:11.660 --> 14:12.660
That's how it is.

14:22.820 --> 14:35.720
And just to show a little bit more about this hash thing at the bottom, just so you know what this is, that's basically the result of all the inputs and the derivation getting spit out somewhere.

14:35.720 --> 14:38.820
And that will tell you that it's the same thing every time based on the inputs.

14:38.820 --> 14:45.840
That's how we make sure that all the stuff that we're putting in is the exact same every time so that we get that reproducibility.

14:45.860 --> 14:52.100
And so just to show this, if we do that same thing, make note of the hash thing.

14:52.100 --> 15:02.220
If I do this command, all I'm doing here is I'm going to show this derivation again, but I'm just going to add a random variable to it just called my var equals demo.

15:02.220 --> 15:03.180
It doesn't do anything.

15:03.180 --> 15:04.120
It doesn't change anything.

15:04.120 --> 15:09.960
But the fact that I added it and the fact that it's there in the inputs, it changes the output.

15:09.960 --> 15:11.180
It changes the hash.

15:11.180 --> 15:13.380
We can see it in the inputs here.

15:13.820 --> 15:14.540
It's here.

15:14.540 --> 15:15.520
It doesn't do anything.

15:15.620 --> 15:21.420
But the end result, this GJI, whatever, and then down here, it's different.

15:21.420 --> 15:25.400
The end result is different because of what we put in, even though it's not actually doing anything.

15:25.400 --> 15:29.300
And Nix is very picky about everything that you put in.

15:29.300 --> 15:34.680
And that guarantees that even if you change a comment, the entire thing is going to be different in the end.

15:35.760 --> 15:48.720
And just to show what is this hash, where does it come from, I have this file, file.txt.

15:49.120 --> 15:50.360
This is a test file.

15:50.360 --> 15:53.120
Capital T exclamation point, just make note of that.

15:53.600 --> 15:59.820
If I do Nix hash file, file.txt, it's going to give me the hash for the file of the stuff in it.

15:59.820 --> 16:08.960
If I go back into that file and I change something, I'm just going to like, there, just one thing.

16:09.040 --> 16:15.300
If I run that same thing, my hash is different because I changed the contents of the file.

16:15.300 --> 16:16.640
So that's all that a hash is.

16:16.640 --> 16:19.460
It's just making sure that your inputs are the same.

16:21.140 --> 16:23.340
So next is the Nix store.

16:23.340 --> 16:25.580
This is where everything lives.

16:25.580 --> 16:28.420
This is like the pantry in your house for all the stuff.

16:28.800 --> 16:31.420
This is like an excerpt of what all the stuff looks like in the Nix store.

16:31.420 --> 16:36.860
I highlighted all the hashes so you can kind of separate out what the thing is and then the hash.

16:37.520 --> 16:42.860
And the binary cache, I think that's something important to know about as well.

16:42.900 --> 16:44.920
You can think of that as precooked meals.

16:45.720 --> 16:53.280
And when I go to, I think I have this, yeah, I'm going to get into it here as well.

16:53.280 --> 17:03.000
But when I go to grab something, I'm going to grab, I'm going to get the derivation from somewhere, which I'll talk about in a second.

17:03.000 --> 17:04.200
And I'm storing that.

17:04.200 --> 17:06.660
And final binary, all that's being put into the store.

17:06.840 --> 17:14.680
And when I go to actually decide whether or not I need to build something from the derivation, you can actually skip that whole step.

17:14.680 --> 17:19.120
Because if we know the hash is the exact same, we know all the inputs are the same.

17:19.120 --> 17:21.620
So we know the result is going to be what we want.

17:21.620 --> 17:30.280
So if somebody else already built that for us and they put it somewhere that we can grab easily, why would we do the whole process of rebuilding it all ourselves?

17:30.380 --> 17:31.980
So that's all a binary cache.

17:31.980 --> 17:33.340
It's just precooked meals for you to fetch.

17:33.340 --> 17:35.260
No need to manually rebuild stuff.

17:35.540 --> 17:39.020
So this slide is like my densest one.

17:39.020 --> 17:41.260
I was thinking about what the best way to explain this is.

17:41.260 --> 17:46.320
But Nix packages, you can think of as where all these recipes come from.

17:46.320 --> 17:48.800
It's the biggest, fattest cookbook.

17:48.920 --> 17:57.080
And this search.nixos.org, you can go here, you can do a search for any Nix package you could probably possibly think of, and it's probably there.

17:57.080 --> 17:58.620
Somebody's probably packaged it and put it there.

17:58.620 --> 18:00.340
It is absolutely huge.

18:00.420 --> 18:02.240
And it's like all the secret sauce.

18:02.240 --> 18:05.740
It has so many recipe generators.

18:06.540 --> 18:10.080
Before, I had this slide saying recipes themselves.

18:10.080 --> 18:14.300
But I think saying that is a little bit too much of an oversimplification.

18:15.000 --> 18:23.580
So here's the flow of what happens when we're run that command to run the hello program or the one where I did 2048.

18:24.360 --> 18:29.220
When you run it, Nix is going to look up hello in Nix packages, which is your big cookbook.

18:29.220 --> 18:33.000
It's going to look in the cookbook for the hello.

18:33.260 --> 18:35.640
And the cookbook has a recipe generator.

18:35.640 --> 18:38.160
You can think of this as like a template for the recipe.

18:38.340 --> 18:40.320
And it's not the recipe itself.

18:40.320 --> 18:45.420
So your machine's going to get the recipe from the cookbook on its own.

18:45.720 --> 18:52.460
Nix is going to run the recipe generator to get the actual recipe, the derivation for your system.

18:52.640 --> 18:55.380
And then it's going to ask the binary cache, yo, do you have this thing?

18:55.380 --> 18:58.560
And if you have it, sweet, I don't have to build it myself.

18:58.560 --> 18:59.660
Yoink, I'm going to grab it.

18:59.660 --> 19:02.040
And if not, I'm going to build it myself.

19:02.360 --> 19:07.300
And this process of building it yourself, like let's say for this hello, it didn't have it.

19:07.300 --> 19:19.860
Let's say I needed GCC to do it, it's going to turtle all the way down recursively and go all the way down to the bootstrap layer if it has to, if it can't find stuff in the binary cache.

19:20.000 --> 19:28.220
Which is really cool, because that means you can build up anything from the lowest level possible, which would take forever, but you could.

19:28.220 --> 19:30.780
You don't need external sources to build.

19:30.780 --> 19:39.480
All you need is the very bare minimum, like POSIX shell and bash and C compiler, stuff like that, super minimal.

19:40.080 --> 19:43.220
And at the end, it puts all this stuff in the store.

19:43.260 --> 19:51.060
And it puts both the recipe, the derivation, and the final binary in the store.

19:51.060 --> 19:52.760
It puts both of those in the store together.

19:52.960 --> 19:55.460
Not under the same hash, they're separate.

19:56.620 --> 19:58.520
So yeah.

19:58.520 --> 19:59.940
So that's Nix packages.

19:59.940 --> 20:04.820
So just to recap derivations or recipes, the Nix store is your pantry.

20:05.040 --> 20:06.820
Nix packages is the biggest, fattest cookbook.

20:06.820 --> 20:13.660
And I went on a side tangent about these recipe generator things, just to not confuse you later if you look into it more.

20:14.020 --> 20:16.780
And this is just a graph that shows all the...

20:16.780 --> 20:21.420
it might be kind of hard to see, but it shows all the repositories.

20:21.620 --> 20:26.420
And you can see that Nix packages unstable is just completely in a league of its own, all the way up at the top.

20:26.420 --> 20:29.560
The AUR is a little bit underneath it.

20:29.760 --> 20:34.120
But those different versions get into what we're going to talk about next for Nix packages.

20:34.320 --> 20:35.480
So Flakes.

20:35.480 --> 20:37.740
Flakes is the reproducibility solution.

20:37.980 --> 20:41.760
Explaining Flakes can be pretty difficult, but just use Flakes, bro.

20:41.760 --> 20:42.180
Trust me.

20:42.180 --> 20:42.800
Just trust me, bro.

20:42.800 --> 20:44.080
All the cool kids use Flakes.

20:45.560 --> 20:50.360
In order to explain Flakes, I'm going to talk about channels really quickly.

20:50.360 --> 20:54.720
And I think you need to know about that to understand what Flakes is doing and why you should care.

20:54.720 --> 21:02.880
So earlier when I gave you this example for building the hello binary, I showed you these are the inputs, and I lied to you.

21:02.880 --> 21:03.700
I'm sorry.

21:03.700 --> 21:09.460
There's actually a hidden input, and it's the Nix packages version that you're grabbing the stuff from.

21:09.460 --> 21:15.160
And that actually changes the output because the inputs are different.

21:15.560 --> 21:24.740
So just to show this, I'm going to run evaluate, which is just going to do the... it's going to tell me what I'm going to get.

21:24.740 --> 21:25.860
It's not going to do the build for me.

21:25.860 --> 21:27.300
It's going to tell me what the result would be.

21:27.940 --> 21:31.020
And you're going to see I have this hash here.

21:31.100 --> 21:34.240
Really only look at the last couple of characters just to pay attention.

21:34.520 --> 21:41.800
And I'm going to do the same thing, but this time I'm going to specify I want it from Nix packages version 2505.

21:42.300 --> 21:45.520
And I think my system right now is on 2511 or unstable.

21:45.640 --> 21:49.400
But you'll see if I run it, my hash is different.

21:49.400 --> 21:50.020
And why?

21:50.020 --> 21:54.820
It's actually a different version of this hello program.

21:54.820 --> 21:58.800
So if I run this, just to show, this one's 2.12.2.

21:58.840 --> 22:01.540
If I run the same thing,

22:05.400 --> 22:07.240
this one's 2.12.1.

22:08.240 --> 22:10.840
I actually think I have a different version in that example.

22:11.240 --> 22:17.660
I can change this to 2505.

22:22.080 --> 22:23.720
2.12.1, same thing.

22:23.880 --> 22:25.660
But the versions are different.

22:25.660 --> 22:34.700
So on my system, the one that I have currently when I ran that evaluate, I got 2.12.2 and the hash was different versus what it is if I use some different version.

22:34.700 --> 22:37.920
So that gets back to the whole it's different.

22:37.920 --> 22:42.840
Running different versions of stuff for the same build will give you a different result.

22:42.840 --> 22:45.680
So this is kind of where Flakes comes in.

22:45.680 --> 22:50.300
And what it does is it's pinning of Nix packages.

22:50.540 --> 22:54.640
And this is like the reproducibility solution monolith all in one.

22:55.160 --> 23:00.340
So it goes back to the highest level of the same inputs are always going to give you the same outputs.

23:00.340 --> 23:02.520
And now it's the same inputs for real.

23:02.520 --> 23:07.420
It's using all the same Nix package source.

23:07.900 --> 23:10.820
And you can pin versions for specific packages.

23:10.940 --> 23:15.640
Once I run this, like this is just a super quick example of that hello in there.

23:15.640 --> 23:16.260
Super minimal.

23:16.260 --> 23:20.280
I'm just pinning it to version 2311 for Nix packages in this example.

23:20.680 --> 23:20.760
And

23:24.000 --> 23:28.100
it's going to generate me a lock file, which is how they version everything.

23:28.100 --> 23:30.800
And it's going to keep track of the version of all the packages.

23:30.800 --> 23:38.920
So that if I give you my repo or whatever, and you run it with the Flake in it, you're going to get the exact same output every time.

23:39.480 --> 23:44.360
Because the version, the Nix packages version for every package you're using is going to also be the same.

23:44.360 --> 23:46.520
There's no more invariability between our systems.

23:46.520 --> 23:50.440
What if what if your system is running 2511 and mine's 2505?

23:50.440 --> 23:51.480
Now we get a different result.

23:51.480 --> 23:53.480
This is not the reproducibility that we actually want.

23:54.540 --> 23:56.820
So this is like the highest level.

23:56.820 --> 23:58.500
Let's take this to the next level.

23:58.500 --> 24:01.620
This is all the previous stuff we talked about.

24:01.620 --> 24:06.680
But instead of configuring applications, packages, you're doing it for your system now.

24:07.000 --> 24:12.760
And this, you can do this for your bootloader, login manager, blah, blah, blah, all the stuff for your system, which is, it's pretty crazy.

24:12.760 --> 24:16.280
When you think about it, you can do your entire system configured declaratively.

24:16.280 --> 24:20.820
And you can just share your entire computer configuration with somebody else.

24:21.080 --> 24:23.900
And they can just have your whole setup, which is what I did earlier.

24:23.900 --> 24:28.580
I put, I put my laptop right here, my whole configuration onto my brother's laptop.

24:28.580 --> 24:29.960
I did that two days ago.

24:31.000 --> 24:34.500
And just to show this, I'm going to give a quick example.

24:36.880 --> 24:39.740
And all that I have here is just a flake.

24:39.980 --> 24:46.820
And it is using Astro's micro VMs, which is just a, I'm just going to boot up a micro VM to show you a NixOS system.

24:47.120 --> 24:51.520
And I'm sharing my Nix store with it so that the boot up time is really fast.

24:51.520 --> 24:52.180
But this is the whole flake.

24:52.180 --> 24:52.720
It's really simple.

24:52.720 --> 24:55.400
All I'm doing is I'm pulling in Nix packages.

24:55.400 --> 24:56.440
I'm using unstable.

24:56.720 --> 24:59.540
And I'm using micro VM, which is the thing I just told you about.

24:59.540 --> 25:01.500
And this is the configuration for it.

25:01.500 --> 25:06.120
The stuff that you care about is this, this configuration.nix file that I made to make it easier to follow.

25:06.120 --> 25:07.160
This is what it looks like.

25:07.160 --> 25:09.560
I'm setting up my host name for my system.

25:09.560 --> 25:11.480
I'm making a user, demo user.

25:11.500 --> 25:14.260
I'm giving him a password, a description.

25:14.420 --> 25:17.100
He's a normal user and I'm giving him wheel group so he can run sudo.

25:17.340 --> 25:21.600
And he's got these packages for the system.

25:21.600 --> 25:24.420
He's got the whole system that has Vim on it.

25:24.420 --> 25:29.120
And it's going to auto log in for my demo user and I'm hitting the system state version.

25:29.640 --> 25:37.660
So if I just run this, you're going to see it's going to boot up a micro VM.

25:41.040 --> 25:45.060
And it's going to put that stuff from the configuration on this machine.

25:45.060 --> 25:48.140
And you'll see we're going to be logged in as demo user in a second.

25:48.140 --> 25:52.100
And we'll see we have the Vim package on here.

25:52.620 --> 25:53.600
So we're logged in.

25:53.600 --> 25:54.240
Cool.

25:54.760 --> 25:55.740
Who am I?

25:56.960 --> 25:57.860
User's wheel.

25:57.860 --> 25:58.440
Cool.

25:58.660 --> 26:00.000
Vim, do I have it?

26:00.000 --> 26:01.380
I do have it.

26:01.400 --> 26:04.800
And then can I run sudo?

26:04.800 --> 26:06.020
Power off.

26:06.880 --> 26:08.100
Password was demo.

26:08.240 --> 26:09.700
Yeah, I can shut it down.

26:09.840 --> 26:19.550
Just to show this like super quick, what I'm just going to do is I'm going to add htop to the packages that are going to go on the system.

26:19.710 --> 26:20.970
And I'm going to build it again.

26:20.970 --> 26:26.710
And you're going to see that this time I'm going to have, I probably should have shown that I didn't have htop on it before, but trust me, I didn't.

26:29.650 --> 26:33.390
I'm running again and you'll see that we have that package on the machine now.

26:36.150 --> 26:44.010
And this little micro VM is just a super simplification of a bigger NixOS system that has all the stuff on it.

26:44.010 --> 26:47.730
So like this system that I'm showing you this on right now has that.

26:50.470 --> 26:51.830
Cool, we have it.

26:51.830 --> 26:59.110
So yeah, that's, it's really powerful being able to use Nix for a whole system instead of just packages and configurations.

26:59.110 --> 27:04.910
And it lets you be really particular about everything that you have on that given system.

27:04.910 --> 27:10.390
And it lets you track it all super easily because like you can just go to that configuration file and see what's on the system.

27:10.390 --> 27:13.650
There's no ambiguity about what's installed on there or how things are configured.

27:15.050 --> 27:17.870
And just as a quick aside, generations.

27:17.950 --> 27:22.710
So I noticed somebody said a question about like versioning systems before.

27:23.070 --> 27:25.070
And I added that while I was listening.

27:25.250 --> 27:28.050
Generations are really cool for the system.

27:28.050 --> 27:40.810
If I were, if I had this on a traditional system and I like rebooted my right now, during my boot menu, I have the option to roll back or use a different generation or version of my NixOS configuration.

27:41.030 --> 27:50.570
So every time I make a change to my config and I rebuilt my system to it, it's going to add it as a new generation list.

27:50.670 --> 28:00.170
And it keeps a backlog of however many you can specify how many you want to keep, how many you want to like delete after a bad config.

28:00.170 --> 28:07.570
Like I do something dangerous, like I change variables for my boot loader, like I'm configuring it with Nix and I do something bad and I bork it.

28:07.650 --> 28:08.950
And now my system is broken.

28:08.950 --> 28:09.890
I don't even boot.

28:10.350 --> 28:10.970
It's fine.

28:10.970 --> 28:13.410
I'll just roll back the configuration and I'm saved.

28:13.410 --> 28:15.610
You don't have to worry about breaking your system anymore.

28:15.610 --> 28:23.330
You can go ham and do all the stupid things you want to do and not have to worry about doing the full fresh install all the way from scratch.

28:26.250 --> 28:27.850
So, yeah.

28:27.850 --> 28:28.350
Thanks.

28:28.350 --> 28:41.390
That was kind of like my super crash course about how I went from not really knowing anything about Nix just back in February to now I have all my machines configured declaratively.

28:41.390 --> 28:43.570
I get to hack on Nix for work.

28:44.990 --> 28:46.510
And, yeah.

28:46.510 --> 28:58.410
And I guess at this point, if I have it, I'm just going to kind of flex my repository that I have for my machines and I share it with Britton over there, so I'll show you.

29:02.920 --> 29:03.460
So, yeah.

29:03.460 --> 29:04.620
This is ours.

29:05.540 --> 29:15.500
And the way, without getting too much into it, just to show not everything for a system configuration has to be all condensed into one file, because most people don't actually do that, because it would end up being really huge.

29:15.500 --> 29:17.180
They split it out into multiple things.

29:17.180 --> 29:20.340
And just at the end, it all gets merged together back into the same place.

29:20.600 --> 29:35.320
But the way that I have things set up that I think is really cool for organizations is, and I'm only going to show this part, I think, the way that I have machines, users, and user environments configured across all my machines, all in one place.

29:35.320 --> 29:41.420
So, I have all these machines set up on my on our infrastructure.

29:41.420 --> 29:42.700
So, like, AlexDev is a machine.

29:42.980 --> 29:45.920
AlexFramework, that's this machine, this laptop that I'm using right now.

29:45.920 --> 29:50.480
And I put the name for it, the host, the target host for it.

29:50.480 --> 29:51.900
And this is using plan, by the way.

29:51.900 --> 29:53.200
I should have mentioned that.

29:54.260 --> 30:01.760
And I have this tag system set up so that I don't actually have all the configurations all in one big place, like I mentioned.

30:01.760 --> 30:09.700
It's actually kind of like a buffet example, where you go to this inventory and you pick out the things that you want for that machine.

30:09.700 --> 30:11.500
So, this is a laptop.

30:11.500 --> 30:12.980
I want to be on tail net.

30:13.080 --> 30:14.680
And this laptop has Hyperlend on it.

30:14.680 --> 30:15.600
That's what I want.

30:15.760 --> 30:22.760
And if I go and actually look at those tags, like the Hyperlend one, you can see, like, for this, this is the base stuff that I need to do Hyperlend.

30:22.760 --> 30:31.840
So, this, because I added this tag to that machine, this is getting pulled into and essentially added to, as far as that machine's concerned, this is part of its configuration.

30:32.260 --> 30:39.500
And the next step is, like, HomeManager, which is configuring dot files for yourself.

30:40.200 --> 30:54.800
So, like, for instance, I have... this is my ZSH RC set up with HomeManager, which is basically, HomeManager is Nix set up, but for your dot files to manage all of that declaratively as well.

30:54.800 --> 31:00.900
And the end result of this, so, I have all this stuff on here, just, I'll show you, like, we have all these aliases and stuff.

31:01.020 --> 31:08.940
And what I'll do is, like, this is the generated ZSH RC.

31:08.940 --> 31:11.100
This is, like, some robot generated RC.

31:11.100 --> 31:12.400
You probably wouldn't want to read this.

31:12.400 --> 31:14.680
Like, it's not meant to be super human readable.

31:14.680 --> 31:19.740
But you can see, like, it's taking all the stuff that I'm configuring here and it's putting it all in here.

31:19.740 --> 31:22.520
Like, all the aliases are here from everywhere.

31:22.940 --> 31:39.620
But, yeah, so, the end game, I guess, that I'm getting at with this is, you can be really modular with system configurations and you can manage all your machines from the same place and choose what you want to be on them with these, like, pre-built little,

31:39.620 --> 31:42.040
like, nuggets that you can make for it.

31:42.040 --> 31:50.200
And it makes spinning up new machines and managing machines and knowing the exact state of all your machines super easy.

31:51.160 --> 31:54.500
So, yeah, I think that's about it.

31:55.340 --> 31:56.520
Thanks, guys.

