Hugo
Hugo is one of the most popular open-source static site generators.
The easiest way to use Hugo on NixOS is to add Hugo to the environment.systemPackages
attribute:
{ pkgs, ... }: {
environment.systemPackages = [
pkgs.git
pkgs.hugo
];
}
$ nixos-rebuild switch --use-remote-sudo
You can now follow the Hugo Quick Start guide, as not much is different from running Hugo on other Linux distributions.
Development Shell
You may, however, want to limit the installation to your Hugo-specific projects. This makes it possible for you or others to download your repository and work with its dependencies, since they are fully specified within the project.
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShellNoCC {
packages = [
pkgs.hugo
# Other dependencies for your project.
];
}
To avoid having to type nix-shell
or nix develop
to access the development shell, consider enabling nix-direnv.
Theming
Nix can be used to deterministically import themes by pinning them to a specific revision and linking the resulting derivation:
{ pkgs ? import <nixpkgs> {} }: let
hugo-theme = pkgs.fetchFromGitHub {
owner = "vaga";
repo = "hugo-theme-m10c";
rev = "862c6e941be9bc46ce8adc6a2fa9e984ba647d6f";
hash = "sha256-wcJSGjL/u43hPLblPmUhusqiMmadVBWJhihRinRXqzg=";
};
in
pkgs.mkShellNoCC {
packages = [
pkgs.hugo
# Other dependencies for your project.
];
shellHook = ''
mkdir -p themes
ln -snf "${hugo-theme}" themes/m10c
'';
}
The theme can be activated using hugo new site . --force
, after creating a hugo.toml
similar to the following:
baseURL = 'https://example.com/'
languageCode = 'en-us'
title = 'example-site'
theme = 'm10c'