mat.services/flake.nix

80 lines
2.9 KiB
Nix
Raw Normal View History

2022-08-08 04:31:56 +00:00
{
description = "personal site";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
2022-09-06 04:36:55 +00:00
gitignore.url = "github:hercules-ci/gitignore.nix";
gitignore.inputs.nixpkgs.follows = "nixpkgs";
2022-12-22 03:08:18 +00:00
pre-commit.url = "github:cachix/pre-commit-hooks.nix";
pre-commit.inputs.nixpkgs.follows = "nixpkgs";
pre-commit.inputs.gitignore.follows = "gitignore";
2022-10-23 15:15:14 +00:00
caddyfile-syntax.url = "github:caddyserver/sublimetext";
caddyfile-syntax.flake = false;
2022-08-08 04:31:56 +00:00
};
2022-12-22 03:08:18 +00:00
outputs = { self, flake-parts, gitignore, pre-commit, ... }@inputs:
2022-08-08 04:31:56 +00:00
flake-parts.lib.mkFlake { inherit self; } {
2022-12-22 03:08:18 +00:00
imports = [ pre-commit.flakeModule ];
2022-10-21 00:04:25 +00:00
systems = [ "x86_64-linux" "aarch64-darwin" ];
2022-12-22 03:08:18 +00:00
perSystem = { config, pkgs, ... }:
2022-08-21 21:46:49 +00:00
let
2022-09-06 04:36:55 +00:00
inherit (gitignore.lib) gitignoreSource;
2022-10-23 16:16:12 +00:00
inherit (pkgs.callPackage ./nix { }) fonts optimize-images update-date;
2022-08-27 19:08:42 +00:00
inherit (fonts) copyFonts linkFonts;
2022-10-23 15:15:14 +00:00
caddyfile-syntax = "${inputs.caddyfile-syntax}/Caddyfile.sublime-syntax";
2022-10-20 23:48:14 +00:00
buildSite = { prod }:
2022-10-21 00:04:25 +00:00
let
2022-12-22 03:08:18 +00:00
ifStaging = pkgs.lib.optionalString (!prod);
2022-10-21 00:04:25 +00:00
in
''
2022-10-20 23:48:14 +00:00
optimize-images
2022-10-23 15:15:14 +00:00
zola build --drafts ${ifStaging "--base-url https://staging--mat-services.netlify.app"}
2022-10-20 23:48:14 +00:00
# zola's ignored_content setting doesn't work in static/
rm -rf public/image/_favicon.svg
'';
2022-08-21 21:46:49 +00:00
in
{
packages.default = with pkgs; stdenv.mkDerivation {
pname = "personal-site";
2022-12-22 03:08:18 +00:00
version = "2022-12-21";
2022-09-06 04:36:55 +00:00
src = gitignoreSource ./.;
2022-12-22 03:08:18 +00:00
nativeBuildInputs = [ optimize-images update-date zola ];
configurePhase = ''
${copyFonts}
2022-10-23 15:15:14 +00:00
mkdir -p extra/syntax
cp ${caddyfile-syntax} extra/syntax
'';
2022-10-20 23:48:14 +00:00
buildPhase = buildSite { prod = true; };
installPhase = ''
cp -r public $out
'';
};
2022-10-20 23:32:33 +00:00
packages.staging-site = config.packages.default.overrideAttrs (_: {
2022-10-20 23:48:14 +00:00
buildPhase = buildSite { prod = false; };
2022-10-20 23:32:33 +00:00
});
2022-12-22 03:08:18 +00:00
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" ];
};
2022-08-21 21:46:49 +00:00
devShells.default = with pkgs; mkShell {
2022-12-22 03:08:18 +00:00
packages = [ jsonnet netlify-cli optimize-images update-date zola ];
shellHook = ''
${config.pre-commit.installationScript}
${linkFonts}
2022-10-23 15:15:14 +00:00
mkdir -p extra/syntax
ln -snf ${caddyfile-syntax} extra/syntax
'';
2022-12-22 03:08:18 +00:00
inputsFrom = builtins.attrValues self.checks;
2022-08-27 19:08:42 +00:00
};
2022-08-08 04:31:56 +00:00
};
};
}