Jump to content

Hugo: Difference between revisions

From NixOS Wiki
Theming: typo
Layer-09 (talk | contribs)
Cleaned up and clarified the page
Line 1: Line 1:
'''[https://gohugo.io Hugo]''' is one of the most popular open-source static site generators.
<languages/>
<translate>
<!--T:1-->
'''Hugo''' is a static site generator written in Go. It builds websites from content files and templates, supporting features such as Markdown content, themes, and flexible deployment options. Hugo is available in the NixOS ecosystem and can be used for a variety of web publishing tasks.<ref>https://gohugo.io/documentation/</ref>
</translate>


The easiest way to use Hugo on NixOS is to add Hugo to the <code>environment.systemPackages</code> attribute:
== Installation ==
{{file|configuration.nix|nix|<nowiki>
{ pkgs, ... }: {
  environment.systemPackages = [
    pkgs.git
    pkgs.hugo
  ];
}
</nowiki>}}
{{Evaluate}}


You can now follow the [https://gohugo.io/getting-started/quick-start/ Hugo Quick Start] guide, as not much is different from running Hugo on other Linux distributions.


=== Development Shell ===
==== 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.
<translate>
{{file|shell.nix|nix|<nowiki>
<!--T:2-->
{ pkgs ? import <nixpkgs> {} }:
To temporarily use Hugo in a shell environment, you can run:
  pkgs.mkShellNoCC {
</translate>
    packages = [
<syntaxhighlight lang="bash">
      pkgs.hugo
nix-shell -p hugo
      # Other dependencies for your project.
</syntaxhighlight>
    ];
  }
</nowiki>}}


To avoid having to type <code>nix-shell</code> or <code>nix develop</code> to access the development shell, consider [[Direnv|enabling nix-direnv]].
<translate>
<!--T:3-->
This will provide a shell with Hugo available without adding it to your system configuration.
</translate>


=== Theming ===
==== System setup ====


Nix can be used to deterministically import themes by pinning them to a specific revision and linking the resulting derivation:
<translate>
<!--T:4-->
To install Hugo, add it to either the system-wide <code>environment.systemPackages</code> in <code>/etc/nixos/configuration.nix</code> or to the user-specific <code>home.packages</code> in <code>~/.config/nixpkgs/home.nix</code>.<ref>https://nixos.org/manual/nixos/stable/</ref>
</translate>
<syntaxhighlight lang="nix">
# System-wide installation (in /etc/nixos/configuration.nix)
environment.systemPackages = with pkgs; [
  hugo
  git # Useful for managing Hugo themes and site repositories
];


{{file|shell.nix|nix|<nowiki>
# User-specific installation (in ~/.config/nixpkgs/home.nix)
{ pkgs ? import <nixpkgs> {} }: let
home.packages = with pkgs; [
  hugo-theme = pkgs.fetchFromGitHub {
  hugo
    owner = "vaga";
  git
    repo = "hugo-theme-m10c";
];
    rev = "862c6e941be9bc46ce8adc6a2fa9e984ba647d6f";
</syntaxhighlight>
    hash = "sha256-wcJSGjL/u43hPLblPmUhusqiMmadVBWJhihRinRXqzg=";
  };
in
  pkgs.mkShellNoCC {
    packages = [
      pkgs.hugo
      # Other dependencies for your project.
    ];


    shellHook = ''
<translate>
      mkdir -p themes
<!--T:5-->
      ln -snf "${hugo-theme}" themes/m10c
Then, rebuild your system or apply your Home Manager configuration:
    '';
</translate>
  }
<syntaxhighlight lang="bash">
</nowiki>}}
# For system-wide installation
sudo nixos-rebuild switch


The theme can be activated using <code>hugo new site . --force</code>, after creating a <code>hugo.toml</code> file similar to the following:
# For Home Manager
home-manager switch
</syntaxhighlight>


{{file|hugo.toml|toml|<nowiki>
== Configuration ==
baseURL = 'https://example.com/'
 
languageCode = 'en-us'
 
title = 'example-site'
==== Basic ====
theme = 'm10c'
 
</nowiki>}}
<translate>
<!--T:8-->
Basic Hugo configuration involves creating a new site and choosing themes. Use the following command to create a new Hugo site:
</translate>
<syntaxhighlight lang="bash">
hugo new site my-site
</syntaxhighlight>
<translate>
Navigate to the site directory and add a theme as a git submodule or download it directly. For detailed steps, refer to the official Hugo documentation.
</translate>
 
==== Advanced ====
 
<translate>
<!--T:9-->
{{Expansion|reason=Section incomplete, needs detailed content on advanced configuration with NixOS}}
</translate>
 
== Tips and tricks ==
 
<translate>
<!--T:10-->
{{Expansion|reason=Section incomplete, needs more tips and tricks}}
</translate>
 
== Troubleshooting ==
 
<translate>
<!--T:11-->
{{Expansion|reason=Section incomplete, needs detailed troubleshooting steps}}
</translate>
 
== References ==


[[Category:Applications]]
[[Category:Applications]]
[[Category:Server]]
[[Category:Server]]

Revision as of 06:53, 19 May 2025

Hugo is a static site generator written in Go. It builds websites from content files and templates, supporting features such as Markdown content, themes, and flexible deployment options. Hugo is available in the NixOS ecosystem and can be used for a variety of web publishing tasks.[1]

Installation

Shell

To temporarily use Hugo in a shell environment, you can run:

nix-shell -p hugo

This will provide a shell with Hugo available without adding it to your system configuration.

System setup

To install Hugo, add it to either the system-wide environment.systemPackages in /etc/nixos/configuration.nix or to the user-specific home.packages in ~/.config/nixpkgs/home.nix.[2]

# System-wide installation (in /etc/nixos/configuration.nix)
environment.systemPackages = with pkgs; [
  hugo
  git # Useful for managing Hugo themes and site repositories
];

# User-specific installation (in ~/.config/nixpkgs/home.nix)
home.packages = with pkgs; [
  hugo
  git
];

Then, rebuild your system or apply your Home Manager configuration:

# For system-wide installation
sudo nixos-rebuild switch

# For Home Manager
home-manager switch

Configuration

Basic

Basic Hugo configuration involves creating a new site and choosing themes. Use the following command to create a new Hugo site:

hugo new site my-site

Navigate to the site directory and add a theme as a git submodule or download it directly. For detailed steps, refer to the official Hugo documentation.

Advanced

☶︎
This article or section needs to be expanded. Section incomplete, needs detailed content on advanced configuration with NixOS Further information may be found in the related discussion page. Please consult the pedia article metapage for guidelines on contributing.

Tips and tricks

☶︎
This article or section needs to be expanded. Section incomplete, needs more tips and tricks Further information may be found in the related discussion page. Please consult the pedia article metapage for guidelines on contributing.

Troubleshooting

☶︎
This article or section needs to be expanded. Section incomplete, needs detailed troubleshooting steps Further information may be found in the related discussion page. Please consult the pedia article metapage for guidelines on contributing.

References