aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2020-10-11 03:56:30 -0300
committerEuAndreh <eu@euandre.org>2020-10-11 04:19:20 -0300
commit6d2fae4d2749d893f5d027d5b4756e709a3847af (patch)
treed99d02b8039e233d2e5ae833b2752ef144274ffc
parentMark slides + article on feature flags as unpublished (diff)
downloadeuandre.org-6d2fae4d2749d893f5d027d5b4756e709a3847af.tar.gz
euandre.org-6d2fae4d2749d893f5d027d5b4756e709a3847af.tar.xz
Decouple testing with Nix
Use Nix for build isolation not for test running.
-rw-r--r--.build.yml1
-rw-r--r--a-propos.md2
-rw-r--r--default.nix150
-rw-r--r--nix/sources.json26
-rw-r--r--nix/sources.nix197
-rwxr-xr-xscripts/assert-content.sh25
-rwxr-xr-xscripts/assert-nixfmt.sh16
-rwxr-xr-xscripts/assert-shellcheck.sh6
-rwxr-xr-xscripts/assert-spelling.sh36
-rwxr-xr-xscripts/assert-todos.sh12
-rw-r--r--scripts/publish-env.sh4
-rw-r--r--scripts/spelling/en.txt (renamed from spelling/en.txt)0
-rw-r--r--scripts/spelling/fr.txt (renamed from spelling/fr.txt)0
-rw-r--r--scripts/spelling/international.txt (renamed from spelling/international.txt)0
-rw-r--r--scripts/spelling/pt.txt (renamed from spelling/pt.txt)1
-rwxr-xr-xspelling/check-spelling.sh37
-rwxr-xr-xtests.sh12
-rw-r--r--utils-i18n.nix52
-rw-r--r--utils.nix105
19 files changed, 415 insertions, 267 deletions
diff --git a/.build.yml b/.build.yml
index 2dce81d..ed27fd4 100644
--- a/.build.yml
+++ b/.build.yml
@@ -19,5 +19,4 @@ tasks:
- docs: |
cd website/
nix-build -A publishScript
- source ./scripts/publish-env.sh
./result/bin/publish.sh
diff --git a/a-propos.md b/a-propos.md
index 661f25e..689da32 100644
--- a/a-propos.md
+++ b/a-propos.md
@@ -29,4 +29,4 @@ regrouper-les en utilisant LaTeX dans recueils de chansons.
[Liste de pastebins]({% link pastebins.fr.md %}).
-[Articles par catégory]({% link categories.fr.md %}).
+[Articles par catégorie]({% link categories.fr.md %}).
diff --git a/default.nix b/default.nix
index b0cb35c..60e879b 100644
--- a/default.nix
+++ b/default.nix
@@ -1,114 +1,60 @@
let
- pkgs = import (fetchTarball
- "https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz") { };
- dicts = rec {
- mkDict = let
- prefix =
- "https://raw.githubusercontent.com/wooorm/dictionaries/61016e00e276f9bf5e52cbc6c02a45f2e49b2c7e/dictionaries";
- in { lang, dicSHA256, affSHA256 }:
- let
- dic = builtins.fetchurl {
- url = "${prefix}/${lang}/index.dic";
- sha256 = dicSHA256;
- };
- aff = builtins.fetchurl {
- url = "${prefix}/${lang}/index.aff";
- sha256 = affSHA256;
- };
- in pkgs.stdenv.mkDerivation {
- name = "songbooks-dict-${lang}";
- builder = builtins.toFile "builder.sh" ''
- source $stdenv/setup
- install -dm755 $out/share/hunspell
- install -m644 ${dic} $out/share/hunspell/${lang}.dic
- install -m644 ${aff} $out/share/hunspell/${lang}.aff
- runHook postInstall
- '';
- };
- en = mkDict {
- lang = "en";
- dicSHA256 = "1k4660ccwwpwac0rc7b8ih3vd24kxgvljkrakv2l1f72yfpw3bp2";
- affSHA256 = "0yvc2fhc03y0y1gwjyb20ifcrxnzm3ama1fri9r5gna092fz3qca";
- };
- pt = mkDict {
- lang = "pt";
- dicSHA256 = "1z0kfxv8m361xhp4zwdlsn2ib8q3rnljj0b2s4482alyxpd00h9x";
- affSHA256 = "1ssj1g7qwh0lv3ajzvchwsfr7cgzrlqms28m1j3gm1y2avi50qhw";
- };
- fr = mkDict {
- lang = "fr";
- dicSHA256 = "10p6jlk9j117mjd1z3dp3vfszcvxqha11kfvksqhvrq4ld9xwzbn";
- affSHA256 = "0d6k608h7gm1za3vdq1fhlwqzz2zxg1z0bx1bfvi0spg4a2mn09p";
- };
- };
- myHunspell = (pkgs.hunspellWithDicts (with dicts; [ en pt fr ]));
-in rec {
- utils = import ./utils.nix {
- pkgs = pkgs;
- src = pkgs.nix-gitignore.gitignoreSource [ ] ./.;
- baseName = "website";
- };
+ niv-sources = import ./nix/sources.nix;
+ pkgs = import niv-sources.nixpkgs { };
+ src = pkgs.nix-gitignore.gitignoreSource [ "!.git" ] ./.;
+ utils-i18n = pkgs.callPackage ./utils-i18n.nix { };
+
jekyllEnv = pkgs.bundlerEnv {
name = "jekyll-env";
gemfile = ./Gemfile;
lockfile = ./Gemfile.lock;
gemset = ./gemset.nix;
};
- subtasks = rec {
- hunspellCheck = utils.baseTask.overrideAttrs (baseAttrs: {
- name = "${baseAttrs.name}-hunspell";
- buildInputs = baseAttrs.buildInputs ++ [ myHunspell ];
- buildPhase = ''
- patchShebangs .
- ./spelling/check-spelling.sh "${subtasks.docs}"
- touch $out
- '';
- });
- assertContent = utils.baseTask.overrideAttrs (baseAttrs: {
- name = "${baseAttrs.name}-assert-content";
- buildInputs = baseAttrs.buildInputs ++ [ pkgs.jq ];
- buildPhase = ''
- patchShebangs .
- ./scripts/assert-content.sh "${subtasks.docs}/site.json"
- touch $out
- '';
- });
- docs = utils.baseTask.overrideAttrs (baseAttrs: {
- name = "${baseAttrs.name}-docs";
- buildInputs = [ jekyllEnv ];
- buildPhase = ''
- patchShebangs .
- jekyll build -d $out
- '';
- });
- };
- test = utils.test [
- utils.formatNix
- (utils.shellcheck null)
- (utils.fixme [
- "utils.nix"
- "TODOs.org"
- "_pastebins/"
- "_posts/"
- "_tils/"
- "drafts/"
- "templates/"
- ])
- subtasks.hunspellCheck
- subtasks.assertContent
- subtasks.docs
+ projectBuildInputs = with pkgs; [
+ jekyllEnv
+
+ nixfmt
+ git
+ shellcheck
+ jq
+ niv
+ (hunspellWithDicts (with utils-i18n.dicts; [ en pt fr ]))
];
- shell = pkgs.mkShell rec {
- name = "website-shell";
- buildInputs = [ jekyllEnv myHunspell ];
+in rec {
+ site = pkgs.stdenv.mkDerivation {
+ inherit src;
+ name = "website-site";
+ phases = [ "unpackPhase" "buildPhase" ];
+ buildInputs = [ jekyllEnv ];
+ buildPhase = ''
+ patchShebangs .
+ jekyll build -d $out
+ '';
};
- publishScript = utils.overwritingPublishScript {
- docsDerivation = subtasks.docs;
- overwrite = true;
+ test = pkgs.stdenv.mkDerivation {
+ inherit src;
+ name = "website-test";
+ phases = [ "unpackPhase" "buildPhase" ];
+ buildInputs = projectBuildInputs;
+ buildPhase = ''
+ patchShebangs .
+ ./tests.sh
+ touch $out
+ '';
};
- fastPublishScript = utils.overwritingPublishScript {
- docsDerivation = subtasks.docs;
- overwrite = false;
+ shell = pkgs.mkShell rec {
+ name = "website-shell";
+ buildInputs = projectBuildInputs;
};
- site = subtasks.docs;
+ publishScript = pkgs.writeShellScriptBin "publish.sh" ''
+ set -euo pipefail
+ SERVER_URL='root@euandre.org'
+ REMOTE_PATH='/home/user-data/www/default/'
+ OUT_DOCS='${site}'
+ ${pkgs.openssh}/bin/ssh -o StrictHostKeyChecking=no "$SERVER_URL" rm -rf "$REMOTE_PATH/*"
+ ${pkgs.rsync}/bin/rsync -avzP \
+ --rsh="ssh -o StrictHostKeyChecking=no" \
+ "$OUT_DOCS/" \
+ "$SERVER_URL:$REMOTE_PATH"
+ '';
}
diff --git a/nix/sources.json b/nix/sources.json
new file mode 100644
index 0000000..c8fe824
--- /dev/null
+++ b/nix/sources.json
@@ -0,0 +1,26 @@
+{
+ "niv": {
+ "branch": "master",
+ "description": "Easy dependency management for Nix projects",
+ "homepage": "https://github.com/nmattia/niv",
+ "owner": "nmattia",
+ "repo": "niv",
+ "rev": "9d35b9e4837ab88517210b1701127612c260eccf",
+ "sha256": "0q50xhnm8g2yfyakrh0nly4swyygxpi0a8cb9gp65wcakcgvzvdh",
+ "type": "tarball",
+ "url": "https://github.com/nmattia/niv/archive/9d35b9e4837ab88517210b1701127612c260eccf.tar.gz",
+ "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
+ },
+ "nixpkgs": {
+ "branch": "nixos-unstable",
+ "description": "Nix Packages collection",
+ "homepage": "",
+ "owner": "NixOS",
+ "repo": "nixpkgs",
+ "rev": "420f89ceb267b461eed5d025b6c3c0e57703cc5c",
+ "sha256": "0c9kr76p6nmf4z2j2afgcddckbaxq6kxlmp1895h6qamm1c0ypb9",
+ "type": "tarball",
+ "url": "https://github.com/NixOS/nixpkgs/archive/420f89ceb267b461eed5d025b6c3c0e57703cc5c.tar.gz",
+ "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
+ }
+}
diff --git a/nix/sources.nix b/nix/sources.nix
new file mode 100644
index 0000000..9f418ad
--- /dev/null
+++ b/nix/sources.nix
@@ -0,0 +1,197 @@
+# This file has been generated by Niv.
+
+let
+
+ #
+ # The fetchers. fetch_<type> fetches specs of type <type>.
+ #
+
+ fetch_file = pkgs: name: spec:
+ let name' = sanitizeName name + "-src";
+ in if spec.builtin or true then
+ builtins_fetchurl {
+ inherit (spec) url sha256;
+ name = name';
+ }
+ else
+ pkgs.fetchurl {
+ inherit (spec) url sha256;
+ name = name';
+ };
+
+ fetch_tarball = pkgs: name: spec:
+ let name' = sanitizeName name + "-src";
+ in if spec.builtin or true then
+ builtins_fetchTarball {
+ name = name';
+ inherit (spec) url sha256;
+ }
+ else
+ pkgs.fetchzip {
+ name = name';
+ inherit (spec) url sha256;
+ };
+
+ fetch_git = name: spec:
+ let
+ ref = if spec ? ref then
+ spec.ref
+ else if spec ? branch then
+ "refs/heads/${spec.branch}"
+ else if spec ? tag then
+ "refs/tags/${spec.tag}"
+ else
+ abort
+ "In git source '${name}': Please specify `ref`, `tag` or `branch`!";
+ in builtins.fetchGit {
+ url = spec.repo;
+ inherit (spec) rev;
+ inherit ref;
+ };
+
+ fetch_local = spec: spec.path;
+
+ fetch_builtin-tarball = name:
+ throw ''
+ [${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`.
+ $ niv modify ${name} -a type=tarball -a builtin=true'';
+
+ fetch_builtin-url = name:
+ throw ''
+ [${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`.
+ $ niv modify ${name} -a type=file -a builtin=true'';
+
+ #
+ # Various helpers
+ #
+
+ # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695
+ sanitizeName = name:
+ (concatMapStrings (s: if builtins.isList s then "-" else s)
+ (builtins.split "[^[:alnum:]+._?=-]+"
+ ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name)));
+
+ # The set of packages used when specs are fetched using non-builtins.
+ mkPkgs = sources: system:
+ let
+ sourcesNixpkgs = import
+ (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) {
+ inherit system;
+ };
+ hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath;
+ hasThisAsNixpkgsPath = <nixpkgs> == ./.;
+ in if builtins.hasAttr "nixpkgs" sources then
+ sourcesNixpkgs
+ else if hasNixpkgsPath && !hasThisAsNixpkgsPath then
+ import <nixpkgs> { }
+ else
+ abort ''
+ Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
+ add a package called "nixpkgs" to your sources.json.
+ '';
+
+ # The actual fetching function.
+ fetch = pkgs: name: spec:
+
+ if !builtins.hasAttr "type" spec then
+ abort "ERROR: niv spec ${name} does not have a 'type' attribute"
+ else if spec.type == "file" then
+ fetch_file pkgs name spec
+ else if spec.type == "tarball" then
+ fetch_tarball pkgs name spec
+ else if spec.type == "git" then
+ fetch_git name spec
+ else if spec.type == "local" then
+ fetch_local spec
+ else if spec.type == "builtin-tarball" then
+ fetch_builtin-tarball name
+ else if spec.type == "builtin-url" then
+ fetch_builtin-url name
+ else
+ abort
+ "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}";
+
+ # If the environment variable NIV_OVERRIDE_${name} is set, then use
+ # the path directly as opposed to the fetched source.
+ replace = name: drv:
+ let
+ saneName = stringAsChars
+ (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name;
+ ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}";
+ in if ersatz == "" then drv else ersatz;
+
+ # Ports of functions for older nix versions
+
+ # a Nix version of mapAttrs if the built-in doesn't exist
+ mapAttrs = builtins.mapAttrs or (f: set:
+ with builtins;
+ listToAttrs (map (attr: {
+ name = attr;
+ value = f attr set.${attr};
+ }) (attrNames set)));
+
+ # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295
+ range = first: last:
+ if first > last then
+ [ ]
+ else
+ builtins.genList (n: first + n) (last - first + 1);
+
+ # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257
+ stringToCharacters = s:
+ map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1));
+
+ # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269
+ stringAsChars = f: s: concatStrings (map f (stringToCharacters s));
+ concatMapStrings = f: list: concatStrings (map f list);
+ concatStrings = builtins.concatStringsSep "";
+
+ # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331
+ optionalAttrs = cond: as: if cond then as else { };
+
+ # fetchTarball version that is compatible between all the versions of Nix
+ builtins_fetchTarball = { url, name ? null, sha256 }@attrs:
+ let inherit (builtins) lessThan nixVersion fetchTarball;
+ in if lessThan nixVersion "1.12" then
+ fetchTarball
+ ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
+ else
+ fetchTarball attrs;
+
+ # fetchurl version that is compatible between all the versions of Nix
+ builtins_fetchurl = { url, name ? null, sha256 }@attrs:
+ let inherit (builtins) lessThan nixVersion fetchurl;
+ in if lessThan nixVersion "1.12" then
+ fetchurl
+ ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
+ else
+ fetchurl attrs;
+
+ # Create the final "sources" from the config
+ mkSources = config:
+ mapAttrs (name: spec:
+ if builtins.hasAttr "outPath" spec then
+ abort
+ "The values in sources.json should not have an 'outPath' attribute"
+ else
+ spec // { outPath = replace name (fetch config.pkgs name spec); })
+ config.sources;
+
+ # The "config" used by the fetchers
+ mkConfig = { sourcesFile ?
+ if builtins.pathExists ./sources.json then ./sources.json else null
+ , sources ? if isNull sourcesFile then
+ { }
+ else
+ builtins.fromJSON (builtins.readFile sourcesFile)
+ , system ? builtins.currentSystem, pkgs ? mkPkgs sources system }: rec {
+ # The sources, i.e. the attribute set of spec name to spec
+ inherit sources;
+
+ # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers
+ inherit pkgs;
+ };
+
+in mkSources (mkConfig { }) // {
+ __functor = _: settings: mkSources (mkConfig settings);
+}
diff --git a/scripts/assert-content.sh b/scripts/assert-content.sh
index a0d661f..e694580 100755
--- a/scripts/assert-content.sh
+++ b/scripts/assert-content.sh
@@ -8,23 +8,8 @@ red() { echo -e "${red}${1}${end}"; }
## Constant definitions
-JSON="${1:-}"
-[[ -z "${JSON}" ]] && {
- red 'Missing input JSON file.'
- cat <<EOF
-Usage:
- $0 <SITE_JSON_PATH>
-
- Arguments
- SITE_JSON_PATH Path to the site.json file which contains data and metadata about pages of the site.
-
-Examples:
- $0 _site/site.json
- $0 result/site.json
- $0 \$(nix-build -A subtasks.docs)/site.json
-EOF
- exit 2
-}
+jekyll build
+JSON='_site/site.json'
LANGS=(en pt fr)
IGNORED_PAGES=(site.json sitemap.xml *.atom)
@@ -138,6 +123,11 @@ for til in $(jq -r '.tils[] | @base64' "${JSON}"); do
assert-frontmatter "$til" 'post' '_tils'
done
+echo Linting slides... >&2
+for slide in $(jq -r '.slides[] | @base64' "${JSON}"); do
+ assert-frontmatter "$slide" 'post' '_slides'
+done
+
echo Asserting unique refs... >&2
KNOWN_IDS=()
assert-unique-ref() {
@@ -163,5 +153,6 @@ assert-unique-ref() {
assert-unique-ref "$(jq -r '.pages[] | @base64' "${JSON}")"
assert-unique-ref "$(jq -r '.articles[] | @base64' "${JSON}")"
assert-unique-ref "$(jq -r '.tils[] | @base64' "${JSON}")"
+assert-unique-ref "$(jq -r '.slides[] | @base64' "${JSON}")"
echo Done. >&2
diff --git a/scripts/assert-nixfmt.sh b/scripts/assert-nixfmt.sh
new file mode 100755
index 0000000..7a68fa9
--- /dev/null
+++ b/scripts/assert-nixfmt.sh
@@ -0,0 +1,16 @@
+#!/usr/bin/env bash
+set -Eeuo pipefail
+cd "$(dirname "${BASH_SOURCE[0]}")"
+cd ../
+
+format() {
+ nix_file="${1}"
+ diff <(nixfmt < "${nix_file}") "${nix_file}" || {
+ echo "The file '${nix_file}' is unformatted. To fix it, run:"
+ echo " nixfmt ${nix_file}"
+ exit 1
+ }
+}
+export -f format
+
+find . -type f -name '*.nix' -print0 | xargs -0 -I% bash -c "format %"
diff --git a/scripts/assert-shellcheck.sh b/scripts/assert-shellcheck.sh
new file mode 100755
index 0000000..e24c29c
--- /dev/null
+++ b/scripts/assert-shellcheck.sh
@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+set -Eeuo pipefail
+cd "$(dirname "${BASH_SOURCE[0]}")"
+cd ../
+
+git ls-files | grep '\.sh$' | xargs shellcheck
diff --git a/scripts/assert-spelling.sh b/scripts/assert-spelling.sh
new file mode 100755
index 0000000..caaecfa
--- /dev/null
+++ b/scripts/assert-spelling.sh
@@ -0,0 +1,36 @@
+#!/usr/bin/env bash
+set -Eeuo pipefail
+cd "$(dirname "${BASH_SOURCE[0]}")"
+cd ../
+
+export LANG=C.UTF-8
+
+for DICT in scripts/spelling/*.txt; do
+ diff <(sort "$DICT") "$DICT" || {
+ echo "The $DICT dictionary is unsorted. To fix it, run:" >&2
+ echo " LANG=C.UTF-8 sort docs/$DICT | sponge docs/$DICT" >&2
+ exit 1
+ }
+done
+
+OUT="$(mktemp)"
+shopt -s globstar
+jekyll build
+for f in _site/**/*.html; do
+ if ! grep -E '^_site/pastebin' <(echo "$f") > /dev/null; then
+ if ! grep -E '^_site/vendor/' <(echo "$f") > /dev/null; then
+ l="$(head -n2 "$f" | tail -n1 | cut -d\" -f2)"
+ hunspell -u3 -H -d "$l" -p <(cat scripts/spelling/international.txt "scripts/spelling/$l.txt") "$f" | tee -a "$OUT"
+ fi
+ fi
+done
+
+if [[ -s "$OUT" ]]; then
+ printf "\nvvv Mispelled words detected by hunspell.\n\n"
+ sort < "$OUT" | uniq
+ printf "\n^^^\n" >&2
+ exit 1
+else
+ echo "No spelling errors detected"
+ exit 0
+fi
diff --git a/scripts/assert-todos.sh b/scripts/assert-todos.sh
new file mode 100755
index 0000000..a59b4cd
--- /dev/null
+++ b/scripts/assert-todos.sh
@@ -0,0 +1,12 @@
+#!/usr/bin/env bash
+set -Eeuo pipefail
+cd "$(dirname "${BASH_SOURCE[0]}")"
+cd ../
+
+# shellcheck disable=2046
+if grep -R FIXME $(git ls-files) | \
+ grep -Ev '^(vendor/|.git/|scripts/assert-todos.sh|templates)'; then
+ echo "Found dangling FIXME markers on the project."
+ echo "You should write them down properly on TODOs.org."
+ exit 1
+fi
diff --git a/scripts/publish-env.sh b/scripts/publish-env.sh
deleted file mode 100644
index d5e8be2..0000000
--- a/scripts/publish-env.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/usr/bin/env bash
-
-export SERVER_URL=root@euandre.org
-export DOCS_SERVER_PATH="/home/user-data/www/default/"
diff --git a/spelling/en.txt b/scripts/spelling/en.txt
index bebfc76..bebfc76 100644
--- a/spelling/en.txt
+++ b/scripts/spelling/en.txt
diff --git a/spelling/fr.txt b/scripts/spelling/fr.txt
index aa09184..aa09184 100644
--- a/spelling/fr.txt
+++ b/scripts/spelling/fr.txt
diff --git a/spelling/international.txt b/scripts/spelling/international.txt
index 3536249..3536249 100644
--- a/spelling/international.txt
+++ b/scripts/spelling/international.txt
diff --git a/spelling/pt.txt b/scripts/spelling/pt.txt
index 2befc17..65d4ac8 100644
--- a/spelling/pt.txt
+++ b/scripts/spelling/pt.txt
@@ -23,6 +23,7 @@ achar
arquivo
artigos
buscar
+categoria
chegar
comece
comentário
diff --git a/spelling/check-spelling.sh b/spelling/check-spelling.sh
deleted file mode 100755
index 3ddfd2a..0000000
--- a/spelling/check-spelling.sh
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/env bash
-set -Eeuo pipefail
-
-HTML_DIR="${1:-}"
-[[ -z "${HTML_DIR}" ]] && {
- echo 'Undefined input HTML_DIR.' >&2
- exit 2
-}
-
-# Required by =sort= and =hunspell=
-export LANG=C.UTF-8
-
-for DICT in spelling/*.txt; do
- diff <(sort "$DICT" | uniq) "$DICT" || {
- echo "The $DICT dictionary is unsorted. To fix it, run:" >&2
- echo " LANG=C.UTF-8 sort $DICT | uniq | sponge $DICT" >&2
- exit 1
- }
-done
-
-rm -f spelling.txt
-shopt -s globstar
-for f in "${HTML_DIR}"/**/*.html; do
- if ! grep -E '/pastebin(/|s.html)' <(echo "$f") > /dev/null; then
- l="$(head -n2 "$f" | tail -n1 | cut -d\" -f2)"
- hunspell -u3 -H -d "$l" -p <(cat spelling/international.txt "spelling/$l.txt") "$f" | tee -a spelling.txt
- fi
-done
-
-if [[ -s spelling.txt ]]; then
- printf "\nvvv Mispelled words detected by hunspell.\n\n" >&2
- sort < spelling.txt | uniq >&2
- printf "\n^^^\n" >&2
- exit 1
-else
- echo "No words mispelled" >&2
-fi
diff --git a/tests.sh b/tests.sh
new file mode 100755
index 0000000..46f1f0e
--- /dev/null
+++ b/tests.sh
@@ -0,0 +1,12 @@
+#!/usr/bin/env bash
+set -Eeuo pipefail
+cd "$(dirname "${BASH_SOURCE[0]}")"
+
+set -x
+
+./scripts/assert-spelling.sh
+./scripts/assert-nixfmt.sh
+./scripts/assert-shellcheck.sh
+./scripts/assert-todos.sh
+
+./scripts/assert-content.sh
diff --git a/utils-i18n.nix b/utils-i18n.nix
new file mode 100644
index 0000000..379cd3b
--- /dev/null
+++ b/utils-i18n.nix
@@ -0,0 +1,52 @@
+{ pkgs }: rec {
+ sphinx-intl = with pkgs.python3.pkgs;
+ buildPythonPackage rec {
+ pname = "sphinx-intl";
+ version = "2.0.1";
+ src = fetchPypi {
+ inherit pname version;
+ sha256 = "1d1q0sanjp4nkfvhsxi75zf3xjyyi8nzxvl3v7l0jy9ld70nwnmj";
+ };
+ propagatedBuildInputs = with pkgs.python3Packages; [ Babel click sphinx ];
+ };
+ dicts = rec {
+ mkDict = let
+ prefix =
+ "https://raw.githubusercontent.com/wooorm/dictionaries/61016e00e276f9bf5e52cbc6c02a45f2e49b2c7e/dictionaries";
+ in { lang, dicSHA256, affSHA256 }:
+ let
+ dic = builtins.fetchurl {
+ url = "${prefix}/${lang}/index.dic";
+ sha256 = dicSHA256;
+ };
+ aff = builtins.fetchurl {
+ url = "${prefix}/${lang}/index.aff";
+ sha256 = affSHA256;
+ };
+ in pkgs.stdenv.mkDerivation {
+ name = "x-bindgen-dict-${lang}";
+ builder = builtins.toFile "builder.sh" ''
+ source $stdenv/setup
+ install -dm755 $out/share/hunspell
+ install -m644 ${dic} $out/share/hunspell/${lang}.dic
+ install -m644 ${aff} $out/share/hunspell/${lang}.aff
+ runHook postInstall
+ '';
+ };
+ en = mkDict {
+ lang = "en";
+ dicSHA256 = "1k4660ccwwpwac0rc7b8ih3vd24kxgvljkrakv2l1f72yfpw3bp2";
+ affSHA256 = "0yvc2fhc03y0y1gwjyb20ifcrxnzm3ama1fri9r5gna092fz3qca";
+ };
+ pt = mkDict {
+ lang = "pt";
+ dicSHA256 = "1z0kfxv8m361xhp4zwdlsn2ib8q3rnljj0b2s4482alyxpd00h9x";
+ affSHA256 = "1ssj1g7qwh0lv3ajzvchwsfr7cgzrlqms28m1j3gm1y2avi50qhw";
+ };
+ fr = mkDict {
+ lang = "fr";
+ dicSHA256 = "10p6jlk9j117mjd1z3dp3vfszcvxqha11kfvksqhvrq4ld9xwzbn";
+ affSHA256 = "0d6k608h7gm1za3vdq1fhlwqzz2zxg1z0bx1bfvi0spg4a2mn09p";
+ };
+ };
+}
diff --git a/utils.nix b/utils.nix
deleted file mode 100644
index 5bcbb10..0000000
--- a/utils.nix
+++ /dev/null
@@ -1,105 +0,0 @@
-{ pkgs, src, baseName }: rec {
- baseTask = pkgs.stdenv.mkDerivation {
- name = "${baseName}-task";
- src = src;
- buildInputs = [ ];
- phases = "unpackPhase buildPhase";
- buildPhase = ''
- echo "ERROR: base task buildPhase not overriden."
- exit 1
- '';
- };
- shellcheck = ignoredFindPattern:
- baseTask.overrideAttrs (baseAttrs: rec {
- name = "${baseAttrs.name}-shellcheck";
- buildInputs = baseAttrs.buildInputs ++ [ pkgs.shellcheck ];
- ignoredPattern =
- if ignoredFindPattern == null then "" else ignoredFindPattern;
- buildPhase = ''
- find . -type f \( -name '*.sh' -and -regextype egrep ! -regex '${ignoredPattern}' \) -print0 | xargs -0 shellcheck -x
- touch $out
- '';
- });
- formatNix = baseTask.overrideAttrs (baseAttrs: {
- name = "${baseAttrs.name}-nixfmt";
- buildInputs = baseAttrs.buildInputs ++ [ pkgs.nixfmt ];
- buildPhase = ''
- format() {
- nix_file="$1"
- diff <(nixfmt < "$nix_file") "$nix_file" || {
- echo "The $nix_file is unformatted. To fix it, run:"
- echo " nixfmt $nix_file"
- exit 1
- }
- }
- export -f format
- find . -type f -name '*.nix' -print0 | xargs -0 -I{} bash -c "format {}" \;
- touch $out
- '';
- });
- fixme = ignoredFiles:
- baseTask.overrideAttrs (baseAttrs: rec {
- name = "${baseAttrs.name}-fixme";
- buildInputs = baseAttrs.buildInputs ++ [ pkgs.ag ];
- ignoredPattern = pkgs.lib.fold (a: b: " --ignore ${a} ${b}") ""
- (if ignoredFiles == null then [
- "utils.nix"
- "TODOs.org"
- ] else
- ignoredFiles);
- buildPhase = ''
- ag FIXME ${ignoredPattern} || {
- touch $out
- exit 0
- }
- echo " Found dangling FIXME markers on the project."
- echo " You should write them down properly on TODOs.org."
- exit 1
- '';
- });
- readmeOrg = title:
- baseTask.overrideAttrs (baseAttrs: {
- name = "${baseAttrs.name}-readme-docs";
- buildInputs = [ pkgs.pandoc ];
- buildPhase = ''
- pandoc README.org -o $out --css docs/README.css --to=html5 --self-contained --metadata title="${title}"
- '';
- });
- test = testDerivations:
- baseTask.overrideAttrs (baseAttrs: {
- name = "${baseAttrs.name}-test";
- buildPhase = ''
- echo "Ran tests for:"
- for d in ${builtins.toString testDerivations}; do
- echo " $d"
- done
- echo "All tests passed!"
- touch $out
- '';
- });
- shellEnvironmentBuild = shellBuildInputs:
- baseTask.overrideAttrs (baseAttrs: {
- name = "${baseAttrs.name}-shell-build-inputs";
- buildPhase = ''
- echo "Can build shell environment for shellBuildInputs!"
- echo noop > $out
- '';
- });
- shellEnvironment = shellBuildInputs:
- pkgs.mkShell {
- name = "${baseName}-shell";
- buildInputs = shellBuildInputs;
- };
- overwritingPublishScript = { docsDerivation, overwrite ? true }:
- pkgs.writeShellScriptBin "publish.sh" ''
- set -euo pipefail
- OUT_DOCS="${docsDerivation}"
- ${
- if overwrite then "" else "# "
- }${pkgs.openssh}/bin/ssh -o StrictHostKeyChecking=no "$SERVER_URL" rm -rf "$DOCS_SERVER_PATH/*"
- ${pkgs.rsync}/bin/rsync -avzP \
- --rsh="ssh -o StrictHostKeyChecking=no" \
- "$OUT_DOCS/" \
- "$SERVER_URL:$DOCS_SERVER_PATH"
- '';
-}