diff --git a/.gitignore b/.gitignore index 889a67e..dea3ff6 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,6 @@ static/style/fonts.css # Local Netlify folder .netlify + +# local pre-commit config +.pre-commit-config.yaml diff --git a/_typos.toml b/_typos.toml new file mode 100644 index 0000000..a005e9d --- /dev/null +++ b/_typos.toml @@ -0,0 +1,2 @@ +[default.extend-words] +referer = "referer" diff --git a/content/posts/command-line-flake-arguments/index.md b/content/posts/command-line-flake-arguments/index.md index 8e5f7d0..c75166e 100644 --- a/content/posts/command-line-flake-arguments/index.md +++ b/content/posts/command-line-flake-arguments/index.md @@ -126,7 +126,7 @@ If software builds are functions, then Nix flakes are pure functions. Indeed, th builder.url = "..."; source.url = "..."; }; - ouputs = { self, builder, source }: { + outputs = { self, builder, source }: { software = builder.build source; }; } diff --git a/flake.lock b/flake.lock index 78bf403..a4b3859 100644 --- a/flake.lock +++ b/flake.lock @@ -16,18 +16,32 @@ "type": "github" } }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1668681692, + "narHash": "sha256-Ht91NGdewz8IQLtWZ9LCeNXMSXHUss+9COoqu6JLmXU=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "009399224d5e398d03b22badca40a37ac85412a1", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flake-parts": { "inputs": { - "nixpkgs": [ - "nixpkgs" - ] + "nixpkgs-lib": "nixpkgs-lib" }, "locked": { - "lastModified": 1664385320, - "narHash": "sha256-uSCHb9RUqHRjTpI8OzyaUuHckFnnxwZqlXEuo+yUpYQ=", + "lastModified": 1668450977, + "narHash": "sha256-cfLhMhnvXn6x1vPm+Jow3RiFAUSCw/l1utktCw5rVA4=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "45298bd207b26e1bcd030a0bb075aa2da29f8e30", + "rev": "d591857e9d7dd9ddbfba0ea02b43b927c3c0f1fa", "type": "github" }, "original": { @@ -36,6 +50,21 @@ "type": "github" } }, + "flake-utils": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "gitignore": { "inputs": { "nixpkgs": [ @@ -58,11 +87,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1665259268, - "narHash": "sha256-ONFhHBLv5nZKhwV/F2GOH16197PbvpyWhoO0AOyktkU=", + "lastModified": 1670064435, + "narHash": "sha256-+ELoY30UN+Pl3Yn7RWRPabykwebsVK/kYE9JsIsUMxQ=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "c5924154f000e6306030300592f4282949b2db6c", + "rev": "61a8a98e6d557e6dd7ed0cdb54c3a3e3bbc5e25c", "type": "github" }, "original": { @@ -72,12 +101,73 @@ "type": "github" } }, + "nixpkgs-lib": { + "locked": { + "dir": "lib", + "lastModified": 1665349835, + "narHash": "sha256-UK4urM3iN80UXQ7EaOappDzcisYIuEURFRoGQ/yPkug=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "34c5293a71ffdb2fe054eb5288adc1882c1eb0b1", + "type": "github" + }, + "original": { + "dir": "lib", + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1671271954, + "narHash": "sha256-cSvu+bnvN08sOlTBWbBrKaBHQZq8mvk8bgpt0ZJ2Snc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "d513b448cc2a6da2c8803e3c197c9fc7e67b19e3", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-22.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "pre-commit": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "gitignore": [ + "gitignore" + ], + "nixpkgs": [ + "nixpkgs" + ], + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1671452357, + "narHash": "sha256-HqzXiQEegpRQ4VEl9pEPgHSIxhJrNJ27HfN1wOc7w2E=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "200790e9c77064c53eaf95805b013d96615ecc27", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, "root": { "inputs": { "caddyfile-syntax": "caddyfile-syntax", "flake-parts": "flake-parts", "gitignore": "gitignore", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "pre-commit": "pre-commit" } } }, diff --git a/flake.nix b/flake.nix index 02f3ba2..137f38e 100644 --- a/flake.nix +++ b/flake.nix @@ -4,19 +4,21 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; flake-parts.url = "github:hercules-ci/flake-parts"; - flake-parts.inputs.nixpkgs.follows = "nixpkgs"; gitignore.url = "github:hercules-ci/gitignore.nix"; gitignore.inputs.nixpkgs.follows = "nixpkgs"; + pre-commit.url = "github:cachix/pre-commit-hooks.nix"; + pre-commit.inputs.nixpkgs.follows = "nixpkgs"; + pre-commit.inputs.gitignore.follows = "gitignore"; caddyfile-syntax.url = "github:caddyserver/sublimetext"; caddyfile-syntax.flake = false; }; - outputs = { self, flake-parts, gitignore, ... }@inputs: + outputs = { self, flake-parts, gitignore, pre-commit, ... }@inputs: flake-parts.lib.mkFlake { inherit self; } { - imports = [ ]; + imports = [ pre-commit.flakeModule ]; systems = [ "x86_64-linux" "aarch64-darwin" ]; - perSystem = { config, self', inputs', pkgs, system, ... }: + perSystem = { config, pkgs, ... }: let inherit (gitignore.lib) gitignoreSource; inherit (pkgs.callPackage ./nix { }) fonts optimize-images update-date; @@ -24,25 +26,23 @@ caddyfile-syntax = "${inputs.caddyfile-syntax}/Caddyfile.sublime-syntax"; buildSite = { prod }: let - inherit (pkgs.lib) optionalString; - ifStaging = optionalString (!prod); - rev = if (self ? rev) then self.rev else "dirty"; + ifStaging = pkgs.lib.optionalString (!prod); in '' optimize-images zola build --drafts ${ifStaging "--base-url https://staging--mat-services.netlify.app"} # zola's ignored_content setting doesn't work in static/ rm -rf public/image/_favicon.svg - convert public/image/favicon.svg -resize 256x256 public/favicon.ico ''; in { packages.default = with pkgs; stdenv.mkDerivation { pname = "personal-site"; - version = "2022-11-25"; + version = "2022-12-21"; src = gitignoreSource ./.; - nativeBuildInputs = [ imagemagick optimize-images update-date zola ]; - configurePhase = copyFonts + '' + nativeBuildInputs = [ optimize-images update-date zola ]; + configurePhase = '' + ${copyFonts} mkdir -p extra/syntax cp ${caddyfile-syntax} extra/syntax ''; @@ -54,12 +54,25 @@ packages.staging-site = config.packages.default.overrideAttrs (_: { buildPhase = buildSite { prod = false; }; }); + pre-commit.settings.hooks = { + # nix hooks + deadnix.enable = true; + nix-linter.enable = true; + nixpkgs-fmt.enable = true; + statix.enable = true; + # general hooks + typos.enable = true; + typos.excludes = [ "webp" "png" "svg" "ico" ]; + }; devShells.default = with pkgs; mkShell { - packages = [ optimize-images update-date zola ]; - shellHook = linkFonts + '' + packages = [ jsonnet netlify-cli optimize-images update-date zola ]; + shellHook = '' + ${config.pre-commit.installationScript} + ${linkFonts} mkdir -p extra/syntax ln -snf ${caddyfile-syntax} extra/syntax ''; + inputsFrom = builtins.attrValues self.checks; }; }; }; diff --git a/nix/fonts.nix b/nix/fonts.nix index fa737d6..9ed199b 100644 --- a/nix/fonts.nix +++ b/nix/fonts.nix @@ -2,7 +2,6 @@ , lib , stdenv , woff2 -, writeShellScriptBin , writeText }: let @@ -45,7 +44,7 @@ rec { name = "font-${pathName name}"; src = fetchFromGitHub { inherit owner repo rev sha256; - sparseCheckout = path; + sparseCheckout = [ path ]; }; nativeBuildInputs = [ woff2 ]; buildPhase = '' @@ -61,7 +60,7 @@ rec { font = fontDerivation fontSrc; }; fonts = map fetchFont fontSrcs; - mkFontCss = { font, name, fileName, cssVar }: + mkFontCss = { name, fileName, cssVar, ... }: let path = pathName name; in '' @font-face { font-family: '${name}'; diff --git a/nix/optimize-images.nix b/nix/optimize-images.nix index 7b74b8f..8a3a20b 100644 --- a/nix/optimize-images.nix +++ b/nix/optimize-images.nix @@ -1,4 +1,4 @@ -{ bc, libwebp, scour, writeShellScriptBin }: +{ bc, imagemagick, libwebp, scour, writeShellScriptBin }: writeShellScriptBin "optimize-images" '' shopt -s globstar nullglob @@ -14,4 +14,5 @@ writeShellScriptBin "optimize-images" '' pct=$(${bc}/bin/bc <<< "scale=1; $newsize * 100 / $oldsize") echo "size went from "$(($oldsize / 1024))"KB to "$(($newsize / 1024))"KB ("$pct"% as large as original)" done + ${imagemagick}/bin/convert static/image/favicon.svg -resize 256x256 static/favicon.ico '' diff --git a/static/favicon.ico b/static/favicon.ico new file mode 100644 index 0000000..938157f Binary files /dev/null and b/static/favicon.ico differ