Avatar

Francisco Moschetti

Uruguay.
Web developer alergic to leetcode.

Back to blog

How I use nix in my dev workflow.

So I’ve been using NixOS as my daily driver for 6 months now, and I have to say that im surprised with how smooth my experience has been so far.

My biggest fear was that it was going to get in my way while trying to do work but luckly I was completly wrong about this.

In fact, I think it made me more productive and gave me more confidence on my setup to work on multiple languages and environments in a easy and safe way.

The main benefit of NixOS is that once you have a decent setup, it takes little work to mantain or update.

During this time I’ve experimented with different nix features and I finally landed on an approach that lets me work on multiple languages in a easy way.

The approach

I’m no expert when it comes to nix, so I try to keep it simple.

Instead of building per project shells, I have dedicated flakes to work with languages and runtimes.

The dependencies of any given project will be managed by their respective package manager, the only thing i do with the flake is have it so the system level stuff needed is there only when i need it.

For example, here is my flake to work with GO, ready to do anything from web dev stuff to mess around with raylib-go bindings.

If I need to work on a project that requires an older GO version, I just need to duplicate this flake, go to nixhub, grab the release I need and paste it in the inputs.


{
  description = "Flake to use GO for web stuff and gamedev.";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
  };

  outputs = { self, nixpkgs, ... }@inputs:

    let
       system = "x86_64-linux";
       pkgs = nixpkgs.legacyPackages.${system};
    in
    {
     devShells.${system}.default = pkgs.mkShell {
      packages = [
        pkgs.go
        pkgs.gopls
        pkgs.golangci-lint-langserver
        pkgs.pkgsCross.mingwW64.buildPackages.gcc
        pkgs.pkgsCross.mingwW64.buildPackages.pkg-config
        #web dev stuff
        pkgs.templ
        pkgs.air
        #raylib
        pkgs.libGL
        pkgs.wayland
        pkgs.libxkbcommon
        pkgs.xorg.libXi
        pkgs.xorg.libXrandr
        pkgs.xorg.libXinerama
        pkgs.xorg.libXcursor
        pkgs.alsa-lib 
        pkgs.openal
        pkgs.pulseaudio
        pkgs.pkg-config
      ];
     };
   };
}

What I want to do next

I want to explore how to use NixOS for production.

I saw that you can create custom images in Digital Ocean.

The idea is to have a couple of VPS templates ready to use with proper ports and firewall setup plus dependencies like traefik and docker to spin up consistent production environments for my projects.