move to a flake

main
Brian Hicks 2021-09-13 16:46:35 -05:00
parent 6fdca53ec3
commit ead45c45e6
4 changed files with 117 additions and 65 deletions

View File

@ -1,54 +0,0 @@
{ ... }:
let
sources = import ./nix/sources.nix;
pkgs = import sources.nixpkgs { };
gitignore = import sources.gitignore { };
in pkgs.stdenv.mkDerivation {
name = "bytes.zone";
src = gitignore.gitignoreSource ./.;
buildInputs = [
pkgs.zola
pkgs.nodePackages.html-minifier
pkgs.nodePackages.clean-css-cli
pkgs.nodePackages.uglify-js
pkgs.pngcrush
];
buildPhase = ''
zola build
echo "compressing CSS"
find public \
-type f -name '*.css' \
-exec cleancss -O 1 -o {}.min {} \; \
-exec mv {}.min {} \;
echo "compressing JS"
find public \
-type f -name '*.js' \
-exec uglifyjs -o {}.min {} \; \
-exec mv {}.min {} \;
echo "compressing HTML"
html-minifier \
--collapse-whitespace \
--decode-entities \
--remove-comments \
--remove-attribute-quotes \
--remove-redundant-attributes \
--remove-optional-tags \
--remove-script-type-attributes \
--remove-style-link-type-attributes \
--file-ext html \
--input-dir public \
--output-dir public
echo "compressing images"
find public -type f -name '*.png' | xargs -n 1 pngcrush -ow -brute
'';
installPhase = ''
mkdir -p $out/share
mv public $out/share/bytes.zone
'';
}

43
flake.lock Normal file
View File

@ -0,0 +1,43 @@
{
"nodes": {
"flake-utils": {
"locked": {
"lastModified": 1631561581,
"narHash": "sha256-3VQMV5zvxaVLvqqUrNz3iJelLw30mIVSfZmAaauM3dA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "7e5bf3925f6fbdfaf50a2a7ca0be2879c4261d19",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1631562492,
"narHash": "sha256-RMXh3Ol04TOdes/gl8GI0Q+8PH7kEeXbHzL0e957/Vc=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "f789739acc4baf042c85f2f7382f4b0af5c5e049",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "release-21.05",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

69
flake.nix Normal file
View File

@ -0,0 +1,69 @@
{
description = "bytes.zone website";
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs/release-21.05";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let pkgs = nixpkgs.legacyPackages.${system};
in rec {
# `nix build`
packages.bytes-zone = pkgs.stdenv.mkDerivation {
name = "bytes.zone";
src = ./.;
buildInputs = [
pkgs.zola
pkgs.nodePackages.html-minifier
pkgs.nodePackages.clean-css-cli
pkgs.nodePackages.uglify-js
pkgs.pngcrush
];
buildPhase = ''
zola build
echo "compressing CSS"
find public \
-type f -name '*.css' \
-exec cleancss -O 1 -o {}.min {} \; \
-exec mv {}.min {} \;
echo "compressing JS"
find public \
-type f -name '*.js' \
-exec uglifyjs -o {}.min {} \; \
-exec mv {}.min {} \;
echo "compressing HTML"
html-minifier \
--collapse-whitespace \
--decode-entities \
--remove-comments \
--remove-attribute-quotes \
--remove-redundant-attributes \
--remove-optional-tags \
--remove-script-type-attributes \
--remove-style-link-type-attributes \
--file-ext html \
--input-dir public \
--output-dir public
echo "compressing images"
find public -type f -name '*.png' | xargs -n 1 pngcrush -ow -brute
'';
installPhase = ''
mkdir -p $out/share
mv public $out/share/bytes.zone
'';
};
defaultPackage = packages.bytes-zone;
overlay = final: prev: { bytes-zone = packages.bytes-zone; };
# `nix develop`
devShell = pkgs.mkShell { buildInputs = with pkgs; [ zola pngcrush ]; };
});
}

View File

@ -1,11 +1,5 @@
{ ... }:
let
sources = import ./nix/sources.nix;
nixpkgs = import sources.nixpkgs { };
niv = import sources.niv { };
pa11y = import ./nix/pkgs/pa11y { pkgs = nixpkgs; };
in with nixpkgs;
stdenv.mkDerivation {
name = "bytes.zone";
buildInputs = [ niv.niv git zola pa11y.pa11y pngcrush ];
}
(import (fetchTarball {
url =
"https://github.com/edolstra/flake-compat/archive/12c64ca55c1014cdc1b16ed5a804aa8576601ff2.tar.gz";
sha256 = "0jm6nzb83wa6ai17ly9fzpqc40wg1viib8klq8lby54agpl213w5";
}) { src = ./.; }).shellNix