Articles tagged #nix
Extra credit
We've achieved our goals already with this series: we have a web service written in Rust, built into a Docker image with nix, with a nice dev shell, that we can deploy to fly.io.
But there's always room for improvement, and so I wanted to talk about a few things we didn't bother doing in the previous chapters.
Making clash-geoip
available in the dev shell
Generating a docker image with nix
There it is. The final installment.
Over the course of this series, we've built a very useful Rust web service that shows us colored ASCII art cats, and we've packaged it with docker, and deployed it to https://fly.io.
We did all that without using nix
at all, and then in the last few chapters,
we've learned to use nix
, and now it's time to tell goodbye,
along with this whole-ass :
Making a dev shell with nix flakes
In the previous chapter, we've made a nix "dev shell" that contained the fly.io command-line utility, "flyctl".
That said, that's not how I want us to define a dev shell.
Our current solution has issues. I don't like that it has import <nixpkgs>
.
Which version of nixpkgs
is that? The one you're on? Who knows what that is.
Learning Nix from the bottom up
Remember the snapshot we made allll the way back in Part 1? Now's the time to use it.
Well, make sure you've committed and pushed all your changes, but when you're ready, let's go back in time to before we installed anything catscii-specific in our VM.
This should emulate the experience of a colleague onboarding onto the project well enough!
Building a Rust service with Nix
I often give bits and pieces of advice on how to build Rust stuff the comfy way. But it can be hard to see how everything comes together, especially when it comes to, say, deploying a web service in production.
So, let's start from the very beginning (setting up a Linux VM), and march together towards the objective: a production-grade Rust web service, built with Nix.
Trying to use nix
Now that my website is deployed as a container image, I wanted to give
nix a try. I'm still doing it the old-fashioned way right
now: with a Dockerfile
, running cargo
in a "builder" image, copying stuff
out of there into a slimmer image (that still has an Ubuntu base, even though
distroless images are a
thing now).
But why?
I was mostly interested in nix because some parts of my website have pretty big native dependencies. itself mostly relies on sqlite3 and some JS engine (used to be quickjs, currently duktape because MSVC Windows builds). But the asset processing pipeline, (which I'd like to integrate with at some point) has a bunch more!
Go back to the homepage.