1 00:00:00,000 --> 00:00:00,400 Okay. 2 00:00:00,400 --> 00:00:01,640 Can you guys hear me okay? 3 00:00:02,120 --> 00:00:02,780 All right. 4 00:00:02,780 --> 00:00:03,120 Great. 5 00:00:03,120 --> 00:00:03,740 Thanks. 6 00:00:04,980 --> 00:00:07,920 So this talk is also meant to be, if you want, interactive. 7 00:00:07,980 --> 00:00:10,500 So if you have a question, I'm happy to stop. 8 00:00:10,880 --> 00:00:13,320 It's definitely an introductory talk. 9 00:00:13,320 --> 00:00:15,660 So if something's confusing, put your hands up. 10 00:00:15,660 --> 00:00:20,160 And if I feel like I can't answer it now, I'll be like, let's answer it later. 11 00:00:20,400 --> 00:00:23,620 So welcome to the talk on learning Nix the fun way. 12 00:00:24,380 --> 00:00:26,760 First off, this talk can be found online. 13 00:00:26,920 --> 00:00:28,680 There's the URI. 14 00:00:29,580 --> 00:00:32,680 And this is a reprieve of a talk I gave at Planet Nix. 15 00:00:32,680 --> 00:00:35,920 So if you heard that talk, nothing's really changed. 16 00:00:36,300 --> 00:00:40,060 You know, my goal is to just spread Nix and some of the fun parts of it. 17 00:00:40,060 --> 00:00:44,020 A lot of it can feel overwhelming and academic. 18 00:00:45,080 --> 00:00:48,500 I welcome improvements, edits, and corrections. 19 00:00:49,100 --> 00:00:50,180 And yeah. 20 00:00:52,080 --> 00:00:52,760 Okay. 21 00:00:52,760 --> 00:00:55,560 So just really quick, let me introduce myself. 22 00:00:55,560 --> 00:00:56,340 I'm Fareed. 23 00:00:56,340 --> 00:00:58,100 I currently work at Confluent. 24 00:00:58,160 --> 00:01:00,600 They're like known for Apache Kafka. 25 00:01:00,700 --> 00:01:02,420 That's some software project. 26 00:01:02,420 --> 00:01:03,820 I don't work on that. 27 00:01:03,820 --> 00:01:06,800 I work on build systems and automation and developer productivity. 28 00:01:07,060 --> 00:01:09,820 I've been using Nix in a variety of capacities. 29 00:01:10,140 --> 00:01:15,480 For a while now, I've presented at a bunch of NixCons, North America, and Europe. 30 00:01:15,880 --> 00:01:23,040 And I had the pleasure of bringing Nix into Google through an acquisition at Looker. 31 00:01:23,140 --> 00:01:25,240 I'm very bullish on Nix. 32 00:01:25,240 --> 00:01:28,400 It's been a source of mostly joy. 33 00:01:28,400 --> 00:01:33,020 And I had the fortunate experience of leveraging it to complete a PhD. 34 00:01:33,020 --> 00:01:35,040 So this thing says nearly complete. 35 00:01:35,040 --> 00:01:37,920 I completed my PhD as of June. 36 00:01:37,980 --> 00:01:39,780 So yeah, I'm very happy about that. 37 00:01:44,700 --> 00:01:50,080 Okay, so that was like the alternate working title for this talk. 38 00:01:50,080 --> 00:01:53,200 And I want to share effectively why I love Nix. 39 00:01:53,200 --> 00:01:54,740 Love is a strong word. 40 00:01:54,800 --> 00:02:03,420 But Nix has brought me a lot of joy, simplification of my software life, and ultimately love. 41 00:02:03,720 --> 00:02:08,040 You know, sometimes though, it's felt like learning it can be challenging. 42 00:02:08,440 --> 00:02:12,540 And I find it's really important to find like the purpose of what I'm learning and why. 43 00:02:13,720 --> 00:02:16,840 So ultimately, like why I love Nix, and you should too. 44 00:02:20,860 --> 00:02:23,140 I've given a lot of talks about Nix. 45 00:02:23,180 --> 00:02:29,300 I've given talks to meetup groups, friends, plenty internally at the companies I've been a part of. 46 00:02:29,380 --> 00:02:37,460 And this is kind of a photo of in my mind, when I'm thinking about wanting to talk about Nix, talking to others. 47 00:02:37,460 --> 00:02:48,120 It's like a noble pursuit where I'm imparting knowledge to my apostles about like what they're missing out on, and they're gaining some infinite wisdom. 48 00:02:48,120 --> 00:02:51,740 And it's somewhat academic, the whole thing. 49 00:02:53,820 --> 00:03:00,540 I tend to always begin these talks, covering that, like Nix as an idea started from a PhD thesis. 50 00:03:00,660 --> 00:03:04,540 And for some reason, I can't not mention the PhD thesis. 51 00:03:04,540 --> 00:03:09,860 I think it's like a law when you do a Nix con talk, or Nix talk, sorry, rather. 52 00:03:10,780 --> 00:03:14,480 And the PhD was the purely functional software deployment model. 53 00:03:14,540 --> 00:03:16,780 And it was in 2006. 54 00:03:18,000 --> 00:03:25,560 In retrospect, when you start off with a thesis for a talk, this slide better depicts how the talks have gone. 55 00:03:25,560 --> 00:03:30,920 People in attendance are totally bored by the nuance and complexity of what I'm talking about. 56 00:03:33,140 --> 00:03:45,880 At worst, I've immediately turned off potential Nix, new Nix enthusiasts by immediately jumping in to like an academic and incredibly verbose vocabulary about the ideas and technologies about Nix. 57 00:03:45,940 --> 00:03:48,220 And I've just lost a willing convert. 58 00:03:52,020 --> 00:03:55,180 Okay, so the motivation of this talk is like, I want to do it different. 59 00:03:58,520 --> 00:04:00,540 Let's learn Nix the fun way. 60 00:04:00,580 --> 00:04:03,360 You should be sold why Nix, what's fun about it? 61 00:04:03,360 --> 00:04:04,880 Why do you want to use it? 62 00:04:05,320 --> 00:04:10,100 You know , it's going to be a little bit of a crash course, but you should come away with like, wow, there's some benefits here. 63 00:04:10,100 --> 00:04:11,700 And it's fun to use. 64 00:04:11,860 --> 00:04:17,020 I want to impart the benefits of using Nix by what I believe to be learning Nix the fun way. 65 00:04:21,300 --> 00:04:22,800 Okay, let's begin. 66 00:04:22,800 --> 00:04:26,640 So there's gonna be some code samples, I apologize, can't get around it. 67 00:04:26,640 --> 00:04:27,780 It's a code thing. 68 00:04:28,160 --> 00:04:30,340 Let's begin with something seemingly innocuous. 69 00:04:30,340 --> 00:04:33,460 This is a script to determine the IP of my current machine. 70 00:04:33,680 --> 00:04:35,320 Looks pretty standard. 71 00:04:35,360 --> 00:04:41,060 I'm hoping most of the people here are probably reminiscent of a lot of scripts that might have looked like this or written themselves. 72 00:04:41,300 --> 00:04:43,360 And it stitches a few programs together. 73 00:04:43,360 --> 00:04:50,180 So we have bash, curl, jq is this tool, if you're not familiar with it, it processes JSON, and you can pull things out of it. 74 00:04:51,700 --> 00:04:58,240 So I run it, and I get the IP of my machine that I'm running from, or the gateway or whatever. 75 00:05:01,820 --> 00:05:06,820 Here's what rewriting that same script in the most raw form of Nix would look like. 76 00:05:06,820 --> 00:05:09,680 Oh, God, you're scared, you wouldn't write this. 77 00:05:09,840 --> 00:05:11,900 I know I just showed you a new language. 78 00:05:11,900 --> 00:05:14,160 But just ignore that for a second. 79 00:05:14,880 --> 00:05:20,720 The only takeaway is it looks like okay, if you squint, it's new, it's scary. 80 00:05:20,720 --> 00:05:24,720 But if you're programming, it should look like JSON. 81 00:05:24,900 --> 00:05:29,440 You know, it looks like other languages on the face of it. 82 00:05:29,440 --> 00:05:32,600 So there, it's not like totally out there. 83 00:05:34,980 --> 00:05:37,180 That's the important part of this recipe. 84 00:05:37,800 --> 00:05:41,200 Okay, there's like, it looks to like the script we wrote before. 85 00:05:41,200 --> 00:05:44,340 Okay, so there's like a direct mapping, I'm pretty happy here. 86 00:05:48,050 --> 00:05:50,890 But of course, that's not what you'd actually write in Nix. 87 00:05:51,050 --> 00:05:55,330 The following is a little bit more idiomatic, and a lot more terse. 88 00:05:55,730 --> 00:06:00,190 And right now we're getting a lot closer to the original script we'd written. 89 00:06:02,170 --> 00:06:06,950 So this is how you'd write that first script in Nix. 90 00:06:07,170 --> 00:06:11,070 And I'll show you like why you'd want to do that anyways. 91 00:06:11,130 --> 00:06:20,650 So for those that might want to follow along now or later, it's important to keep note of this commit value and that I'm building this on an AMD 64 Linux machine. 92 00:06:26,090 --> 00:06:32,570 Okay, so Nix, I wrote this like thing that I'm telling you you should do for this script. 93 00:06:32,870 --> 00:06:33,490 Why? 94 00:06:33,490 --> 00:06:35,010 Well, let's see, let's build it. 95 00:06:36,070 --> 00:06:38,510 Okay, you get some output. 96 00:06:39,110 --> 00:06:41,110 It has the name, what is my IP? 97 00:06:41,110 --> 00:06:42,430 Okay, that's cool. 98 00:06:43,930 --> 00:06:49,630 Inside of this path is a script, and it's that script we ended up creating. 99 00:06:51,790 --> 00:06:55,610 We can execute that script, and it works as we expect. 100 00:06:55,610 --> 00:06:57,050 That's the original IP. 101 00:06:57,050 --> 00:06:59,070 We're functionally identical so far. 102 00:06:59,070 --> 00:06:59,990 So far so good. 103 00:06:59,990 --> 00:07:01,830 I didn't lose functionality. 104 00:07:02,170 --> 00:07:03,410 This is great. 105 00:07:06,310 --> 00:07:10,310 Okay, but why did we go through this whole thing? 106 00:07:10,310 --> 00:07:14,150 Why did I make you learn a superset of JSON basically? 107 00:07:14,150 --> 00:07:15,750 Why do we even need Nix? 108 00:07:15,770 --> 00:07:17,070 What's this file? 109 00:07:17,070 --> 00:07:18,090 What does it look like? 110 00:07:19,950 --> 00:07:31,030 Okay, so the output of the script actually looks really similar to what we might have written offhand at first, except everything seems to be prefixed with this really long string. 111 00:07:31,870 --> 00:07:37,650 So you can see like everything has a Nix store or something in front of it, but for the most part everything's identical. 112 00:07:40,640 --> 00:07:46,960 Okay, although I promised not to get too academic into Nix, this part is important. 113 00:07:48,300 --> 00:07:57,980 What is that garbled string at the front, like ahead of our build script, and similarly found within the script before each of the tools? 114 00:08:01,340 --> 00:08:08,240 Well, Nix has a handy command, and it could show us what does that script, like what does that prefix mean? 115 00:08:08,260 --> 00:08:11,460 So you could write Nix derivation show and give it the path. 116 00:08:14,980 --> 00:08:19,860 Okay, so the whole purpose of Nix is to kind of build this file. 117 00:08:19,860 --> 00:08:25,100 Why did we go through all that setup of writing that recipe? 118 00:08:25,180 --> 00:08:30,860 It's ultimately to produce this, and it's the recipe of what it takes to build our IP script. 119 00:08:33,080 --> 00:08:34,900 It has the build command. 120 00:08:36,740 --> 00:08:41,420 It has the text of the script, which may be also the source code. 121 00:08:43,280 --> 00:08:51,880 It has the input tools we needed, so our script needed bash, jq, curl, for some reason this thing called standard end. 122 00:08:54,300 --> 00:09:01,100 It also has the system we're running on, and as well as the architecture and operating system. 123 00:09:01,420 --> 00:09:08,360 So all of this is hashed together to give you that garbled string at the absolute top. 124 00:09:10,520 --> 00:09:30,260 So that's actually a really mind-bending property, because when you see that garbled string, that means we actually have incredibly strong guarantees about our build recipe, because the build recipe includes other garbled strings that represent other garbled strings, 125 00:09:30,260 --> 00:09:35,800 that represent other garbled strings, and so forth and so forth, down to the source code. 126 00:09:37,860 --> 00:09:44,600 There's a level of recursion here that means repeatedly seeing this hash is an incredibly strong property of reproducibility. 127 00:09:44,600 --> 00:10:01,380 You can train your eye, if I see the same string, I have this incredibly strong property about the whole tree of software, whatever the root of what you're building is, is identical down to the architecture, source code, tools, and then recursively at each of those levels. 128 00:10:05,240 --> 00:10:11,400 In Nix, you spend a lot of time wiring things up to basically model things as a graph. 129 00:10:11,400 --> 00:10:18,400 Turns out, once you have a graph, everything you might want to do in software is a permutation or transformation of graphs. 130 00:10:18,400 --> 00:10:19,680 That's all we're doing. 131 00:10:20,540 --> 00:10:29,000 So I built the thing in Nix, I can now have it visualized as this graph, and Nix gives me a handy command to do so. 132 00:10:29,000 --> 00:10:30,540 And here is that graph. 133 00:10:31,420 --> 00:10:36,300 This is the full dependency graph of that seemingly innocuous script. 134 00:10:36,300 --> 00:10:46,920 So in software today, we are taking on so much implicit dependencies we don't know about, and Nix makes those extremely evident and explicit. 135 00:10:48,380 --> 00:10:56,140 So, I don't know, we see jq and for some reason there's krb5 and then that's Kerberos. 136 00:10:56,140 --> 00:11:02,000 I don't know why, you know, to build libcurl, I'm sure, because it has a bunch of dependencies and on and on. 137 00:11:05,100 --> 00:11:07,960 Okay, so here's another Nix snippet. 138 00:11:08,060 --> 00:11:13,100 Again, ignore the actual syntax, but know that we're defining here a shell environment. 139 00:11:13,100 --> 00:11:19,280 So you're working on a project, and you want to define a set of tools to build your project file, to build your project. 140 00:11:21,440 --> 00:11:25,020 And remember that garbled string at the bottom. 141 00:11:25,880 --> 00:11:31,080 We import our same script as I did before and we add it into our shell. 142 00:11:31,080 --> 00:11:34,820 So I'm saying I have a shell and I want to use this tool. 143 00:11:35,900 --> 00:11:37,600 Then you can enter the shell. 144 00:11:43,020 --> 00:11:45,820 Okay, so you can Nix shell and you enter the shell. 145 00:11:48,660 --> 00:11:52,060 I see the little shell hook I did just to show you we're entering a shell. 146 00:11:54,900 --> 00:12:02,760 So I can say my path now contains what is my IP, so I can say which on it. 147 00:12:03,780 --> 00:12:08,580 And it'll find the same path of the binary. 148 00:12:08,740 --> 00:12:15,460 And more importantly, it finds it at the exact same prefix that I had built earlier. 149 00:12:15,460 --> 00:12:21,500 So now I'm taking that exact same binary and moving it into an environment for a developer. 150 00:12:21,980 --> 00:12:32,060 And I know that that developer has the exact same binary and all its dependencies with an extremely strong invariant. 151 00:12:33,960 --> 00:12:39,660 And it's also good it runs and works as we expect, because if it didn't, that would be a big waste of time. 152 00:12:42,670 --> 00:12:43,630 Boom. 153 00:12:43,730 --> 00:12:45,210 To me, this was huge. 154 00:12:45,210 --> 00:12:47,810 I was like, did we realize what we just did? 155 00:12:48,630 --> 00:12:53,970 We just created a simple way to bring reproducible developer environments for projects. 156 00:12:53,970 --> 00:13:05,570 You don't need to give a docker file, have people enter namespaces, network namespaces, volume mounts, you know, doing non-reproducible steps. 157 00:13:05,570 --> 00:13:11,730 This is a way to be natively giving reproducible packages across individual developer projects. 158 00:13:13,810 --> 00:13:16,790 And you could easily validate it thanks to that prefix hash. 159 00:13:20,860 --> 00:13:22,620 But this goes even further. 160 00:13:22,620 --> 00:13:24,860 We actually know everything about our code now. 161 00:13:25,940 --> 00:13:28,320 We can do binary or source deployments. 162 00:13:28,320 --> 00:13:42,960 Again, when we have that graph, we can take that graph and move all the pieces of that graph, which represent files on your machine, onto another machine, and we like to colloquially call that a deployment. 163 00:13:45,560 --> 00:13:48,440 So, Nix makes this really simple. 164 00:13:48,720 --> 00:13:52,280 We simply copy those paths from one machine to another. 165 00:13:53,160 --> 00:13:58,620 And they don't even need Nix installed, because you're just moving it from a folder to a folder. 166 00:14:00,160 --> 00:14:01,100 Boom. 167 00:14:01,200 --> 00:14:02,200 Deployments. 168 00:14:02,280 --> 00:14:07,380 I don't need some crazy fancy machinery or whatever to get perfect reproductive deployments. 169 00:14:07,380 --> 00:14:08,320 Yeah, question. 170 00:14:12,150 --> 00:14:17,050 Yeah, the question was, will this only work if you're on the same architecture and operating system? 171 00:14:17,050 --> 00:14:17,630 That is correct. 172 00:14:17,630 --> 00:14:20,910 Unless you have bin format and you're doing emulation. 173 00:14:20,970 --> 00:14:28,090 But you can build on one machine for the target host, because you can cross-compile relatively easily in Nix. 174 00:14:28,490 --> 00:14:38,590 So, the idea, though, ultimately I want to get across is when you have a graph of things, you just move the graph of things to the machine and you know it's perfectly going to work. 175 00:14:38,590 --> 00:14:44,790 I don't know how many of us have ever been like, I built something here locally and I installed it there. 176 00:14:44,790 --> 00:14:51,470 Oh wait, it doesn't have libssl or it has libssl at 1.0 and not 1.1. 177 00:14:51,610 --> 00:15:01,210 You've captured everything down to libc, like the fundamental library in Linux, and you move that over and you know everything's going to work perfectly. 178 00:15:05,880 --> 00:15:07,360 So, here's one such command. 179 00:15:07,360 --> 00:15:11,440 There's a couple ways to do it in Nix to copy the graph we saw earlier to another machine. 180 00:15:11,440 --> 00:15:17,100 In this example, we're leveraging Nix copy, but you could do something as dumb as scp or rsync. 181 00:15:17,480 --> 00:15:20,800 I didn't mean to call you dumb if that's what you use, I just meant simpler. 182 00:15:22,840 --> 00:15:27,560 So, the items are copied over and let's log into this machine. 183 00:15:31,040 --> 00:15:38,380 And I ran the path and notice it's the exact same path that is present there and I run it. 184 00:15:38,380 --> 00:15:40,260 So, it's that same prefix string. 185 00:15:40,660 --> 00:15:49,960 So, that means for it to have run, because it points to other very specific paths, all those paths were there on that other machine and it all works and wires and runs. 186 00:15:49,960 --> 00:15:53,020 So, I moved that whole graph over. 187 00:15:55,910 --> 00:16:06,930 Wow, we just did a deployment of not only our code, which was the script, but all of its necessary dependencies, such as curl, jq, and bash. 188 00:16:07,570 --> 00:16:09,290 This blows my mind. 189 00:16:09,450 --> 00:16:19,370 Like I said, I can't tell you the number of times in practice I had to coordinate the runtime needed on the host for some base library not being present or whatever. 190 00:16:20,290 --> 00:16:22,490 It simplifies it a lot. 191 00:16:25,140 --> 00:16:30,480 Okay, well maybe that's a bit aggressive for deployments and you've already drank the Kool-Aid of Kubernetes. 192 00:16:33,180 --> 00:16:43,340 No problem, since we know the graph and again everything is merely a transformation of a graph, we can turn that into an image. 193 00:16:47,100 --> 00:16:53,740 So, here's another snippet, and again ignore the syntax, but know this is creating an OCI-compliant image. 194 00:16:58,410 --> 00:17:02,390 We set the commands of our image to be our whatismyip package. 195 00:17:05,580 --> 00:17:10,940 And just like that... next slide... so let's go build that image. 196 00:17:13,580 --> 00:17:18,300 So, the output of it is a tarball, because an OCI image is a tarball. 197 00:17:20,500 --> 00:17:29,340 We can load that tarball into docker daemon as normal, or you could do this through whatever the you know a registry or whatnot. 198 00:17:31,460 --> 00:17:37,120 Okay, I could run the tarball, or run the image effectively, and it works as we'd expect. 199 00:17:37,120 --> 00:17:41,100 I get the IP, because the the command was the IP. 200 00:17:41,100 --> 00:17:52,540 I can inspect the image, and we yet again see that the same prefix hash on our package for the command to execute is there. 201 00:17:52,540 --> 00:18:00,820 Again, this continues to give me those warm fuzzy feelings in the inside that I've now produced an image that I'm deploying, and it has the same prefix hash. 202 00:18:06,390 --> 00:18:07,470 Cool. 203 00:18:07,650 --> 00:18:10,770 So, we have Nix and docker integration perfectly. 204 00:18:10,830 --> 00:18:14,550 The image produced only has the files exactly necessary to run the tool. 205 00:18:14,690 --> 00:18:18,450 So, I've also done effectively distroless, which is all the rage right right now. 206 00:18:18,450 --> 00:18:21,910 So, you don't have any other base libraries running around. 207 00:18:21,910 --> 00:18:30,630 You've built an image and a file system exactly with what's needed to run the command and or the application therein. 208 00:18:32,590 --> 00:18:34,390 And honestly, you could do the same. 209 00:18:34,390 --> 00:18:35,930 There's plenty of other slides here. 210 00:18:35,930 --> 00:18:39,090 I'm not going to show you every variant, but everything's just a permutation. 211 00:18:39,090 --> 00:18:40,730 We did OCI images. 212 00:18:40,910 --> 00:18:43,930 You could do a random assembly tarball. 213 00:18:43,990 --> 00:18:45,710 You could do a self-extracting zip. 214 00:18:45,710 --> 00:18:46,670 You could do RPM. 215 00:18:46,670 --> 00:18:47,610 You could do a Debian. 216 00:18:47,610 --> 00:18:48,610 You could do a flatback. 217 00:18:48,610 --> 00:18:50,110 You could do an app image. 218 00:18:50,270 --> 00:18:54,250 Again, you've spent all the time setting up your graph. 219 00:18:57,130 --> 00:19:01,130 Well, Linux distribution itself is actually just a collection of packages. 220 00:19:01,250 --> 00:19:05,750 It's a permutation and a collection of software files. 221 00:19:05,750 --> 00:19:16,820 It turns out, you could also build an OS out of Nix itself, and that's what NixOS is. 222 00:19:18,780 --> 00:19:25,380 Again, oh, so again, ignore the... this is like a very basic config setup for a NixOS image. 223 00:19:25,440 --> 00:19:32,700 You don't have to care about the syntax, but what's important is we're setting one up, and I'm importing that same package. 224 00:19:33,300 --> 00:19:38,740 And I'm telling the OS image, include this as a default package within the image. 225 00:19:40,840 --> 00:19:44,480 And I'm starting it as a VM, just so I could demo it. 226 00:19:45,280 --> 00:19:49,240 But you can build an ISO or whatever and then boot into it. 227 00:19:52,350 --> 00:19:55,230 Okay, so like everything else, we build it. 228 00:19:55,230 --> 00:19:56,930 So I'm building my VM. 229 00:19:57,570 --> 00:20:01,590 Again, keeping in mind, we want to look for this prefix hash. 230 00:20:02,890 --> 00:20:06,010 So we get an output directory. 231 00:20:07,290 --> 00:20:11,430 Okay, and within that output directory is a run script to run KMU. 232 00:20:11,430 --> 00:20:17,830 I'm going to run my OS with some fun parameters, just so I can see stuff in the TTY. 233 00:20:21,100 --> 00:20:23,300 It starts to log in into NixOS. 234 00:20:23,400 --> 00:20:24,680 I log in. 235 00:20:26,760 --> 00:20:31,860 And again, I execute which is which, what is my IP. 236 00:20:31,860 --> 00:20:33,420 Looks like I found it. 237 00:20:33,420 --> 00:20:37,180 It's on some other symlinks path, but then I say real path. 238 00:20:37,180 --> 00:20:42,500 I get to the underlying symlink, and I see that warm, fuzzy feeling again. 239 00:20:42,500 --> 00:20:44,320 I see that same prefix hash. 240 00:20:44,320 --> 00:20:55,920 So now I've built an OS distribution that has my software package, perfectly reproducible with all its dependencies and that same OS. 241 00:20:56,000 --> 00:20:57,360 I feel happy inside. 242 00:20:57,360 --> 00:20:58,360 I feel joy. 243 00:20:59,460 --> 00:21:04,240 And yeah, and it works, because we ran it. 244 00:21:05,280 --> 00:21:06,280 Oh, that was it. 245 00:21:06,280 --> 00:21:07,300 Yeah, thank you. 246 00:21:12,190 --> 00:21:12,790 Questions? 247 00:21:12,790 --> 00:21:14,270 Yeah, and I'll try to repeat them. 248 00:21:23,600 --> 00:21:27,740 I think the question was, can you do a NixOS module? 249 00:21:33,290 --> 00:21:40,210 Yeah, I mean, the question is, can you do a NixOS module to configure a Docker image? 250 00:21:40,830 --> 00:21:42,350 Sure, I think you could. 251 00:21:42,350 --> 00:21:46,430 A module is just another level of abstraction to set up code. 252 00:21:46,430 --> 00:22:03,430 And I could see, if you have a very consistent pattern for building your OCI images, you might not want them to have to write something closer to a Docker file and write some other higher level thing that you end up emitting the OCI tarball for. 253 00:22:03,430 --> 00:22:04,290 Totally. 254 00:22:12,530 --> 00:22:15,410 Okay, the question is, where is jq and curl coming from? 255 00:22:15,410 --> 00:22:16,630 That's a good question. 256 00:22:16,690 --> 00:22:21,050 So it would be incredibly tedious to have to rewrite the world yourself. 257 00:22:21,270 --> 00:22:24,210 Thankfully, there's a large community that has already done that for you. 258 00:22:24,390 --> 00:22:27,350 And that is called Nix Packages. 259 00:22:27,350 --> 00:22:35,770 So there is already a huge package set where authors have already taken the painstaking time to do all those dependency edges. 260 00:22:35,770 --> 00:22:37,930 So you don't have to always start from scratch. 261 00:22:40,710 --> 00:22:47,290 And it's also the world's largest package set, by at least one order of magnitude, I think. 262 00:22:55,710 --> 00:22:58,950 Yeah, the question is, there's Nix Package Manager and NixOS. 263 00:22:59,690 --> 00:23:01,950 Naming in Nix is hard. 264 00:23:02,290 --> 00:23:03,750 They don't do a very good job. 265 00:23:03,750 --> 00:23:11,930 I think my takeaway for the talk is Nix just says, tell me what your graph is. 266 00:23:12,030 --> 00:23:14,850 And once I have your graph, I can do whatever I want with it. 267 00:23:14,850 --> 00:23:18,490 So there's Nix Package Manager that says, download the graph. 268 00:23:18,670 --> 00:23:23,890 Something like, you know, apt-get or yum or whatever. 269 00:23:23,890 --> 00:23:29,150 So it says, you have a name, download the graph for me and let me install this package locally. 270 00:23:29,510 --> 00:23:37,150 NixOS says, here's a bunch of packages, turn them into an OS distribution, and let me run that. 271 00:23:37,150 --> 00:23:44,370 So they're all just different variants of, here are different graphs, put them together and make them a thing. 272 00:23:51,760 --> 00:23:53,440 Yeah, what is Nix Shell? 273 00:23:53,860 --> 00:24:04,060 So Nix Shell, just to get a bit more pedantic, will download the packages, but it puts them in this separate Nix store thing . 274 00:24:04,360 --> 00:24:06,300 And then it just sets your path. 275 00:24:06,400 --> 00:24:11,160 So in Linux, how things are found is they do a search along your path. 276 00:24:11,320 --> 00:24:23,900 So the moment you do a Nix Shell, it drops you into a new bash environment with your path set with some new... your path environment variable set with some new directories. 277 00:24:23,900 --> 00:24:25,020 So they're found. 278 00:24:25,040 --> 00:24:29,560 So it's like, ephemeral to that single session. 279 00:24:29,560 --> 00:24:34,820 And what's great is there's no container, no namespaces, no cgroups, nothing. 280 00:24:34,820 --> 00:24:38,620 So you're like fully native within the host. 281 00:24:51,290 --> 00:24:54,510 Sorry, the question is, does this work for alternate architectures? 282 00:24:56,390 --> 00:24:57,650 Things work. 283 00:24:58,290 --> 00:25:00,970 Ultimately, you're building third-party software. 284 00:25:01,110 --> 00:25:09,250 So the asterisk here is, do things work for alternate architectures, is going to be, does that software build anyways reliably for those alternate architectures? 285 00:25:10,190 --> 00:25:11,770 If you're on your own. 286 00:25:11,770 --> 00:25:24,850 The other benefit is, if using this large package set, authors have taken the time, and many of them are here, they're running RISC-V or cross-compiling, and they've submitted patches to make them work for alternate architectures. 287 00:25:24,850 --> 00:25:28,170 But fundamentally, Nix is architecture agnostic. 288 00:26:00,300 --> 00:26:14,700 Because Nix is this recursive hash calculation, a cryptographic hash of your stuff, if I changed even a comment in my source code, I went back to that script, what is my IP, and I put a comment. 289 00:26:14,700 --> 00:26:17,960 I functionally didn't change the thing. 290 00:26:19,820 --> 00:26:30,920 Asterisk will get a different hash, because when it goes to build this big recipe file, so this is the recipe file that says, Nix, this is how you build this thing. 291 00:26:31,540 --> 00:26:41,700 It had here the text, that's the contents of the script, like the contents of the script to change, and then therefore the hash changed. 292 00:26:41,940 --> 00:26:43,380 Again, this is recursive. 293 00:26:43,380 --> 00:26:56,260 That meant if I wanted to use a different curl, and it only changed because of a comment, its hash would change, and now my hash would change, because I have a different hash in my hash. 294 00:26:57,640 --> 00:27:02,440 So I get a totally different output, and that's okay, they live side by side. 295 00:27:03,000 --> 00:27:09,460 The beauty of having hashes in the name is now they're not colliding spaces in the directory. 296 00:27:09,460 --> 00:27:12,800 They're just like sitting side by side in a big directory tree. 297 00:27:13,620 --> 00:27:16,780 If I want to go back, I delete that comment. 298 00:27:16,860 --> 00:27:23,280 If I perfectly delete it, and the hash calculates back to the same thing, Nix says, you already got it there, buddy. 299 00:27:23,280 --> 00:27:26,400 I'm not going to do it again, and it skips some work. 300 00:27:29,910 --> 00:27:32,890 Again, really clear, that's not bit reproducible. 301 00:27:33,290 --> 00:27:35,010 Nix can do bit reproduction. 302 00:27:35,390 --> 00:27:36,530 This is a bit different. 303 00:27:36,530 --> 00:27:47,290 This is pessimistic reproduction, because the source changes always affect the hash. 304 00:27:51,590 --> 00:27:52,510 Okay, thank you. 305 00:27:52,510 --> 00:27:53,390 I'll be around. 306 00:27:53,390 --> 00:27:56,190 If you have more introductory questions, I'm happy to answer. 307 00:27:56,270 --> 00:28:01,370 If you have high-level questions, I'm happy to answer, and I hope you learn to love Nix as much as I do. 308 00:28:01,370 --> 00:28:02,110 Thank you.