Skip to content

Commit

Permalink
build: add nix flake (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjshearer committed Jun 17, 2024
1 parent b188cfb commit 991f5e0
Show file tree
Hide file tree
Showing 15 changed files with 2,223 additions and 2,310 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
12 changes: 3 additions & 9 deletions .github/actions/setup-runner/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ description: Install dependencies shared by all jobs
runs:
using: "composite"
steps:
- run: corepack enable
shell: bash
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version-file: package.json
cache: pnpm
- run: pnpm install --frozen-lockfile
shell: bash
- uses: DeterminateSystems/nix-installer-action@v12
- uses: DeterminateSystems/magic-nix-cache-action@v7
- uses: DeterminateSystems/flake-checker-action@v8
12 changes: 7 additions & 5 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-runner
- name: Setup Pages
id: pages
uses: actions/configure-pages@v3
uses: actions/configure-pages@v5
- name: Build
run: pnpm build --baseURL ${{ steps.pages.outputs.base_url }}
# HACK: https://github.com/NixOS/nix/issues/5663#issuecomment-2010521981
# see baseURL input in flake.nix for more details
run: nix build --override-input baseURL file+file://<(printf %s "${{ steps.pages.outputs.base_url }}")
- if: github.ref == 'refs/heads/main'
name: Upload Artifact
uses: actions/upload-pages-artifact@v2
uses: actions/upload-pages-artifact@v3
with:
name: build
path: build
path: result
retention-days: 1
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ jobs:
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
uses: actions/deploy-pages@v4
with:
artifact_name: build
6 changes: 3 additions & 3 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-runner
- name: Check Linting and Formatting
run: |
pnpm lint:check & pnpm format:check
shell: bash
run: nix develop .#default --command bash -c "pnpm format:check && pnpm lint"
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
build
result
public
resources
node_modules
hugo_stats.json

*.crt
*.key
*.key

.direnv
5 changes: 4 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ pnpm-lock.yaml
layouts/**/*.md
layouts/partials/imgh.html
layouts/resume/_markup/render-heading.html
build
build

.direnv
result
12 changes: 7 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
{
"css.validate": false,
"editor.codeActionsOnSave": {
"source.fixAll": "explicit"
},
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"eslint.format.enable": true,
"eslint.rules.customizations": [
{
"rule": "*",
"severity": "warn"
}
],
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"eslint.format.enable": true,
"css.validate": false,
"stylelint.configFile": ".stylelintrc.yaml",
"stylelint.validate": ["css"],
"yaml.schemaStore.enable": false
"[nix]": {
"editor.defaultFormatter": "jnoortheen.nix-ide"
}
}
74 changes: 19 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,72 +4,36 @@ _A minimal static resume builder; inspired by [sproogen's modern-resume-theme](h

_Host your own resume on GitHub for free!_

## Repository Setup
## Setup

### Remote Repository

1. [Fork](https://github.com/cjshearer/modern-hugo-resume/fork) this repository, naming it `<your_username>.github.io`.
2. In your new repository, go to `Settings > Pages` and under "Build and deployment" select "GitHub Actions" as the source.
3. Go to `Actions` and click "Enable workflows".

When you update the `main` branch of your repository with your information, the resume will automatically be built and deployed to `https://<your_username>.github.io`.

4. [optional] If you just want to see the page deployed now, without updating the resume content, you can manually trigger the build and deploy workflow by going to `Actions > ./github/workflows/deploy.yaml` and clicking "run workflow".

## Local Usage

### Prerequisites

#### Node

We recommend installing the latest version (or at least 16) of Node with [nvm](https://github.com/nvm-sh/nvm).

[Windows]: You'll need to use [nvm-windows](https://github.com/coreybutler/nvm-windows) if you want to use nvm.

#### Git

You probably already have this.

[Windows]: Install with `winget install -e --id Git.Git`

### Setup

Clone the repository:

```sh
git clone git@github.com:<your_username>/<your_username>.github.io.git
```

We use [corepack](https://nodejs.org/api/corepack.html) (comes with Node >= 16)
to manage `pnpm`. To install, run the following from the project's root
directory.
3. Go to `Actions` and click "Enable workflows". When you next push to the `main` branch of your repository, the resume site will automatically be built and deployed to `https://<your_username>.github.io`.

[Windows]: You may need to run the following with elevated privileges. For a convenient way to do this, install gsudo with `winget install -e --id gerardog.gsudo` and prepend `gsudo` to the following command:
> [!TIP]
> You can also trigger the workflow to build and deploy the website by going to `Actions > ./github/workflows/deploy.yaml` and clicking "run workflow".
```sh
corepack enable
```
### Local Repository

To install the project dependencies, run the following command from the project's root directory:
#### With [Nix](https://nixos.org/download/)

```sh
pnpm install
```
Run `nix develop` (or install [nix-direnv](https://github.com/nix-community/nix-direnv)).

## Local Development
#### Without Nix

To make changes and instantly see them at http://localhost:1313, run:
1. Install [`hugo`](https://gohugo.io/installation/) 1.27.0+extended.
2. Install `node` >= 20.2.0 with [nvm](https://github.com/nvm-sh/nvm).
3. Install `pnpm` with `corepack enable`.
4. Run `pnpm install`.

```sh
pnpm dev
```
## Development

To make the server accessible over tailscale, run
### Rebuild on file change

```sh
pnpm dev:tailscale
```
To rebuild changes automatically, run `pnpm dev`.

To create a production build, run:
### Build

```sh
pnpm build
```
To create a production build, run `pnpm build`.
74 changes: 74 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
description = "modern-hugo-resume";

inputs = {
nixpkgs.url = "github:NixOs/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";

# HACK: enable build argument with https://github.com/NixOS/nix/issues/5663#issuecomment-2010521981
baseURL.url = "file+file:///dev/null";
baseURL.flake = false;
};

outputs = { self, nixpkgs, flake-utils, baseURL }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
hugo = pkgs.hugo;
nodejs = pkgs.nodejs_22;
pnpm = pkgs.pnpm;
nativeBuildInputs = [ nodejs hugo pnpm ];
in
{
packages.default = pkgs.stdenv.mkDerivation (finalAttrs: {
pname = "modern-hugo-resume";
name = finalAttrs.pname;

src = ./.;

nativeBuildInputs = nativeBuildInputs ++ [ pnpm.configHook ];

pnpmDeps = pnpm.fetchDeps {
inherit (finalAttrs) pname src;
hash = "sha256-LopdAXf7EScCbyXQ0op6xohdv6vRPdNQrVzIRxOvAG0=";
};

postBuild = ''
pnpm run build --baseURL=${builtins.readFile baseURL}
'';

installPhase = ''
cp -r build $out
'';

# used by lint workflow so we can use cached pnpm deps
shellHook = ''
pnpmConfigHook
'';
});

devShell = pkgs.mkShell { inherit nativeBuildInputs; };
});
}
5 changes: 0 additions & 5 deletions layouts/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,4 @@
{{ else }}
<link href="{{ $styles.RelPermalink }}" rel="stylesheet" />
{{ end }}

{{ if .Site.GoogleAnalytics }}
{{ template "_internal/google_analytics.html" . }}
{{ template "_internal/google_analytics_async.html" . }}
{{ end }}
</head>
17 changes: 5 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
"@fortawesome/fontawesome-free": "^6.4.2",
"@fullhuman/postcss-purgecss": "^5.0.0",
"@tailwindcss/typography": "^0.5.10",
"@types/node": "^20.8.9",
"autoprefixer": "^10.4.16",
"hugo-bin": "^0.116.3",
"lint-staged": "^13.3.0",
"postcss": "^8.4.31",
"postcss-cli": "^10.1.0",
Expand All @@ -27,13 +25,9 @@
"engines": {
"node": ">=20.2.0",
"npm": "please-use-pnpm",
"pnpm": "8.6.7",
"pnpm": "9.1.1",
"yarn": "please-use-pnpm"
},
"hugo-bin": {
"buildTags": "extended"
},
"keywords": [],
"lint-staged": {
"*": [
"pnpm prettier --write --ignore-unknown"
Expand All @@ -42,21 +36,20 @@
"pnpm stylelint --fix"
]
},
"name": "cjshearer.github.io",
"packageManager": "pnpm@8.6.7",
"name": "modern-hugo-resume",
"packageManager": "pnpm@9.1.1",
"scripts": {
"build": "pnpm run hugo:build",
"clean": "pnpm run hugo:clean && rm -rf node_modules",
"dev": "pnpm run hugo:serve",
"dev:tailscale": "./tailscale-dev.sh",
"format": "pnpm prettier .",
"format:check": "pnpm format --check",
"format:fix": "pnpm format --write",
"format": "pnpm prettier .",
"hugo:build": "hugo -d build --minify",
"hugo:clean": "rm -rf build resources public",
"hugo:serve": "hugo server",
"lint:fix": "pnpm lint --fix",
"lint": "pnpm stylelint **/*.{html,css}",
"lint:fix": "pnpm lint --fix",
"prepare": "simple-git-hooks"
},
"simple-git-hooks": {
Expand Down
Loading

0 comments on commit 991f5e0

Please sign in to comment.