Compare commits

..

No commits in common. "168297aa8fe33d9a1d848d196b4fa22f46bdbccc" and "a512e2a078b3894b5cd3fd4d4950cadaa9a79851" have entirely different histories.

9 changed files with 64 additions and 170 deletions

View File

@ -1,52 +1,54 @@
local PROD = 'production';
local STAGE = 'staging';
local VOLUME = { name: 'site', path: '/site' };
local NIX = 'nix --extra-experimental-features nix-command --extra-experimental-features flakes';
local Volume = { name: 'site', path: '/site' };
local WhenProd(prod) = if prod then {
event: ['promote'],
target: [PROD],
target: ['production'],
} else {
target: { exclude: [PROD] },
target: { exclude: ['production'] },
};
local Step(env, name, cmds) =
local prod = env == PROD;
local NixStep(env) =
local prod = env == 'production';
local output = if prod then '' else ' .#staging-site';
{
name: name + ' ' + env,
name: 'nix build ' + env,
image: 'nixos/nix:latest',
volumes: [VOLUME],
commands: cmds,
volumes: [Volume],
commands: [
'$NIX build' + output,
'cp -r result/* /site/',
],
when: WhenProd(prod),
};
local NetlifyStep(env) =
local prod = env == 'production';
{
name: 'netlify deploy ' + env,
image: 'internetmat/drone-netlify:latest',
pull: 'always',
volumes: [Volume],
settings: {
token: { from_secret: 'netlify_token' },
site: { from_secret: 'netlify_site_id' },
alias: env,
path: '/site',
prod: prod,
},
when: WhenProd(prod),
};
local NixStep(env) =
local prod = env == PROD;
local output = if prod then '' else ' .#staging-site';
Step(env, 'nix build', [
NIX + ' build' + output,
'cp -r result/* /site/',
]);
local DeployStep(env) =
local prod = env == PROD;
local options = if prod then '--prod' else '--alias staging';
Step(env, 'netlify deploy', [
NIX + ' profile install netlify-cli',
'netlify deploy -d /site ' + options,
]);
{
kind: 'pipeline',
type: 'docker',
name: 'default',
environment: {
NIX: 'nix --extra-experimental-features nix-command --extra-experimental-features flakes',
},
volumes: [{ name: 'site', temp: {} }],
steps: [
NixStep(STAGE),
NixStep(PROD),
DeployStep(STAGE),
DeployStep(PROD),
NixStep('staging'),
NixStep('production'),
NetlifyStep('staging'),
NetlifyStep('production'),
],
}

3
.gitignore vendored
View File

@ -10,6 +10,3 @@ static/style/fonts.css
# Local Netlify folder
.netlify
# local pre-commit config
.pre-commit-config.yaml

View File

@ -1,2 +0,0 @@
[default.extend-words]
referer = "referer"

View File

@ -126,7 +126,7 @@ If software builds are functions, then Nix flakes are pure functions. Indeed, th
builder.url = "...";
source.url = "...";
};
outputs = { self, builder, source }: {
ouputs = { self, builder, source }: {
software = builder.build source;
};
}

View File

@ -16,32 +16,18 @@
"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-lib": "nixpkgs-lib"
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1668450977,
"narHash": "sha256-cfLhMhnvXn6x1vPm+Jow3RiFAUSCw/l1utktCw5rVA4=",
"lastModified": 1664385320,
"narHash": "sha256-uSCHb9RUqHRjTpI8OzyaUuHckFnnxwZqlXEuo+yUpYQ=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "d591857e9d7dd9ddbfba0ea02b43b927c3c0f1fa",
"rev": "45298bd207b26e1bcd030a0bb075aa2da29f8e30",
"type": "github"
},
"original": {
@ -50,21 +36,6 @@
"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": [
@ -87,11 +58,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1670064435,
"narHash": "sha256-+ELoY30UN+Pl3Yn7RWRPabykwebsVK/kYE9JsIsUMxQ=",
"lastModified": 1665259268,
"narHash": "sha256-ONFhHBLv5nZKhwV/F2GOH16197PbvpyWhoO0AOyktkU=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "61a8a98e6d557e6dd7ed0cdb54c3a3e3bbc5e25c",
"rev": "c5924154f000e6306030300592f4282949b2db6c",
"type": "github"
},
"original": {
@ -101,73 +72,12 @@
"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",
"pre-commit": "pre-commit"
"nixpkgs": "nixpkgs"
}
}
},

View File

@ -4,21 +4,19 @@
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, pre-commit, ... }@inputs:
outputs = { self, flake-parts, gitignore, ... }@inputs:
flake-parts.lib.mkFlake { inherit self; } {
imports = [ pre-commit.flakeModule ];
imports = [ ];
systems = [ "x86_64-linux" "aarch64-darwin" ];
perSystem = { config, pkgs, ... }:
perSystem = { config, self', inputs', pkgs, system, ... }:
let
inherit (gitignore.lib) gitignoreSource;
inherit (pkgs.callPackage ./nix { }) fonts optimize-images update-date;
@ -26,23 +24,25 @@
caddyfile-syntax = "${inputs.caddyfile-syntax}/Caddyfile.sublime-syntax";
buildSite = { prod }:
let
ifStaging = pkgs.lib.optionalString (!prod);
inherit (pkgs.lib) optionalString;
ifStaging = optionalString (!prod);
rev = if (self ? rev) then self.rev else "dirty";
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-12-21";
version = "2022-11-25";
src = gitignoreSource ./.;
nativeBuildInputs = [ optimize-images update-date zola ];
configurePhase = ''
${copyFonts}
nativeBuildInputs = [ imagemagick optimize-images update-date zola ];
configurePhase = copyFonts + ''
mkdir -p extra/syntax
cp ${caddyfile-syntax} extra/syntax
'';
@ -54,25 +54,12 @@
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 = [ jsonnet netlify-cli optimize-images update-date zola ];
shellHook = ''
${config.pre-commit.installationScript}
${linkFonts}
packages = [ optimize-images update-date zola ];
shellHook = linkFonts + ''
mkdir -p extra/syntax
ln -snf ${caddyfile-syntax} extra/syntax
'';
inputsFrom = builtins.attrValues self.checks;
};
};
};

View File

@ -2,6 +2,7 @@
, lib
, stdenv
, woff2
, writeShellScriptBin
, writeText
}:
let
@ -44,7 +45,7 @@ rec {
name = "font-${pathName name}";
src = fetchFromGitHub {
inherit owner repo rev sha256;
sparseCheckout = [ path ];
sparseCheckout = path;
};
nativeBuildInputs = [ woff2 ];
buildPhase = ''
@ -60,7 +61,7 @@ rec {
font = fontDerivation fontSrc;
};
fonts = map fetchFont fontSrcs;
mkFontCss = { name, fileName, cssVar, ... }:
mkFontCss = { font, name, fileName, cssVar }:
let path = pathName name; in ''
@font-face {
font-family: '${name}';

View File

@ -1,4 +1,4 @@
{ bc, imagemagick, libwebp, scour, writeShellScriptBin }:
{ bc, libwebp, scour, writeShellScriptBin }:
writeShellScriptBin "optimize-images" ''
shopt -s globstar nullglob
@ -14,5 +14,4 @@ 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
''

Binary file not shown.

Before

Width:  |  Height:  |  Size: 45 KiB