From 2a701eb5eb0014cbb007c68d4a3415ffdf54c7e6 Mon Sep 17 00:00:00 2001 From: cjshearer Date: Tue, 25 Jun 2024 14:18:07 -0400 Subject: [PATCH] build: ignore unused files in `nix build` To avoid unnecessary rebuilds, we now ignore unused files from the build src. --- README.md | 6 +++--- flake.nix | 27 +++++++++++++++++++++------ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 5c5424f..0f7cd8f 100644 --- a/README.md +++ b/README.md @@ -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 = ".github.io" diff --git a/flake.nix b/flake.nix index f08bb5d..fe6fdd7 100644 --- a/flake.nix +++ b/flake.nix @@ -19,7 +19,7 @@ nodejs = pkgs.nodejs_22; pnpm = pkgs.pnpm; nativeBuildInputs = [ go hugo nodejs pnpm ]; - sourceRoot = "exampleSite"; + buildFolder = "exampleSite"; in { checks = { @@ -38,13 +38,28 @@ # 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="; }; @@ -52,7 +67,7 @@ let hugoVendor = pkgs.stdenv.mkDerivation { name = "${finalAttrs.pname}-hugoVendor"; - inherit (finalAttrs) src setSourceRoot; + inherit (finalAttrs) src sourceRoot; nativeBuildInputs = [ go hugo git ]; buildPhase = '' @@ -88,7 +103,7 @@ ]; shellHook = self.checks.${system}.pre-commit-check.shellHook + '' - pushd ${sourceRoot} + pushd ${buildFolder} pnpm install