Skip to content

Commit

Permalink
Merge pull request #279 from pankona/hugo-build-with-nix
Browse files Browse the repository at this point in the history
Install tools to use hugo with Nix to avoid unstable snap
  • Loading branch information
pankona authored Apr 4, 2024
2 parents e6e0f51 + a417e55 commit f457208
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 21 deletions.
28 changes: 9 additions & 19 deletions .github/workflows/generate_site_and_deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,33 @@ defaults:
jobs:
build:
runs-on: ubuntu-latest
env:
# Keep same version with `make deps`
HUGO_VERSION: 0.124.1
steps:
- name: Install Hugo CLI
run: |
wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \
&& sudo dpkg -i ${{ runner.temp }}/hugo.deb
- name: Install Dart Sass
run: sudo snap install dart-sass
- name: Checkout
uses: actions/checkout@v4
# Required go env because hugo module depends on it
- name: Cache hugo resources
uses: actions/cache@v4
with:
path: /home/runner/.cache/hugo_cache
key: ${{ runner.os }}-hugo-v${{ env.HUGO_VERSION }}-hugomod-${{ hashFiles('go.sum') }}
key: ${{ runner.os }}-flake-${{ hashFiles('flake.lock') }}-hugomod-${{ hashFiles('go.sum') }}
restore-keys: |
${{ runner.os }}-hugo-v${{ env.HUGO_VERSION }}-hugomod-
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache-dependency-path: 'go.sum'
${{ runner.os }}-flake-${{ hashFiles('flake.lock') }}-hugomod-
- name: Setup Pages
id: pages
uses: actions/configure-pages@v5
- uses: DeterminateSystems/nix-installer-action@v10
- uses: DeterminateSystems/magic-nix-cache-action@v4
- name: Build hugo-nix to measure how longtime used to build
run: 'nix run .#hugo-nix -- version'
- name: Install Node.js dependencies
run: "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true"
run: "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && nix develop --command npm ci || true"
# Required go env before this step because hugo module depends on it. Now whole setup is completed with Nix
- name: Build with Hugo
env:
# For maximum backward compatibility with Hugo modules
HUGO_ENVIRONMENT: production
HUGO_ENV: production
run: |
hugo --panicOnWarning \
nix run .#hugo-nix -- --panicOnWarning \
--gc \
--minify \
--baseURL "${{ steps.pages.outputs.base_url }}/"
Expand Down
25 changes: 23 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,31 @@
nixpkgs-fmt
vim

edge-pkgs.dprint

edge-pkgs.hugo
edge-pkgs.go_1_22
edge-pkgs.dprint
dart-sass
];
};
});

apps = {
hugo-nix = {
type = "app";
program = with pkgs;lib.getExe (writeShellApplication
{
name = "hugo-with-dependencies";
runtimeInputs = [
edge-pkgs.hugo
edge-pkgs.go_1_22
dart-sass
];
text = ''
hugo "$@"
'';
});
};
};
}
);
}

0 comments on commit f457208

Please sign in to comment.