Welcome to Stuce’s website

This website serves as a collection of cool stuff I do related to computer science during my free time.

It might also some day be extended to work as a landing page for my other services on this domain.

Easy devops with nix and Yesod

I did a website with Nix, and Yesod, a framework in Haskell.

I actually ran into multiples issues :

Sadly, by using the default toolchain, (Stack and a DockerFile), I would need to maintain a way to build my server in multiple ways. So I decided to just use nix instead.

Where Nix really doesn’t shine is in its documentation (yet!). I did need a lot of research to actually setup the tools properly : Stack needs to have ghc installed with all the proper dependencies to work, and it is needed by the development server provided by the Yesod framework.

Simply creating a shell with pkgs.haskellPackages.callCabal2nix ./. {} does not work, since it doesn’t provide GHC with the packages in a way that Stack can see, which will force it to re-download the whole toolchain. So I needed actually use

pkgs.haskellPackages.ghcWithPackages
(pkgs: myPkg.getCabalDeps.libraryHaskellDepends);

in my shell to actually be able to use yesod devel.

Generally, to make a docker, we try to build inside a first docker, and then copy everything to a smaller image, generally alpine, and try to uninstall everything that isn’t needed. This is in fact often harder than just finding all dependencies to build with nix, and then create a distroless image with nix. Only problem is that I got an image around 40mb bigger since I didn’t use musl, and nix’s glibc is pretty big. I could easily by replacing pkgs with pkgs.musl in my flake compile it for musl, but it takes a few hours to recompile every dependency, and I deem it not worth the trouble as I will only deploy one instance. (If we had a cachix instance and wanted to deploy multiple instances, theses drawbacks would become meaningless.)

This website’s generator

Although technologies like Hugo or Jekyll sound appealing, I wanted to use technologies I already know of and do it in a more DIY fashion, so I ended up using typix, which is a framework to use typst with nix.

This allows certain things like specifying fonts declaratively (not yet supported by typst at time of writing) and get me a formatter and an lsp by simply typing nix develop

Then since doing nix build give me a nix derivation. This derivation can then be installed in my nixos server and served with a webserver like nginx in around 10 lines of configuration.

Another advantage of this approach would be if I ever have coworkers on the project (hypothetically), they just know they can compile it using nix run, and there is no need to learn how the build tool works (in this case no need to learn the typst watch command).

And since I use typst, it will be easy to just use it’s ecosystem to create graphs and other visuals, as although I want the site simple, it doesn’t mean it can’t get cool visuals !

One of the goals is to be able to add tags, to sort the articles by interest, and maybe make the project multi files later on if performance requests it. (Aka file gets too big to be served fast)