{ pkgs, rootSrc ? pkgs.nix-gitignore.gitignoreSource [ ] ./., 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 = rootSrc; 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 = baseTask.overrideAttrs (baseAttrs: { name = "${baseAttrs.name}-fixme"; buildInputs = baseAttrs.buildInputs ++ [ pkgs.ag ]; buildPhase = '' ag FIXME --ignore default.nix || { touch $out exit 0 } echo "^^^^^^^^^^^^^^^^^" echo " Found dangling FIXME markers on the project xp" exit 1 ''; }); 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 ''; }); } # subtasks = rec { # shellcheck = baseTask.overrideAttrs(baseAttrs: { # name = "${baseAttrs.name}-shellcheck"; # buildInputs = baseAttrs.buildInputs ++ [ pkgs.shellcheck ]; # buildPhase = '' # export SHELLCHECK_OPTS="-e SC1090 -e SC1091 -e SC2139" # ignored='(encrypted|os-installation.sh|notmuch-post.sh)' # find . -type f -name '*.sh' | grep -E -v $ignored | xargs shellcheck # touch $out # ''; # }); # fixme = baseTask.overrideAttrs(baseAttrs: { # name = "${baseAttrs.name}-fixme"; # buildInputs = baseAttrs.buildInputs ++ [ ag ]; # buildPhase = '' # ag FIXME --ignore default.nix || { # touch $out # } # ''; # }); # uniqueFeeds = baseTask.overrideAttrs (baseAttrs: { # name = "${baseAttrs.name}-unique-feeds"; # buildPhase = '' # OUT="$(uniq -D <(sort ./newsboat/urls))" # [[ $OUT = "" ]] || { # echo "Duplicate subscriptions found in ./newsboat/urls:" # echo "$OUT" # exit 1 # } # touch $out # ''; # }); # formatNix = baseTask.overrideAttrs (baseAttrs: { # name = "${baseAttrs.name}-nixfmt"; # buildInputs = baseAttrs.buildInputs ++ [nixfmt]; # buildPhase = '' # diff <(nixfmt < default.nix) default.nix || { # echo "The default.nix is unformatted. To fix it, run:" # echo " nixfmt default.nix" # exit 1 # } # touch $out # ''; # }); # };