Skip to content

Commit

Permalink
build: ignore unused files in nix build
Browse files Browse the repository at this point in the history
To avoid unnecessary rebuilds, we now ignore
unused files from the build src.
  • Loading branch information
cjshearer committed Jun 25, 2024
1 parent 4d11600 commit 2a701eb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ GitHub Actions is configured to build the site using Nix. Now that your site is

Nix also requires the expected hash of downloaded dependencies. Now that `modern-hugo-resume` is imported, you will need to update this hash. Follow the instructions above `outputHash` in [`flake.nix`](./flake.nix).

See [`cjshearer.dev/flake.nix`](https://github.com/cjshearer/cjshearer.dev/blob/77b6e94990ca1f7168760a41ea3ee7e9b3745b17/flake.nix) for reference.
See [`cjshearer.dev/flake.nix`](https://github.com/cjshearer/cjshearer.dev/blob/9b49eaef33ed9fb4d8726f6578085d76145c3d1a/flake.nix) for reference.

```diff
# flake.nix
- sourceRoot = "exampleSite";
+ sourceRoot = ".";
- buildFolder = "exampleSite";
+ buildFolder = ".";
...
- pname = "modern-hugo-resume-exampleSite"
+ pname = "<your username>.github.io"
Expand Down
27 changes: 21 additions & 6 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
nodejs = pkgs.nodejs_22;
pnpm = pkgs.pnpm;
nativeBuildInputs = [ go hugo nodejs pnpm ];
sourceRoot = "exampleSite";
buildFolder = "exampleSite";
in
{
checks = {
Expand All @@ -38,21 +38,36 @@
# TODO: remove `name` once I get around to versioning this
name = finalAttrs.pname;

src = ./.;
setSourceRoot = "sourceRoot=$(echo *-source/${sourceRoot})";
src = with pkgs.lib.fileset; (toSource {
root = ./.;
fileset = difference
(gitTracked ./.)
(unions [
./.github
./.vscode
./.envrc
./.gitignore
./biome.json
./LICENSE
./README.md
])
;
});

sourceRoot = "${finalAttrs.src.name}/${buildFolder}";

nativeBuildInputs = nativeBuildInputs ++ [ pnpm.configHook ];

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

buildPhase =
let
hugoVendor = pkgs.stdenv.mkDerivation {
name = "${finalAttrs.pname}-hugoVendor";
inherit (finalAttrs) src setSourceRoot;
inherit (finalAttrs) src sourceRoot;
nativeBuildInputs = [ go hugo git ];

buildPhase = ''
Expand Down Expand Up @@ -88,7 +103,7 @@
];

shellHook = self.checks.${system}.pre-commit-check.shellHook + ''
pushd ${sourceRoot}
pushd ${buildFolder}
pnpm install
Expand Down

0 comments on commit 2a701eb

Please sign in to comment.