So one of the things that we did after Defcon was we went through and cut up all the talks that were given at NixVegas. And this one has the audio missing for the first five or so minutes, so just bear with me while I narrate over it a little bit. But this is reproduce this build, how we built the Nix badge. And because this is Nix, we can just provide repos up front. So NixVegas slash badge, that's the firmware for the badge. It uses the ESP32 SDK. And NixVegas slash PCB is the reproducible hardware pipeline that we built for the badge. And that uses KiCad as the CAD software with a mix of plugins that are actually packaged reproducibly so they can spit out the correct Gerber file that JLCPCB needs in a bill of materials. And it's called a centroid file that basically is everything that JLCPCB needs to fabricate the PCB. And having a reproducible PCB pipeline is actually really useful. As it turns out, you can run the electrical rules checks and the design rules checks in your build pipeline to make sure you're always getting the exact same PCB every time you upload it. And also, it's very useful if you're repeatedly uploading things to test JLCPCB's preview feature so you can make sure that your board that you're previewing is the one that you built and ultimately the one you're going to get printed. Speaking of getting things printed, so this is what JLCPCB ships you. This was kind of after our prototyping phase. They kind of are notorious for shipping you a lot of cardboard, a lot of red bubble wrap, and each one of those red bubble wrap things has like, I think, six PCBs in it. We had to go through every one and pull it out, pop the mouse bytes off, which are basically these little snaps that secure the board frame in. We had a couple prototype badges that we passed around for people to take a peek at. And yeah, so we had all these things arrive and Tristan and I basically spent the better part of five or six hours the Tuesday before DefCon soldering all those things. So this is the first one that worked. We plugged it into USB and flashed the firmware on it and, you know, thankfully all the LEDs lit up. And from what it seems like, most of the badges were pretty much like this. Maybe like a couple defects here and there, but most of them just came up. They're actually pretty consistent, which was good. Another interesting thing about the programming process is that the ESP32 uses the clear-to-send pin of the serial line as a reset line. And that's really useful because regardless of what state the badge is in, you don't actually need to hold down any reset buttons or any bootloader buttons to get into the bootloader. So you just plug it in and immediately bootload it and it will reset and basically get going. So yeah, here you can see I'm kind of going over the KiCad PCB just at a very high level. So this is the PCB editor as opposed to the schematic editor. There's normally a schematic editor and you define the basically electrical schematic there. And then you basically tell KiCad that I want all those components on a physical PCB and it will copy all of them there. And then you get to spend hours and hours arranging them and routing them and putting silkscreen on and doing solder mask knockouts and all sorts of good stuff. You can see that there are zones drawn. Those are those red outlines around each lambda. Basically what those are for are those are different copper fill kind of designations. So you can tell KiCad to fill different parts of the PCB differently. So that's what creates the board's kind of like light versus dark lambda effect as opposed to, you know, something that's printed on it because it's a blue it's a blue PCB. So because the NixOS logo is just different shades of blue, you can kind of do darker or lighter blue. So that's, yeah, you can see I'm turning on the silkscreen layer there. That kind of made the negative space between all the lambdas. And yeah, by the way, this was made with the new NixOS logo that the marketing team just created. So the board cuts are all from that. And yeah, so you can just import, actually, board cuts from an SVG directly into KiCad and then give it a scale factor and it will basically just resize that SVG and that will be your board. So there's a tool called SVG to Shenzhen that lets you do this for kind of complicated outlines. I actually didn't even have to use that here. I mostly use SVG to Shenzhen for that actually. That is our artwork which was live traced in Inkscape. And then, yeah, I did use SVG to Shenzhen to basically create a custom footprint with the solder mask knockout for our art. Anyway, that's kind of this first part of voiceover. Audio is going to return in a few seconds. Yeah, enjoy. It's a little bit counterintuitive. It's a solder mask knockout layer because it's assumed that there's mask. The solder mask is basically the blue color. It's the thing that effectively a coating that goes over the copper so you don't short the copper. But if you have a solder mask layer, that means that that part of the solder mask is actually removed. Now, if you remove the solder mask, you expose copper. So then you have to go and actually add two things. So if I hide the mask layer, you see there's all that still all this basically, which is actually copper knockout. So all of these outlines have the copper removed so you can see through to the PCB. And FR4, it's the type of material that these PCBs are made of. It's kind of like a fiberglass style material is slightly translucent. So we cranked up this LED basically to maximum and you can see the kind of RGB effect on the back. So that's SVG to Shenzhen and KiCad. What I will note is that there's a nasty Ruby script that we had to write in the repository to convert the SVG to Shenzhen output to an actual copper knockout because it creates a solder mask knockout but not a copper knockout. And Q and KiCad are different formats. And there's a lot of manual copy paste of KiCad files that that part is not really that reproducible honestly, just because the tooling is annoying. So how this all kind of comes together is if I go to the PCB repository, we basically have a Nix package that is actually a couple things. There's the KiCad text injector, which is if you look on the back of these badges, actually the store path that the badge was rendered to in the Gerber files is actually printed on the back. So KiCad text injector is a Rust package. It's actually not upstream to Nix packages, although that's something that I plan to do. It's just a really simple Rust package that replaces the placeholders in KiCad with environment variables. So that's how we got the store path on that. And then there's this other project called JLCFCTSRE. It's a reverse engineering project. So the fab that we used is JLCPCB. So they're a Chinese fab based in Shenzhen. And one of the things that we looked into doing was using basically using JLC's like colored silkscreen. And JLC has kind of a strange thing where their colored silkscreen is a proprietary like encrypted format. But someone's gone and reverse engineered it. It seemingly like only exists to like vendor lock UN basically because it's just encrypting an SVG basically. There's interestingly no tooling that really supports this. So we were looking into like originally making these white using like doing a white PCB and then actually printing the NixOS colors on it. But seeing there's no tooling from KiCad that actually works with JLCPCB. We ended up using the copper and stuff. And honestly, that was it was cheaper. It turned out better, I think. Although I'd still like to see a white version with color silkscreen. So those are just some support packages that we made. Then our default.nix. So this is where we actually start locking down KiCad libraries. So we have the JLCPCB KiCad library from GitHub that we locked the exact version. So if you want to, you know, reproduce this hardware, then you can you can literally reproduce the build basically. There's also this fabrication toolkit for KiCad, which is a collection of Python scripts that are kind of annoying to use, that correctly export the Gerbers and get them into a format that JLCPCB can read. So I've got a derivation that basically takes those two things together and creates KiCad's third party directory, which is all of the plugins. And it's this kind of nasty JQ script basically that adds a bunch of JSON in the sandbox to KiCad's plugins directory. But all this is in the packages. And then yeah, the actual build, we define all the layers that we want to render. We actually do a couple renderings, including like a 3D render and then a render of the Gerber, so you can open that in the Gerber editor, and then a actual fab copy, which uses fabrication toolkits. And so we run KiCad Text Injector to basically inject the environment variables which are relevant, which are mostly just the store path. And then the build phase basically exports the Gerbers, exports the drill, so you can render or load those into a Gerber viewer. And then the check phase runs the ERC and DRC, so you can get assurance that your electrical rules aren't being violated and your design rules aren't being violated, although that wasn't 100% assurance if you define the electrical rules wrong, such as swapping a 3v3 and ground. It will just make sure that you're not connecting 3v3 to ground, but if you're going through a component then you're still going to violate, or you're not going to violate ERC, but it's also just not going to work. So then we also, the post check, once we know that the check phase is good, we render it to another output. So this is using a feature of Nix called split output derivations. So you can actually define in Nix derivations this outputs variable. So we have out, which is the Gerbers, and then check, which is basically the ERC and DRC reports, and then fab and render, fab being the JLC output, and then render being just 3D renders if you want to look at the badge in a photo viewer or something. So then the renders are all using KiCad's render ray tracer, using the KiCad CLI, and that was pretty easy. Then the install phase, just moving all the things to their outpats. So if you go and build this, actually, well, one thing of note is that because we have so many polygons in the copper layer, the design rule check actually takes quite a long time to run. So because I think if you do this sort of PCB art, you hit pathological cases with KiCad, where it will basically try to compare every single polygon in your copper layer against every single other polygon, and so it effectively becomes like an N-squared, and you just end up taking a lot of time, but it eventually finishes. So it'll at least get partially through the build. And while it's doing that, let's talk firmware. So basically, I got started on the firmware and got a couple demos working of the various hardware features. And then Tristan has been working pretty hard on it pretty recently. So the firmware is in the NixVegas slash badge repo. And if I do a NixFlake show, effectively, there's just one output, there's default, and it's the same as the output called NixBadge. And the result that it produces by, say, NixBuild, this dot caret star actually produces all the outputs. You don't have to do that, it'll just build the firmware by default, but if you want to do dot caret star, it will give you a flasher script too. Alternatively, if you want to develop on it, you can basically just NixDevelop, and it will automatically set the ESP IDF framework up for you. There's actually a Nix packaged version of ESP's IDF. I think it's the IoT development framework is what that's called. Oh boy , keypad's freezing. Come on . It's probably doing the design rule check right now. Oh, there it goes. I think I'm going to just kill that. Oh, there we go. Come on. This laptop is not a powerful laptop for doing any sort of CAD work. Now, during my talk? That is true, they could probably build it pretty quickly. All right. Well, my laptop reboots. Any questions? So, probably manually routing all the traces was really frustrating. The auto-router had a lot of hard time with the shape of the badge. It frequently just could not route anything at all, and I had to just manually draw a bunch of traces. Changing the layout of a bunch of traces and having to re-route them was also pretty frustrating. I'm going to unlock my data sets and get in here. All right, now let's start playing with the firmware. So, to actually start playing with the firmware, there's a USB port on the badge. Just plug your USB-C in. And run Nix Develop. And part of the Nix Develop, or the build, it will actually patch the ESP IDF, because there's a plugin that we use that requires patches to it. So, it will just do that for you. But it takes a second, because it has to copy the entire ESP IDF. All right, there we go. But it drops you directly in source, and your friend is going to be... and this is in the readme, so if you check out the readme... The hardware feature is also, loudly, kind of the known issue about the SD card and how to build it. But yeah, for develop, your friend is idf.py, which is conveniently in your path. So, if I copy this, it will build it. And mostly, it shouldn't have to rebuild too much. Yeah, there we go. I kind of just built it. And ESP IDF has a monitor command that lets you basically break into a serial monitor that's very similar to something like screen. So, it's going to flash it, and then it will start monitoring. And so, yeah, by default, the badges come up in a configuration that's kind of the most battery saving configuration, so it just lights up the LEDs, basically. The ESP32, which is a RISC-V core, actually supports a bunch of things that we're not necessarily using. And by default, we don't use the Wi-Fi. But if we turn, if we unplug it, and if you hold the button down at boot, and plug it back in, run the monitor again, oh , it switches the port. Okay. All right, let's try this again. That's still ACN0. I'm just going to go monitor. And I'm going to hold the button down and hit reset. Oh, until it's fully up. Okay. All right, there we go. So, this actually started up Wi-Fi. And what these badges are doing when Wi-Fi is started up, basically, is they use ESP's mesh light library to basically automatically create a mesh topology. So, it spawns a Wi-Fi network, and it tries to connect to other badges' Wi-Fi networks. And let me try to connect to it. Is that an NVS config option? It is not working. Oh, what's that? You hold the button. So, if you hold boot, that puts it to the boot loader. Okay. I think, yeah, the issue, basically, is that the USB also resets it. So, I just have to hold the button until it comes up. If I want to just show the console. I think it's whatever the latest is. So, we can, yeah, probably we're going to probably not going to be able to do this demo live, at least. But, yeah. Oh, really? Do I have the old version? That's entirely possible. Can I try your badge? No. Well, we'll come around and, yeah, if you guys are curious about doing binary substitution over this, it basically connects to our Wi-Fi network and talks to our servers. It's not that fast, and because the SD card is not working, it's, you know, especially slow because the ESP32 has to Wi-Fi schedule a lot. But the firmware is open source. Y'all can hack on it. We're definitely willing to help you all get going with it, especially if it's your first foray into Nix and you want to hack the badge. I mean, yeah. You guys, you guys have the tools, so. Any more questions? So, yeah, the getting KiCad plugins to work in the Nix sandbox, basically it was reconstructing the entire KiCad, like, plugins directory every build. Which, I mean, it's useful if you want to get the same output every time because it was very reliable. I think I had, like, probably, like, 15 different uploads to JLCPCB that were all, like, slightly different because they have... So, JLCPCB has a great, like, Gerber file viewer, and I wanted to make sure that, like, when I uploaded it, it was kind of what I expected. So, I'd do something and then, like, I'd make a little change and then I'd just upload the same zip. But getting it there, it was just a lot of scripting. But that actually gave me a pretty good iteration process with JLC. Because, I mean, I knew it was going to produce the correct thing every time and that it was going to change in just the way I intended. So, it actually gave me pretty fine-grained control of that process. JLC still had trouble with the orientation of some of the components. So, I think that's kind of a classic one, like, the diode was, like, flipped around or something despite the footprint being correct. And there's always a couple things with JLC that you have to mess with manually. But, I mean, at least Nix made some of the stuff work pretty well. Any more questions? And to the question of will you guys get a badge, we've got a bunch. So, probably. That's more of a Tristan question. What parts did we use Zik for? So, GPIO. Yeah, that's right. So, we used it to do some GPIO initialization and also we're still using the ASN1 stuff. So, yeah, the mesh communication... Zik has a great ASN1 library and it's a memory-safe ASN1 parser, which is super cool. So, we were playing with it on the mesh communication side of things. Of course, ESP-IDF still has a bunch of that framework that's written in C. I'm aware that there's a safe Rust version that's, like, a community-supported version of the ESP. It's, like, a kind of a Rust version of the ESP-IDF that's more, like, community-driven, basically. Although it doesn't support all the things, like, Wi-Fi. It still has to probably use unsafe to connect to some of that stuff, especially considering that the Wi-Fi chipset on the ESP32 is, like, locked down and has vendor blobs everywhere, basically, and Expressive ships you, basically, .a files to link into your project. But, yeah, I mean, it was pretty easy to link ZIG with it. It was, like, just some CMake file modifications, pretty much, and integration with ESP's, like, existing build system. So, actually, that wasn't that bad. I think the main issues that we had with it were, like, calling convention issues, like, where we would accidentally use the wrong calling convention for something, and then we'd just corrupt some memory, and it would cause problems, like, down the line. But once we were, like, once we had, like, the translation layer between C and ZIG, like, working, it was pretty easy to write ZIG that would, you know, just work. Unless we, well, unless we exhausted the stack, then things would get corrupted as well. So, obviously, not perfect. Yeah, any other questions? Any what issues? Feature size, like, what? Oh, I see. Okay. So, I copied the design rule. Basically, all the design rules, they're pretty well documented for JLCPCB, and someone actually implemented a KiCad rule set that basically automatically does the design rule checks for you. Those were, like, a little bit hard to dig up, but once I found them, it was all fine. And JLCPCB is also pretty good at running, like, design rule checks for you after the fact, too. So, like, you have a couple layers of, I guess, like, safety with the design rules on JLCPCB. So, I didn't really have any feature size issues because KiCad caught them first. It was mostly just, like, mistakes that I made, like, the 3.3 volt and ground swap on the SD card. What we really wanted to do with that is we really wanted to actually cache packages to the SD card, but, I mean, that'll just be in a future hardware revision of the badge, so. Or if people are enterprising enough to, you know, exacto things and bodge wire it, that also works, too. The hardware hacking village is down the corner. I was, like, 95% sure I'd have to say that because I'd make some mistake that would warrant it, and here we are, so. But, yeah. Any other questions? Oh, yeah. So, also, when you're getting PCBs fabbed with JLCPCB, and they have a lot of polygons in the copper layer, or solder, probably most of the copper layer, JLCPCB will kind of choke when you upload them and act like it's not going to render any of the, you know, any of the art that you added. But in, like, a half hour, the preview will magically appear and they'll be able to fab the boards. So, none of this was documented. It was just all stuff that we figured out just through trial and error. And, obviously, I mean, you know, you can reproduce this build, but sometimes you can't reproduce JLCPCB errors, so. All right, anything else? All right. Well, that's all I got. It's, that's our last talk for the day. We're going to go into the unconference. So, the unconference is an idea that we borrowed from Scale, actually. It is just the mess around with hardware in front of you, talk to people, chill out, maybe do some lightning talks, too. So, if you want to do lightning talks, come to me or Tristan and let us know. And, Firefox is messed up. And, yeah, we can get you slotted in. Lightning talks are, like, five to ten minutes, basically, if you want to go over. I mean, I'm not going to complain, so. But, yeah, thank you, guys. So, the badge actually generically acts as a router. So, I'm actually connected to it right now. We pushed some firmware that fixes some stuff. Also includes the default credentials for the Nix Vegas Wi-Fi network. So, I was able to actually get push over the badge. But, let's substitute over the badge. How does that work? Well, it's in the readme. So, if you connect to the badge, so, these badges, if you hold the reset button at the boot, or rather, not the reset button, the button at boot, and hit the reset button, they come up as this Nix badge and then, effectively, the last few digits of the MAC address. And so, you connect to that, gives you an IP address over DHCP. So, you can generically, like, ping over this. It's kind of slow. But if you want to use it as a substitutor, let's pick... I already have hello. Give me a package . Something that's small, ideally. Links? All right, let's go links. So , you pick port 1008 on the badge. It's a TCP port that we're kind of trying to think of as, this is, like, kind of a link local Nix cache port, basically. It's actually a free port in the IANA registry, which is interesting, because it's less than 1024. It was previously only used by Solaris, actually, for UDP. So, there's nothing registered to this port. So, it could be one that Nix uses if you registered it. But it will then go and download. And if you have the... If you have the ESP console open, you'll see that it's basically chunking the response from cache.nixos.lv, because it's connected to our network. So, it's actually substituting over this network. And it will take a while. It's not fast. The ESP IDF HTTP server is... I don't think we're using it right, first of all. And second of all... Oh, there... Well, actually, that didn't work earlier. All right. Let's try Cowsay. Let's see what Cowsay's dependencies are. Is the badge even still up? Yeah, it's still up. Oh, there we go. Oh, there we go. We got Cowsay. And we got Cowsay over the badge. Now, there's not an SD card, so it doesn't actually cache anything. But you can do that if you want. It's a nice party trick. And yeah, that's it. That's all documented in the README, by the way. So, this comes up as... Yeah, here we go. So, you just hold the button, we'll boot it. And yeah, you connect to the Wi-Fi network, basically. And just set the last octet to one. It can be a router, too. The password, by the way, it's all 1234578. Apparently, in the default ESP mesh configuration, you can't, like, change this for some reason. But it's there in case you want to mess with it. And that's it. Which button? So, the button is the one that's actually labeled button in the top right of the badge. So, it is the button. But yeah, have fun.