aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bash/fake-symlinks.sh4
-rw-r--r--default.nix2
-rw-r--r--nixos/utils.nix99
-rw-r--r--[l---------]utils.nix100
4 files changed, 103 insertions, 102 deletions
diff --git a/bash/fake-symlinks.sh b/bash/fake-symlinks.sh
index 42a483b..939f519 100644
--- a/bash/fake-symlinks.sh
+++ b/bash/fake-symlinks.sh
@@ -9,7 +9,9 @@ SRHT_REPOS_PATH="$HOME/dev/libre"
for repo in "${SRHT_REPOS[@]}"; do
REPO="$repo" envsubst < "$DOTFILES/templates/sr-ht-build.yaml" > "$SRHT_REPOS_PATH/$repo/.build.yml"
- cp "$DOTFILES/nixos/utils.nix" "$SRHT_REPOS_PATH/$repo/utils.nix"
+ if [[ "$repo" != "dotfiles" ]]; then
+ cp "$DOTFILES/utils.nix" "$SRHT_REPOS_PATH/$repo/utils.nix"
+ fi
if [[ "$repo" != "website" ]]; then
REPO="$repo" envsubst < "$DOTFILES/templates/env.sh" > "$SRHT_REPOS_PATH/$repo/env.sh"
fi
diff --git a/default.nix b/default.nix
index abc4694..da5e3f9 100644
--- a/default.nix
+++ b/default.nix
@@ -2,7 +2,7 @@ let
pkgs = import <nixpkgs> { };
rootSrc = pkgs.nix-gitignore.gitignoreSource [ ] ./.;
in rec {
- utils = import ./nixos/utils.nix {
+ utils = import ./utils.nix {
pkgs = pkgs;
src = rootSrc;
baseName = "dotfiles";
diff --git a/nixos/utils.nix b/nixos/utils.nix
deleted file mode 100644
index ad5d4a0..0000000
--- a/nixos/utils.nix
+++ /dev/null
@@ -1,99 +0,0 @@
-{ pkgs, src, baseName }:
-let
- nixfmt = import (builtins.fetchTarball
- "https://github.com/serokell/nixfmt/archive/master.tar.gz") { };
-in 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: {
- name = "${baseAttrs.name}-shellcheck";
- buildInputs = baseAttrs.buildInputs ++ [ pkgs.shellcheck ];
- buildPhase = ''
- find . -type f \( -name '*.sh' -and -regextype egrep ! -regex '${ignoredFindPattern}' \) -print0 | xargs -0 shellcheck
- touch $out
- '';
- });
- formatNix = baseTask.overrideAttrs (baseAttrs: {
- name = "${baseAttrs.name}-nixfmt";
- buildInputs = baseAttrs.buildInputs ++ [ 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 [
- "default.nix"
- "TODOs.org"
- ] else
- ignoredFiles);
- buildPhase = ''
- ag FIXME ${ignoredPattern} || {
- touch $out
- exit 0
- }
- echo " Found dangling FIXME markers on the project."
- exit 1
- '';
- });
- orgMkDocs = title:
- baseTask.overrideAttrs (baseAttrs: {
- name = "${baseAttrs.name}-docs";
- buildInputs = [ pkgs.pandoc pkgs.mkdocs ];
- buildPhase = ''
- # Convert from org-mode to markdown with pandoc
- find docs/ -type f -name '*.org' -print0 | xargs -0 -I{} pandoc -o {}.md {}.org
-
- # Give the generated markdown files to MkDocs
- mkdocs build
-
- # Build remaining one-off files
- pandoc README.org -o site/index.html --css docs/README.css --to=html5 --self-contained --metadata title="${title}"
-
- mv site/ $out/
- '';
- });
- 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
- '';
- });
- publishScript = docsDerivation:
- pkgs.writeShellScriptBin "publish.sh" ''
- set -euo pipefail
- OUT_DOCS="${docsDerivation}"
- ${pkgs.rsync}/bin/rsync -avzP
- --rsh="ssh -o StrictHostKeyChecking=no" \
- "$OUT_DOCS" \
- "$SERVER_URL:$DOCS_SERVER_PATH"
- '';
-}
diff --git a/utils.nix b/utils.nix
index f386d80..ad5d4a0 120000..100644
--- a/utils.nix
+++ b/utils.nix
@@ -1 +1,99 @@
-nixos/utils.nix \ No newline at end of file
+{ pkgs, src, baseName }:
+let
+ nixfmt = import (builtins.fetchTarball
+ "https://github.com/serokell/nixfmt/archive/master.tar.gz") { };
+in 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: {
+ name = "${baseAttrs.name}-shellcheck";
+ buildInputs = baseAttrs.buildInputs ++ [ pkgs.shellcheck ];
+ buildPhase = ''
+ find . -type f \( -name '*.sh' -and -regextype egrep ! -regex '${ignoredFindPattern}' \) -print0 | xargs -0 shellcheck
+ touch $out
+ '';
+ });
+ formatNix = baseTask.overrideAttrs (baseAttrs: {
+ name = "${baseAttrs.name}-nixfmt";
+ buildInputs = baseAttrs.buildInputs ++ [ 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 [
+ "default.nix"
+ "TODOs.org"
+ ] else
+ ignoredFiles);
+ buildPhase = ''
+ ag FIXME ${ignoredPattern} || {
+ touch $out
+ exit 0
+ }
+ echo " Found dangling FIXME markers on the project."
+ exit 1
+ '';
+ });
+ orgMkDocs = title:
+ baseTask.overrideAttrs (baseAttrs: {
+ name = "${baseAttrs.name}-docs";
+ buildInputs = [ pkgs.pandoc pkgs.mkdocs ];
+ buildPhase = ''
+ # Convert from org-mode to markdown with pandoc
+ find docs/ -type f -name '*.org' -print0 | xargs -0 -I{} pandoc -o {}.md {}.org
+
+ # Give the generated markdown files to MkDocs
+ mkdocs build
+
+ # Build remaining one-off files
+ pandoc README.org -o site/index.html --css docs/README.css --to=html5 --self-contained --metadata title="${title}"
+
+ mv site/ $out/
+ '';
+ });
+ 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
+ '';
+ });
+ publishScript = docsDerivation:
+ pkgs.writeShellScriptBin "publish.sh" ''
+ set -euo pipefail
+ OUT_DOCS="${docsDerivation}"
+ ${pkgs.rsync}/bin/rsync -avzP
+ --rsh="ssh -o StrictHostKeyChecking=no" \
+ "$OUT_DOCS" \
+ "$SERVER_URL:$DOCS_SERVER_PATH"
+ '';
+}