Transcript#
This transcript was generated automatically and may contain errors.
Our featured lab manager today is Eric Nantz. Isabella Velazquez is my co-host. My name is Libby Herron and we are so excited to introduce Eric. Would you like to introduce yourself? Tell us a little bit about about you and what you're gonna be talking about today.
Thank you, Libby. Hello, friends. Yeah, my name is Eric Nantz. By day, I am a senior director statistician in our innovation group over at Eli Lilly, a pharma company where I help with a lot of clinical trial design algorithms, building capabilities, shiny apps, R packages, and also kind of at the intersection of DevOps and making sure we're using innovative HPC and cloud computing and all that fun stuff. Outside of my day job, you might know me a bit perhaps for my voice. I have been in the podcasting world since about 2012 when I did the R podcast back then just on a whim, just trying something new. And then that's morphed into things like the Shiny Developer Series, as I'm very passionate about shiny applications, as well as more recently the R Weekly Highlights podcast to showcase the highlights that are shared on R Weekly every single week. So I am involved in the community quite a bit and I'm super excited to be here today. So thank you, Libby, for having me here.
We are so excited. And I can't remember if you just said in that spiel, anything about R pharma.
Oh, you're right. I have not. I am also one of the organizers for the R pharma group where we have a conference, a virtual conference every year for those in the life sciences that are wanting to engage with the open source community and supercharging workflows. But that's a total team effort. I've been part of that since the beginning and it's definitely a passion project to see how we can help patients with open source and share our knowledge across. So you can find all that information at rinpharma.com and I'll be referencing that actually a little bit later on.
Fantastic. If you are curious about any of these links, Isabella is putting them in the chat.
And if you do not happen to be in pharma or in any type of medical field, I really highly recommend you still investigate R pharma. Go look at the workshops, go look at the talks. There is so much goodness to be had there. Also, Christy has a cute dog on her lap. Oh my gosh, we need the name of the cute dog. Okay. Let's go ahead and get started. Eric is going to be talking about Nix and Rix. They are different things. We are going to get into it. This is going to be all about reproducible environments for development in data science and really in whatever you're working in. But Rix is specifically going to be for doing data science.
So Eric, I will let you share your screen so that you can take it away. And I think that the first thing that we are going to talk about is like, why do we need reproducible environments?
Why reproducible environments matter
Let's do that. So I'm going to frame it in a way that definitely echoes a lot of what I've seen in my industry work, but also just in the day-to-day world of data science. Things happen when you are either working on an analysis or building an application, you usually have to have some form of dependencies. Typically in the R world, it's R packages and Python world, very similar. And you want to be able to be assured that say two years from now, a month from now, or perhaps longer, that you can make this analysis or make this application run through the test of time. And there are, there have been efforts in the community and also in the DevOps sector in general to try and address this. Within the R side, we have, of course, the renv package offered by Kevin O'Shea over at Posit. Also, we have seen the advent of what are called containers, more popularized by the Docker project to kind of encapsulate more than just say a program itself, but the system-ish dependencies around that. A lot of these can be very helpful. In fact, I've been an renv user since it was first released. I've had Kevin on my podcast to mod renv.
There are situations though, when just isolating the reproducibility of your analytical environment is not quite enough because R, like Python, like these other languages, depend on your system as well. And when you have different collaborators that might be using different systems for their R environment, maybe some are using Linux, some are using Mac, some are using Windows. You can start to get a little differences when you get to that system level. Containers do try to address that, but they don't quite get it right in terms of not having a very easy on-ramp to that. But over time, I have discovered, along with others in the community, that there is kind of an in-between of this that we think is very well positioned for data science, and that is Nix itself.
I'm going to jump around in a little bit of my slides from another time here, but I'll first frame a couple ways you can think of Nix, and then we're just going to dive right in some stuff to really show this in action. You may have heard of Nix and me talk about it before. What the heck is it? It's a lot of things. It's a package manager, kind of like an app store source of software, but it's also its own domain-specific language. You'll see that shortly. It's also an immutable installation, meaning that once you do something with Nix, you really can't touch it, even if you tried by accident to change it. But it's also completely sandbox environments. You may hear about that, but you still may be asking, wait, wait, really, what is Nix? So that's where I want to dive in the real examples of what it means for you as a data scientist, and going above and beyond that if you want to really get up into the next level of reproducibility.
But over time, I have discovered, along with others in the community, that there is kind of an in-between of this that we think is very well positioned for data science, and that is Nix itself.
Introducing the Rix package
So as an R user, I will admit, if you just jump into Nix head first, it's going to be a tough going. That is where the Rix package comes in. This came at a perfect time in my Linux journey, or Nix journey, I should say. As I've been hearing about on podcasts, I've been hearing other people in DevOps talk about, but as an R user, I was like, I don't know where to start. Bruno Rodriguez, who I've had the good fortune of talking to a couple of occasions, has built the Rix package to be that bridge between the world of R and the world of Nix, without you having to be that perfect expert in the Nix domain-specific language to take full advantage of this. And that's what we're going to walk through today.
So with that, are we ready for some code examples? Let's have some fun here, shall we?
Yay, let's do it. Let's go. I'm going to put a link to Bruno's book in the chat as well, which is Building Reproducible Analytical Pipelines with R, because I send it to everybody that I know. If you're interested in that, another Bruno production, there you go.
Live demo: Nix and Rix in action
Excellent. So I'm going to motivate this by something that will seem a bit radical to y'all, especially if you have seen me talk about various things. So let me know if the font's not big enough. I can zoom in any time. I've been in the R community for many years. I've been a user of R since grad school for a long, long time. I don't care to say the year because I've already feel old enough as it is. Watch what happens when I try to run R on my system.
I do not have R on my system. I am using R in project specific workflows that are completely self-contained by Nix. This is just to prove to you that in my system that I'm running right now, which is ironically also powered by Nix, I can't run R by default. That's a feature, not a bug, because I want the entire project to be encapsulated by Nix, to keep it isolated from the rest of my system when I do crazy stuff in my system automation stuff and DevOps stuff, and to be able to share this across different architecture.
So let's motivate this with an example and we'll dive right in. I am part of the R Weekly team and one of the things we like to do as the curators is try to figure out who's got the upcoming issue. And that's when I built in Quarto a Quarto dashboard that has a couple HTML widgets to kind of give a calendar view of who is on the next issue. You can do this with Quarto, a little bit of R code, a little bit of HTML widgets. You certainly could do this without Nix. You could do this in your plain R session, but I wanted a way to be able to update this on a regular basis and make sure that when I update this, it's got the same environment, as close to the same environment as I can assure to as when I'm developing it. So that is where Rix is going to come into play because Rix will help you get into that bridge of opting into Nix itself.
And the way you do that is we have, I'm going to go to my other directory here. I'm doing some fancy stuff in my shell prompt. That could be a whole other hangout all together. But in this directory, you're about to see this R script right here. And I told you, I don't have R on here. I don't have R on here. I don't have R on this R script right here. And I told you, I don't have R on here, but I can run R on a temporary basis. Let's see what I mean by that. I have an alias that will actually, with the power of Nix, and we'll get to how to get to install Nix in a little bit here. I am jumping a little bit. I can create, and I'll show you what this alias is shortly, a temporary R environment that is completely disposable. But now, now I have R.
This is a custom environment exposed by Rix so that now if I have an R script that declares my dependencies I want for this R-related project, I can run a simple function. So what am I talking about with this script here? Oops, let me do that again. We have here a simple R script. You could either take this straight from the Rix website and modify as needed. And it is a simple function called Rix. You have two mechanisms to determine kind of at the higher level versus the lower level of what your project needs. One is you can say, do I want to make this project snapshotted by a certain date that's supported by Rix or a supported R version? For this project, I chose the date. But you could easily say instead of date, you could say R underscore ver and say 451 or 461 or any R version that Nix itself supports. And then this should be pretty intuitive. You can give a vector of package names. Again, renv has its lock file. Nix, you can feed in the package names here. You just need the names of packages. If you have system packages, you can feed that as well as a vector. And these would be any packages that are available in the Nix software repository. And then lastly, you could, we may not get into as much, you can tie this to the RStudio IDE or make it more general. And of course, you could overwrite your config when you build this.
So if I run this in this temporary session, let's boot up R here. Yes, it works. And I can do source build Nix config. Nothing really happened. Well, something did happen. And I'll show you what had happened. But I've already done this. So it's a little cheating here. I have built what is called a default.nix file. Now we're going to get into the DSL of Nix. This should probably look a little foreign to you. It certainly did to me. This is literally its own language. R is its own language. Python is its own language. JavaScript is its own language. Nix has its own language. And if you have infinite time, or a lot of time, you could probably learn this pretty well yourself. But Rix takes care of this for you. It does have some parts that you can kind of recognize, but I want to call out a few important things here. One of which is, look at what it's fixing. There is a convenience that Bruno and his team have built, where it has a cache of the Nix software repository ready for R. He does some stuff on top of that. But the real key thing is, notice this SHA-256. This is like in Git for version control. You have a commit hash, or commit SHA if you will, that you can always go back to that no matter how far you go. It's the same with Nix. Every dependency is captured by these different hashes that are available in the Nix repository, such that if I run this, and I build this system five years from now, if I have this default.nix, it will give me the same packages, the same versions of packages, the same system dependencies. It is that in-between then of Docker and just application level dependencies like renv does for the R package ecosystem. So I don't expect the end user to play with this on their own, because Rix is going to handle that for you.
Every dependency is captured by these different hashes that are available in the Nix repository, such that if I run this, and I build this system five years from now, if I have this default.nix, it will give me the same packages, the same versions of packages, the same system dependencies.
So I built this now, and now I want to get out of this. You can see my shell prompt has this like impure Nix shell with the customizations I did. I'm out now. And if I do which R again, whoops, that's gone because that was a temporary shell. Again. All right, hold on.
Eric, I'm going to pause you really quickly. I wanted to tell you your camera froze.
Of course it did. You might want to turn your camera off, turn it back on. And then the other one is I want to recap what you did so that I make sure I understand. You went into a Nix shell, which is a sandbox environment, and then you ran a Rix function.
Yep. Called R, you ran a Rix function, Rix being the R package Rix. We had a couple of questions in the chat, which I want to say, I think we're going to get there. One was from Brent saying, does this work for Positron? We're going to show some IDE level stuff in just a minute, Brent, so don't worry. Nathan asked, can you add packages later? Because in that Rix call, you kind of preloaded some stuff, right?
That is correct. Yep. So into your session, once you have already spun this up with R, can you add packages later? And I believe that you can.
Well, yes and no. It depends a little bit. You have to kind of get out of that environment, update whatever call you make to generate that default.nix, and then rebuild the system. And the way I typically do that is if I realize, oh, I'm missing, like, maybe one of the HTML widgets are out there, I would just update this script, save it, rebuild it, and then re-enter my environment, and then I'll have it. You can't just add them in that same environment, because it has to build the environment every time you change something. So it is kind of a rinse and repeat. I try to be pretty prospective about it, but I miss certain packages that I haven't added. So that is something that you kind of have to get in the habit of it. But once you do, it's really not that difficult. It's just adding a couple package references to this file.
Who is Rix for?
Okay. Fantastic. The other question that we had was from Nathan that was, who would Rix be useful for? And, like, expressing a little bit of nervousness about, like, selling Nix and Rix to other people. And, like, SPSS colleagues find that the fact that R packages can change over time is sort of a hard sell. So this might be an even harder sell. Could you give a quick rundown on who Rix or Nix plus Rix would be a really good fit for?
It's an interesting point. I can definitely understand that concern about packages, you know, packages updating, versioning, you know, maybe things change that you don't want. In that case, actually, Nix is even better for this, because you can have that snapshot in time of these dependencies. And as long as you're not changing that date, that time of when that hash of the Nix package ecosystem you're drawing upon, if you keep that same hash, those package versions aren't changing from under you. With that said, who is this for?
I will admit there are a lot of people that can probably get by just fine with the combination of renv for R and UV or something like that for Python. It's when you start to develop pipelines, analytics capabilities that are touching more than just R or Python. I'm talking about things like ensuring that you have the same environment for your application, say with Shiny, when you're building locally, versus deploying to maybe a Kubernetes cluster, or wanting to do CI CD, but the mechanism you're doing CI CD on the host you're on is maybe a completely different Linux network on an HPC cluster, or on the cloud via GitHub Actions or GitLab Runners or things like that. Nix really shines in this case, because you don't have to hope for the best that those other host environments have everything you need for the environment to be completely reproducible. You can take that variation away by leveraging Nix to orchestrate all that together.
You can take that variation away by leveraging Nix to orchestrate all that together.
So not all of you may have to go that far. I have to, because I've got a lot of things I'm doing at both the analytic level, but also at the deployment and DevOps level. So Nix has been a real lifesaver for that. Fantastic. Okay, we have other questions, but we will hold on to them, because I think we are going to get there eventually. And I will let you spin your environment back up.
Building and entering the Nix environment
Yeah, so now that we've built this, and in fact, I'm not sure if I actually, I haven't actually built it yet. So when you build, when I build an environment, this is all in the Rix documentation site too. After you got that default.nix generated by Rix, you just run nix-build.
Now that was pretty quick. I did do a little homework before this. Sometimes, sometimes things have to compile from source, not all the time. So if you've done that in R before, especially on Linux, you know that sometimes things can take a while. It depends on how old that snapshot is that you're calling from, and whether the Nix package ecorepository has binaries of those packages available. So with that, yeah, was there another question or should I keep going? No, I was trying to think, I was thinking about that. It's sort of like Webber or WebR, where like Nix, and in their own sort of like encapsulated system, whether or not they have all the versions of the packages that you are calling can help determine whether or not you need to compile those binaries, right? Right, exactly.
Good to know. Yeah, so we built it, but we're still not in the environment yet, because I still do which R. It's like, I don't know where R is. That is where the next command that's in my muscle memory after doing this, but after looking at the Rix documentation, it will be, you run nix-shell. This is where the magic happens. Notice my prompt changed a little bit. Now I've got this fancy thing called impure. It may look a little different on your system, but now if I do which R, check it out, and notice this is not the same R version as I had in that temporary shell that I did when I just built the config. This is an older version of R, because this is a version of R that was built for this specific project that I did that timestamp of like January, was that this year or last year when I built this.
Positron as a first-class Nix citizen
Now comes one of my favorite parts. Positron is a first-class customer to Nix environments. All you have to do, all you have to do is launch Positron in that shell and look at this R442. I did not have to configure Positron at all. It just works. I cannot emphasize how awesome this is. This is huge. This means you can have your favorite IDE, have your IDE installed globally on your system. I don't care. It could be if you're on Windows or Mac, you can have a default Positron instance, but you just launch it in your Nix shell and it will respect everything in that shell. I think this is just pure magic. That's why I'm so excited about it, because I literally do this every day when I'm developing a project and it just works. It is just mind-blowing stuff right here.
It just works. I cannot emphasize how awesome this is. This is huge. This means you can have your favorite IDE, have your IDE installed globally on your system.
This could also work with VS Code as well. If you're like hopping between other languages, Nix can be used for any language really. So you get the same benefit of VS Code for the RStudio users out there. Again, full respect. I still use RStudio for some of my projects. It's a little different because you have to almost compile RStudio in that same Nix shell, whereas in Positron and VS Code, that could be installed on your system no matter how it's installed. It can just be there and it will, as long as you launch those IDEs in the same Nix shell, you get the full benefits of it.
So to prove that this all works, this is the source Quarto doc of the calendar. I'm just going to do preview here, cross my fingers and nothing broke in my debugging, and there it is. That is the same calendar now running locally on my environment. And this answers one of our questions from Brent, which was how does this work with Quarto and Python code chunks? Because you are able to just spin up your IDE and run things, run any file that you would inside of that IDE, it works just fine. But if you have extra questions about the nitty gritty of that, Brent, definitely chime in and let me know. We can follow up.
Yeah, it's a wonderful point because you think, oh, wait, what is Quarto calling, right? Or what is our markdown calling? It's all in that shell. Again, think of this shell that I'm in as a completely different world from the rest of my system. And notice what I'll boot up now in a more friendly view, my build Nix config, I did put Quarto as a system dependency in this shell. I could have had Quarto as a default like application across my entire system. But this now means it's what I'm illustrating here is that I have achieved the project specific reproducibility with not just the packages and R, I have achieved it with Quarto as well.
In fact, we can do a new terminal here. We can do quarto version. And this is an older version because this was, again, built on an older version of the Nix package repository. So it pulled down an older version of Quarto, but it is all declared through both my friendly wrapper that Rix provides. And then it translates to the default.nix. Sorry for the syntax highlighting here, but you see here, the system packages are right here. I didn't have to add these myself. This is all automatic with Rix. Quarto, R, Pandoc, Nix itself, it's all here. So that way you can generalize this concept to other system frameworks that your analysis project might need. Maybe it's a Postgres database or a SQLite or DuckDB or who knows. You can all make that work here. It is absolutely amazing that, again, I can encapsulate both the R dependencies, and yes, Python works here too, as well as the system dependencies.
Transitive dependencies and the Nix store
So, yep, and we have one more question that's like along these lines, so I figured I'd ask. It's from nfolts and it says, does Rix handle the transitive dependencies, i.e. like how does it know, or does it just do the listed ones? And I think that that is part of what we're talking about in that chunk. Yeah, so it will look like when you look at a default.nix, it's only caring about these specific packages, but as we all know, these packages have dependencies. We know dplyr has quite a few dependencies, yada yada. There are, in the Nix package repository, a specific bucket of literal software packages called R packages. So, they actually mirror CRAN on a periodic basis and bring the entirety of CRAN over to Nix. Therefore, if I'm installing something like dplyr, this recipe of sorting, and think of this default.nix as, this recipe to declare that I want these packages, it is going to get all the dependencies for all the R packages in this list, and likewise for the system dependencies. It's going to get whatever dependencies Quarto has, or Pandoc has, or the like. It just all is a huge topology of networked packages in this Nix repository. You can just think of it of, it's all bundled all the time onto your system as, ironically, an area called the Nix store.
You can actually try to find where it is, and in fact, you can kind of get a glimpse of it if I do which Quarto here. You see this path, Nix, store, weird hash, Quarto, bin Quarto. Everything you build in Nix will go to some unique area in this store, and that's where it's all being built, but you as a user, even if you wanted to, you cannot blow this away. You can only interact with this with what Nix provides. You can't just go rm-rf, Nix store, blah blah blah. It's gonna say, nope, no, not allowed, no permission. That's where the immutable part comes in. This is where you can have insurance on your local machine, even if you build other things on your local machine, it's not gonna blow up on you.
Non-CRAN packages and Bioconductor
Well, we have a double question from both Brent and from Raha who say, what does this mean for packages that are not on CRAN, for example, like bioconductor packages which are very, very useful in pharma? Excellent point. I don't know about bioconductor being supported, however, and in fact, I think they're working on that. I do know that there are ways to install packages from GitHub or another Git-like repository. So that is, yep, installing packages from GitHub. That's where the syntax looks a little different. You have to be a little more verbose with this, where you have to give it a list of lists in this git underscore packages argument, the package name, where the repository is, and the actual commit that you want to draw from. Because what Rix will do is it will tell Nix, take this thing from GitHub and compile it from source. So that is a way to, at least for non-CRAN packages, and again I don't recall exactly for bioconductor, but if there is a package on another repository you can absolutely do this with GitHub or GitLab type of packages.
Unfortunately, the other well-known repository that I speak highly of, R-Universe, is not compatible with Nix. It's really CRAN only, as in the default Nix kind of package repository store. But with packages on a GitHub or GitHub-like platform, you can install them as well.
Oh, these are excellent questions, y'all. Thank you so much.
All right, what is next on our docket? We do have a couple more questions that I think are good for closer to the end, because they will be more about comparing other environments to Rix. But I will keep an eye on the chat.
Yep, so one of the things I mentioned as my enthusiasm for why I'm doing Nix a lot in my day-to-day work and my open source work is I have to interact with different systems.
I mentioned earlier we want this calendar to be updated on a regular basis, and I don't want to run that on my machine. You know, I got things to do. I want to use a cloud service for that, in this case GitHub Actions. So if this is your first time hearing about GitHub Actions, they're a way to tell GitHub that on specific events in your repository or on a scheduled basis, run some things for me. And it could be basically anything.
But what we do here is I have a GitHub Action, and we'll dive deep into this a little bit, to actually build the Quarto Dashboard of that calendar and then push it out to GitHub Pages. Under the hood, GitHub Actions are actually glorified containers, orchestrated by Docker most likely, that Microsoft hosts on their cloud servers.
Connection issues
And you can... Oh, Eric, I think you froze.
Both sound and picture. Let's see if we can get Eric back.
And then we have to remember what Eric was saying when he comes back. But let me see if I can.
Let's see. I'm gonna ping him in the actual chat here.
All right. I'm putting something in the Zoom chat for him. I'll check in with him on Discord. Everybody tag Eric.
Oh, well, in the meantime, please, please, lend us more of your questions here so that we can stack them up for Eric when he gets back.
I'm also curious if anybody has tried the other alternatives. Like, some folks have mentioned Arm.
There's RV, UVR, there's all sorts of things.
Oh, no. Wait. Kristy. Did I go away?
Or is Kristy aging you're in a way?
Okay, we might have lost Eric for a moment, but I think he's upcoming back. Everything's okay. We will hold on. Later I will be.
We will hold on. Later I will be leaving myself a post-it note to try to find this in the recording and edit it out and fix it. Okay, good. Brent says I'm here. Lauren says I'm here.
We're going to hope that we get Eric back and that Eric didn't lose some vital capabilities. He did say right when he had joined that there were, he was having Zoom problems, like his system was chronically restarting. So we hope that he comes back. We had a question, we had several questions actually when Isabella posted about this on LinkedIn about comparisons, how does this stack up to renv? How does this stack up to RV or UVR? I feel like UVR is the newer version of things instead of RV. I am not up to date on this. Y'all are going to have to tell me what you use and what you have played around with because I don't know.
Whoa, Isabella just put the biggest poll I have ever seen in the Discord chat. Which package managers do you use? Oh, for R specifically. I have only used renv or I do say REM sometimes just like when I'm trying to be quick. But if you have ever seen me or Tan Ho post about this on Blue Sky or anywhere else, we have just like a contiguous relationship with renv and I tend to fight with it a lot and really not enjoy the experience. No shade to anybody who loves renv or who gets along with it well. I've just experienced some nightmares developing Shiny in renv, which is a big struggle.
Wait, Eric's back. Okay, he's back, he's back, he's back. Here we go. I'm making Eric a host and maybe he can come back and share his screen.
I am so sorry. I knew I had a bad feeling about this.
I was telling them that beforehand you were saying your computer was acting up on you.
Well, it's a Zoom thing. I think I did end up re-destroying things.
I was asking like jokingly, oh, Eric must be on Linux and not Windows because I don't think this would play as nicely on Windows. But let me tell y'all, Zoom hates Linux.
They do. And I tried contingency. So I'm sorry for the editing you're about to have to do.
No worries. I can pick up where I left off.
I think it was only like five minutes too. We ran a poll in between this asking like what package manager people have experience with. Majority renv, but then also the other majority is absolutely nothing, which I think is really interesting. So 46% said renv, 42% said nothing at all, which was me for a really long time. I felt like using a reproducible environment or using a package manager at all was like not worth the trouble. So I'm glad that we're all learning more about it together.
Using Nix with GitHub Actions
Yep. So I will finish off my excitement about doing this on different systems. So I'm a podcast host. I can give you a good transition point.
So the nice thing about using Nix with GitHub Actions is that instead of relying on installing R itself in the GitHub Action in a different way than I did on my local environment, I can actually use actions that are provided by the top vendor that we often cite for installing Nix in the first place called Determinate Systems, where you can basically use this action that I call install Nix. And it's literally just a few lines. And I just had some stuff for logging if I needed it. And then within this, you can say, okay, use a cache of packages if you do this repeatedly. And then to build the system, or the build of the Nix dependency, you know, manifest is the exact same as my home environment, Nix-build. So it is literally in the GitHub Action YAML framework, the way to have that same way of building the environment as we had in my local setup. And then Bruno Rodriguez, to his credit, has its own version of GitHub Actions tailored to Nix in common workflows, such as publishing Quarto sites or Quarto's things. And there is a Quarto Nix GitHub Action that he's built, which will respect my environment and simply just run the right Quarto command to publish the GitHub pages. And boom, we got it. So in this case, yeah, it's a calendar app. It's not like a huge thing, right? But this should demonstrate to you that you could generalize this to any type of thing where you have to deploy or run your analyses or your application on a different system. And you want a way to make sure that particular project is using the same dependencies, the same both from the analytical side and your system level side as you were on your local setup. Nix has been the way I can achieve both. And again, you may not be in that same world I'm in, but I think it unlocks a lot of possibilities that are at play here. So that is why for this project, it probably was a case of over-engineering, but it was a great demonstration at the same time that with Quarto and a little bit of our logic, Nix can be a very valuable thing there too.
Nix has been the way I can achieve both. And again, you may not be in that same world I'm in, but I think it unlocks a lot of possibilities that are at play here.
Q&A: Nix on Windows
All right. Yeah, we can take over questions. I can show other things that we're capable of and mix whatever you like. Okay, fantastic. I've been storing up so many questions. Okay, let's do it. So the first one is, let's go back to the Linux versus Windows question for a second, because Jacques had asked, what is the status of Nix on Windows? I think so far it just works with Unix-based systems. Do you have any info on that?
Yes. So one thing to note is that with Windows, you have to install Nix on what's called WSL. That's called the Windows Subsystem for Linux, because as you correctly pointed out, this is a Unix-like utility where Mac is based in Unix, so you don't have to do this. But for Windows, you need to mock up a Linux or Unix type of environment, and WSL or WSL2 are going to be what you need to install it on Windows.
I wish, I really wish this was a native thing just to Windows, because I have ambitions of seeing where Nix can go in life sciences, but there is a barrier to getting R-based submissions to FDA and using any kind of additional technology, like even Docker and Nix, because the reviewers at a health authority don't necessarily have the privileges on their system to install WSL. So that is something to keep in mind if you're on a Windows environment that you may have to get IT help or think about what that means for you. But once you get WSL up and running, then it's that Determinate Systems Nix installer makes it super easy to get Nix on from that point on.
Q&A: Dev containers and Positron
Sweet. Thank you. Okay. We had talked a little bit in the chat about dev containers. I don't want to spend too much time on this, but Noor had asked, are dev containers analogous to Docker, or is she thinking about this wrong? I put a link in the Discord to the dev containers page for Positron so that people can go take a look. Dev containers are available in Positron. They were not for a while. We had to develop and work them in. But do you have a little explainer for Noor on dev containers in Positron slash VS Code and what they can be analogous to in her thinking?
Yeah, that's a great question, because I actually lived the dev container life for a long time when I was getting more involved in open source and sharing my adventures in open source back when I was doing those sometimes chaotic Shiny dev series live streams. Those environments were all dev containers, because at the time I didn't even know about Nix yet. Dev containers are a way for you to have a slightly less... It's still a little bit of a barrier of entry, but it basically turns your development environment into a container that's based on a specific JSON kind of setting file that you can put into your project that works natively with VS Code. And as you said, Positron is now able to support that as well. Again, containers can be a bit of a heavy footprint. You often get into permission issues. You want to bring in things from your other parts of your system, and they can take a long time to build depending on how big they are.
Oh no, Eric froze again. Well, Eric's not the only one who experiences large containers either. We had a couple of people in the chat, including Christy, who said like, yeah, containers can be really, really expensive as far as space to be able to use and run. In Positron, if you open a folder from the get-go, like just open folder, and it contains a .devcontainer.json file, you're going to get this little pop-up in Positron that's like, hey, Positron recognizes that you have a dev container in this, and it sees this dev container config file. Do you want to reopen this in a container, and it just does it for you, which is super great. So, if you are using dev containers, and you would like to use them in Positron, and you weren't able to before, I highly recommend you go check it out, because I think the experience is pretty solid.
Bye, Brent is going to see you. If anybody has to run, and you know that we only have like 13 minutes left, it is okay to run. We will very, very patiently hope that Eric comes back, but we know that he's having computer problems. We have more questions that went unanswered, and we also have like a little section at the end that we would like to talk about for deployment with Eric if he comes back, but we will follow up on Discord, and we will follow up on LinkedIn if we get some answers from Eric for some of these questions, which we would love to share with you.
One of them on LinkedIn was, what are your opinions on Rix versus devenv.sh, because it
sounds like Rix isn't our user's first step into Nix. I think that was from Gregory on LinkedIn, and then the other one was thoughts on the Rix-Nix combo versus UBR. So, if we do not get Eric back in a solid way, I think he's back. I'm back. I'm back. I'm so sorry. I'm on another system now, so I've switched systems. Oh, unbelievable. Okay. Do we want Eric to talk about, just answer questions about comparisons, or do you have stuff on this system that you can talk about deployment with? Because that was our last hopeful topic for the day, was like, you've made this thing. It is in a sandbox. What do you do with it now? How do you collaborate with it? How do you get back into it? How do you deploy it, give it to other people, the whole process of that?
Yeah, absolutely. Let me pull up my GitHub repo again while I share my screen here, and again, super apologies for the tech stuff. This has never happened to me before. Famous last words. I think I jinxed Eric, y'all, because when he popped up early, I was like, oh, Eric, you don't have to join early. I always know that your stuff will work, because Eric and I both do like podcasting stuff, and our cameras always look good, and our mics are always on lock, and he's like, oh no, Libby, you jinxed it. Now it's going to happen. It's my fault, y'all. I take full responsibility. You know, it's a sign of the times. We knew it would be chaotic today. We just didn't expect it to be chaotic in this way. There's always chaos at the lab.
That's the wrong screen. I apologize.
Nor, I did see your question pop up. I'm saving that one.
Okay, let me zoom in here a bit. This should not crash on me. Let's go back to Calendar.
Collaboration and deployment with Nix
With respect to, yeah, if you want to collaborate and share this with others, the best part about this is that all they really need to get started with this is to install Nix on their system. If they have Nix on their system, they can literally clone this, and this repo already has a default.nix already built in here, right? So they just have to clone this, run nix-build, and they will have everything bootstrapped for them. So yes, the prerequisite really is just having Nix on the system. Everything else is taken care of in this manifest here. That is why Nix is kind of considered a declarative programming model. It's all text-based. It's all in these scripts here, and the collaborators can easily deploy this on their system, their machine, their laptop, whatever have you, and you'll get that bit-for-bit reproducibility that if I'm working on this Calendar project and I have a collaborator in R Weekly working on their system, it just works for them. So that is the beauty of it. It may, over in Nix itself, that's all you really need to do it.
Amaze! Okay, so they are cloning a repo, they're running nix-build, and then they're good to go because... That's correct, yep. I would love to compare this to what can happen when you are using renv, and what the other person does is they clone your repo, and then what they need to do is run renv restore, and it's supposed to go grab all of the stuff that matches the versions of all of your R packages, and it is supposed to deploy or run your project, run that project on your system or whatever it is with everything working. But what can happen is if you have, let's say, GitHub packages of random things, you can put those into renv, no problem, right? But will you be able to actually get that random project back? Very unlikely, because so many GitHub R packages are not maintained, they don't have any versions, they just have one version that's updated all the time. But with Rix, you actually are signaling a commit, a single commit, so you are getting an actual version of code, and it's always going to be able to go back and get it. I have never experienced a good experience with that with renv, like that's a problem. I have had to manually edit lock files, like it can be such a mess. It can be even worse when you hop from one architecture to another. Don't get me started on going from like a Linux HPC environment of renv over to a Mac M1, or M chip renv.
But with Rix, you actually are signaling a commit, a single commit, so you are getting an actual version of code, and it's always going to be able to go back and get it.
Yes, absolutely. Good luck to you. I have had to attempt to run a Shiny app that was developed on an older Windows machine with an older version of Arrow and an older version of SF, and I just could not get it to work on my newer Mac machine, right? There was no way it was going to work, and it was built with all kinds of one-off GitHub packages, and so it was all about how can I refactor this code to skip all the GitHub packages, get the exact right version of these packages that actually don't run on this new Mac machine at all, like the older versions of Arrow I think didn't even run on Mac, because Mac is now ARM. It was just a huge mess. So I, in those instances, would have been saved by something like this.
Yep, and again, if you have the luxury of even being on the same system the whole time, or you have collaborators that are on the same system, you might be able to get away with it, but I think in due time, as systems become more capable and more complex, ARM was a major shift in the Mac ecosystem from Intel-based processors that our community had to catch up to that, and now they have caught up in a lot of it, but with Nix, and I'm not saying Nix is completely immune to all of that. There are some gotchas that you might get, but guess what? With Nix being a declarative, do you know who's really good at ingesting declarative type of programming? LLMs.
So you could have a nice even local-based LLM that knows Nix pretty well just because the resources have been out there for years and years, and it can get you out of some jams even with Nix if you find yourself in that. So it's an interesting time to learn even when things maybe not go quite as expected the first time you do it.
Yeah, and I think that there are some hang-ups and people are like, oh wait, but it's harder to use packages that are not on CRAN, right? And that might be a little bit of a barrier. It's also kind of a good thing that it pushes you towards CRAN packages or it pushes you towards things that are like more strictly version control. It kind of makes your development safer if you are pushed away from using those maybe unversioned, unsafer, or less safe packages. Unsafer is definitely not a word, Libby. But it sort of embraces that limit a little bit and you might be developing it more safely.
Absolutely, absolutely. And again, I will not even begin to act like I am the biggest expert in Nix. I know enough to be dangerous, you might say. I won't lie on my host system. I'm in Zoom making a crash all the time. I've actually been very impressed with what Nix has been able to do on my host system. And again, when I have gaps, I just get a little help from an agent and I get everything ready to go. It's kind of this new movement in DevOps to kind of take more control of your system. But I think for data science, we can kind of have that same mindset. When you need it, you'll know you'll need it. And now I have projects where I definitely need it.
Community questions
Well, you know, Dylan mentioned something in the chat, which is a fantastic challenge to what I just said, which is things like Stan aren't on CRAN. But are versions still nice? And like, do you have any experience with using Stan with Nix?
I recall one of my other projects, I think, was Yeah, as you said, I don't think it was on CRAN. So I had to go to the GitHub version of those Stan related packages. And then it would compile from source on an older system. That definitely took a while. But I think it eventually worked. It's been a couple of years since I did that. But when in doubt, try to find it on GitHub or get like online repository. And Nix with Rix can certainly do its best to handle that.
All right, fantastic. Let's hop over to a couple of questions in our last few minutes here. One of them was, if I can find it, from Noor just recently, which was, can you have RV and Rix installed on the same system? Or do they not play nice?
I have not. Actually, I think you can have them on the same system because there are different ways you can have Nix on your system. Ironically, the system on now is my work machine, where it's not a Nix OS system by any means. It's an Apple Mac OS, right? You can install the Nix package manager on a Mac or Windows and it will not conflict of anything else you have on your system. So you could absolutely have RV, UV on your host system and then have that have Nix play its own way and they don't talk to each other. So you could absolutely have them. I don't think you could mix RV inside a Nix shell like I was doing with the Calendar project. I think you would just have to treat them totally separate from on your system, but they can be there. They don't have to be angry at each other. They can coexist.
Okay, cool. And we had a question that was from LinkedIn. That was, do you have any thoughts on a comparison between Rix and devenv.sh, which I just put in the Discord, but you might not have experience with it. I don't know.
So I have definitely heard about devenv and I think they're trying to tackle a very similar way of approaching Nix. As we were talking about earlier with the dev container question, how Microsoft tried to approach Docker with dev containers. It's an alternative syntax to get into opting into installing stuff with Nix. So you could say it's got its own DSL of sorts that tries to be a bit more, I guess, kind of analogous to JSON or you might say YAML like and tries to take care of a lot of things for you. I have not tried with devenv with any R project, but I've heard good things about it. And maybe if you're doing multiple systems, it might be an interesting way to go.
What I do have experience with is that you saw in my demo how I had to run that nix-shell command when I wanted to launch into that Nix environment after I built it. There is a project called durenv that basically when you install that and you from a terminal kind of change into that project area, it'll run that Nix shell stuff for you. So you don't have to necessarily do that. And then when you exit out of that shell, it'll put your system back to normal. So that one, that's kind of nice. And Bruno likes that a lot. And he did that in one of his previous workshops. I haven't done it as much as because Nix-shell is not that difficult for me to type. But yeah, I could see why that might get annoying to some people. So I have done durenv, but I haven't done much with devenv yet. So that's a good question.
Well, thank you so much. I think that was a Gregory question. Gregory says devenv does the activation that you used to have to use durenv for. So that's kind of nice. Yeah, thank you, Gregory. We'll have to have Gregory come tell us all about devenv.
Okay, this has been chaotic, but great. Thank you for teaching us all about reproducible environments in Nix using the Rix R package. Thank you to Bruno for all of his work with development. He's not here, but thanks Bruno for all that you've done.
And I want to recognize that bioconductor packages are also very, very valuable, but not on CRAN. If anybody does not know about bioconductor, it's almost 2,500 packages, I think. They have to go through their own vetting process. There is, yep. It's a whole ecosystem. Definitely go Google bioconductor. You will know that you have a use case for a bioconductor package because they're very niche, but they are powerful and amazing, and it's a whole own thing. So definitely go check out bioconductor.
Eric, this was really fun. Thank you so much for joining us. Despite coming in and out and problems, thank you for rejoining and enjoying it on another system. If anybody has follow-up questions or a thank you for Eric, you can tag him in the Discord, and we will absolutely, you know, try to follow up with what we can.
