From ead45c45e6bff2b262f6be25689b49f2506063a9 Mon Sep 17 00:00:00 2001 From: Brian Hicks Date: Mon, 13 Sep 2021 16:46:35 -0500 Subject: [PATCH] move to a flake --- default.nix | 54 ----------------------------------------- flake.lock | 43 +++++++++++++++++++++++++++++++++ flake.nix | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++ shell.nix | 16 ++++--------- 4 files changed, 117 insertions(+), 65 deletions(-) delete mode 100644 default.nix create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/default.nix b/default.nix deleted file mode 100644 index 7f6b503..0000000 --- a/default.nix +++ /dev/null @@ -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 - ''; -} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..f2ceea5 --- /dev/null +++ b/flake.lock @@ -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 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..508eae2 --- /dev/null +++ b/flake.nix @@ -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 ]; }; + }); +} diff --git a/shell.nix b/shell.nix index 4bcf904..f48084f 100644 --- a/shell.nix +++ b/shell.nix @@ -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