I like to keep this website extremely simple and not just from a design perspective, but from a maintenance perspective too.

I don’t want to spend all my time trying to maintain this website and that’s why I ended up picking Hugo so long ago and I’ve stuck to it (as well as for my other websites like 0xa.io).

However, when you’re not actively maintaining software it eventually starts rotting underneath you. You must do some minimal maintenance so it doesn’t creep up on you and require a drawn out migration or expensive rewrite.

I have spoken before about how much I like Nix and you shouldn’t be surprised that I used Nix and Flakes for this website too.

The Flake Config Link to heading

I had an existing Hugo website, but if you don’t have one already we’ll be able to create one once we setup the nix develop environment.

Since flakes are still experimental make sure to enable them

{
  description = "Personal website for Chris Portela";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs";
    utils.url = "github:numtide/flake-utils";
    hugo-coder = {
      url = "github:luizdepra/hugo-coder";
      flake = false;
    };
  };

  outputs = inputs@{ self, nixpkgs, utils, ... }:
    utils.lib.eachSystem [
      utils.lib.system.x86_64-darwin
      utils.lib.system.x86_64-linux
      utils.lib.system.aarch64-darwin
      utils.lib.system.aarch64-linux
    ]
      (system:
        let
          pkgs = import nixpkgs {
            inherit system;
          };
        in
        rec {

          packages.website = pkgs.stdenv.mkDerivation {
            name = "website";
            src = self;
            buildInputs = [ pkgs.git pkgs.nodePackages.prettier ];
            buildPhase = ''
              mkdir -p themes
              ln -s ${inputs.hugo-coder} themes/hugo-coder
              sed -i -e 's/enableGitInfo = true/enableGitInfo = false/' config.toml
              ${pkgs.hugo}/bin/hugo
              ${pkgs.nodePackages.prettier}/bin/prettier -w public '!**/*.{js,css}'
            '';
            installPhase = "cp -r public $out";
          };

          defaultPackage = self.packages.${system}.website;

          apps = rec {
            hugo = utils.lib.mkApp { drv = pkgs.hugo; };
            default = hugo;
          };

          devShell =
            pkgs.mkShell { buildInputs = [ pkgs.nixpkgs-fmt pkgs.hugo ]; };
        });
}

The source for this website is private, but if you could clone it then all you’d need to do to build the website locally is run nix build. Other flakes, like the one for my dedicated server can simply make my website’s flake an input and use the website package in the outputs to get the static files needed to host the site via Nginx (or whatever).

To actually be able to use hugo for things like hugo new you can just run nix develop and you’ll have both hugo and nixpkgs-fmt avalible in your terminal.

The beauty of this too is that because of the flake.lock all these dependencies are locked at a known working point. I can obviously keep it updated pretty easily using nix flake update, but if for whatever reason hugo had a major change I could simply not update right away and continue being able to build my website on any of my computers; including the dedicated server which hosts it.