So my talk is on doing toolchains declaratively, which is very powerful with Nix. So the main thing is... Toolchains essentially allow for being able to target different platforms that are compiling code between systems. One of the problems with toolchains has been that on a lot of distributions they live in random places like opt or just in US or local. With Nix we are able to put them in a very specific location. It's very powerful. And one of the other problems is toolchains can only target one platform until you have to compile it for another platform like GCC. So if you want to target RISC-V and you're on X86, you have to recompile GCC entirely, which can be very difficult if you don't have the hardware for it. With Nix we can easily do this and distribute it between multiple systems using remote builders and various other features. So the more of Nix way of doing things is splitting toolchains into their base components. So this would be having a derivation specifically for your C compiler, runtime libraries, your C++ implementation, pin tools and all that. Currently LLVM and Nix packages does this, but we're working on this with GCC right now. Another powerful thing is being able to have multiple versions of a compiler. Because some code might like only certain versions of a compiler and being able to change versions of a compiler dynamically is very useful. So one of the current problems we have with compilers in Nix packages right now is GCC is very monolithic. Essentially what that means is GCC will build all components inside of one derivation, which takes a lot of time. So you're not able to parallelize it that well. It's also not multi-target. What this essentially means is GCC only targets your current target. Like if you have GCC targeting ARM, you can't specify to do x86 or you can't specify to do RISC-V. You need to do an entirely new build, which could be another 30 minutes or on slower hardware a few hours of just compiling GCC. And one of the problems we also have in Nix packages is cross-compilations are heavy. One of the ways this is a problem is we essentially instantiate an entirely new instance of Nix packages. So let's say Nix packages take about 4 gigs of RAM to evaluate. You essentially create a new instance of that, which is another 4 gigs of RAM being allocated just to be able to cross-compile that. There is another way of doing cross-compilation, which is emulated, but that is not real cross-compilation and there's a lot of issues with that. So pretty much the plan is to streamline how we handle cross-compilation right now in Nix packages. So part of that plan is to redo how the C compiler is introduced in or loaded in Nix packages. Currently there is a CC attribute, which contains the C compiler, which is essentially the entire toolchain for C. Inside the standard environment, there is an SCM no-libc function, or no-cc set, which is the SCM without a C compiler. So the idea is to make that essentially the default, and for more packages to use that by default without a C compiler. Instead of explicitly inheriting a C compiler without implicitly having one. One of the things we are doing is also adding new toolchain attributes, so this is part of the splitting of GCC. So now it's all going to be in their own components. Why cross-compiling is important? If you want to target an AVR, you can't really compile your code on an AVR device, or you can't compile on an ESP32. You have to have a toolchain which can cross-compile from your host system to the target system. It's also useful for finding bugs in builds without having the actual hardware. So if you want to support RISC-V, but you just don't have any hardware for it, you then can use a cross-compilation build. And then you can also integrate that with QMU and NixOS VMs, and have an automated test suite essentially to be able to build and test for any device that you don't really have. There's two kinds of methodologies into cross-compilation in Nix packages. There is packages-across, which gives you a set of various platforms like targeting PowerPC, x86, 32-bit and 64-bit, RISC-V, 32-bit, 64-bit, all that. They create in a new Nix packages instance, which we call a variant now. It's pretty simple to use, but it's harder to chain up. Let's say if you want to do a statically linked LLVM build for RISC-V, you can't really chain that. A lot of the attributes just collide and you lose a lot of that inheriting that's going on. You can do this by manually importing Nix packages and specifying the attributes, but that is not really recommended currently in Nix packages. There is the override way. Essentially, the SEM is an attribute that everyone pulls in to create a package. That's actually powerful because if you use an override, an overlay onto a package, you can actually override that package and then have a new standard environment. This will change how we have disjoining CC and SEM, but essentially it is the same principle going on. A new way of doing CROSS we have being worked on is called CROSS-SEM. It is a chainable attribute set. As you can tell by the example, we are able to define a CROSS-compiling standard environment for ARM that is statically linked. That's a lot of a more streamlined way of doing it rather than being able to create a new Nix packages instance. The idea is to also do one stage of bootstrapping. With CROSS-compiling currently, it goes through three to four stages. It builds from your host to target, then build to target. It does this weird set of chaining that takes a lot of resources, a lot of disk space, increases your closure size. The new way is to be CROSS-compiling as minimal as possible. Essentially, if you only need to have this specific library for that architecture or whatever you are targeting, it is only going to be building that. It is easier to manipulate and mutate. It is also explicit CROSS versus implicit. With doing packages across, it depends on what you put into the native build inputs or build inputs. But being able to override and specify that you want this specific package as a dependency for the package you are CROSS-compiling and have that one compiled instead rather than having it implicitly done is pretty powerful. This is going to work a lot better with multi-target compilers. This will make it easier to compile your compiler once and then target any platform. There is a PR fork right now that has been slow to work on. There is something called GCCNG. John Erickson and I have been working on this for about two months now. It is a very LLVM-brained way of doing GCC where everything is on their own components. We actually splice it better so we are able to handle CROSS-compiling a lot better. This version of GCC is also easier to work with vendor forks. Some vendors like Tenstore or Expressive like to fork and change GCC and different compilers around. Being able to point GCCNG to whatever that source is and tell it to compile and get the compiler is a lot easier to work with than trying to manually do it or do some weird overrides. We are weirdly importing it in a way. There is a function called buildGCCPackageSet which spits out an entire GCC package set for whatever version of GCC you want. LLVM is getting the same sort of treatment where I have been for pretty much a year now refactoring a lot of how LLVM works to make it work better with splicing and overrides and being able to be a lot more flexible and easier to work with but more maintainable. The entire idea is to streamline how we are doing toolchains. I actually do have a bit of a demo of how we can do this currently. As you can tell, these are three different kinds of ways of doing cross compiling. This is the PackagesCross method. You then have the Override method which you can see we just specify PackagesCross and pull in the same environment. And then this is the sort of new way of doing it with the CrossSDN. As you can tell, we are doing cross compiling for a 32-bit ARM and doing it with Hello. And then if I give it a start, you can see it's just evaluated everything and now it's actually cross compiling all those. And there's actually a lot of logic of how this works currently. But with a lot of new work, this will be very streamlined once we have a more override-friendly way of doing cross compiling and manipulating toolchains. Any questions? No, but... We can't really use it with the badges because the Espressif IDF, which is their SDK, is very strict with how it wants to be used. You technically could, but we haven't had the time to actually do that. And they're using the infrastructure in these packages right now. But it technically is possible. Explaining splicing. Essentially, the idea is that a lot of how Nix Packages works is it happens in a series of... You can imagine everything as an overlay in Nix Packages. And let's say if you want to override something, you have to splice it. Essentially, that means you cut it out at that point and inject something new. We do this a lot with the three different build platforms. This is a way of how things are done with compilers. You have build, host, and target. Those define how things are pointed to and what supports what. Host is the system you're natively running on. But the build is what you're actually building on. And then target is whatever devices you're targeting. And so we have three attribute sets which mimic that behavior. We have build packages, host packages, and target packages. And splicing changes based on what phase of Nix Packages you're in. And so using that make function that handles splicing a lot better... Yeah, that essentially controls how the attribute set is defined with overrides. There's a lot of logic in actual Nix Packages of how to handle the splicing correctly. Any other questions? Does this change anything with regards to cross-compilation in Nix? Does it make it better or is it still changing? I don't see it impacting flakes currently. But I could see it in the future being a stepping stone to improving cross-compilation. I have floated some ideas with... I'm trying to think of his name... It's Rob... The other Rob, but he's on... I forget the last name, but he's on the Nix team. And we've had some discussions because one of the things I brought up was adding a definition that pulls in more information about your host into flakes. And so there's been some discussions about that a few months ago. But this could definitely be some sort of thing to look at. Improving Nix itself to make flakes handle cross-compilation better.