mirror of
https://gitlab.com/TECHNOFAB/soonix.git
synced 2026-02-02 15:25:05 +01:00
Compare commits
2 commits
880ebb6e42
...
bfe628020c
| Author | SHA1 | Date | |
|---|---|---|---|
| bfe628020c | |||
| aef4bc1a26 |
1 changed files with 61 additions and 63 deletions
124
lib/module.nix
124
lib/module.nix
|
|
@ -4,7 +4,7 @@
|
||||||
lib,
|
lib,
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
inherit (lib) types mkOption concatMapStringsSep;
|
inherit (lib) types mkOption concatMapStringsSep mapAttrsToList;
|
||||||
soonix_lib = import ./. {inherit pkgs;};
|
soonix_lib = import ./. {inherit pkgs;};
|
||||||
inherit (soonix_lib) engines buildAllFiles;
|
inherit (soonix_lib) engines buildAllFiles;
|
||||||
in {
|
in {
|
||||||
|
|
@ -253,70 +253,74 @@ in {
|
||||||
builtins.addErrorContext "[soonix] while generating shell hook"
|
builtins.addErrorContext "[soonix] while generating shell hook"
|
||||||
# sh
|
# sh
|
||||||
''
|
''
|
||||||
CHECK_MODE=''${CHECK_MODE:-false}
|
function _soonix() {
|
||||||
SKIP_GITIGNORE=''${SKIP_GITIGNORE:-false}
|
CHECK_MODE=''${CHECK_MODE:-false}
|
||||||
|
SKIP_GITIGNORE=''${SKIP_GITIGNORE:-false}
|
||||||
|
|
||||||
_soonix_log() {
|
_soonix_log() {
|
||||||
local level="$1"
|
local level="$1"
|
||||||
local hook="$2"
|
local hook="$2"
|
||||||
local message="$3"
|
local message="$3"
|
||||||
[[ "''${SOONIX_LOG-}" == "true" ]] && echo "$level [$hook]: $message" || true
|
[[ "''${SOONIX_LOG-}" == "true" ]] && echo "$level [$hook]: $message" || true
|
||||||
}
|
}
|
||||||
|
|
||||||
_soonix_add_to_gitignore() {
|
_soonix_add_to_gitignore() {
|
||||||
local file="$1"
|
local file="$1"
|
||||||
local gitignore=".gitignore"
|
local gitignore=".gitignore"
|
||||||
|
|
||||||
if [[ ! -f "$gitignore" ]]; then
|
if [[ ! -f "$gitignore" ]]; then
|
||||||
touch "$gitignore"
|
touch "$gitignore"
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if file is already in gitignore
|
|
||||||
if ! grep -Fxq "/$file" "$gitignore"; then
|
|
||||||
# Add sentinel comments if not present
|
|
||||||
if ! grep -q "# soonix" "$gitignore"; then
|
|
||||||
echo "" >> "$gitignore"
|
|
||||||
echo "# soonix" >> "$gitignore"
|
|
||||||
echo "# end soonix" >> "$gitignore"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Insert the file path before the end comment
|
# Check if file is already in gitignore
|
||||||
${pkgs.gnused}/bin/sed -i "/# end soonix/i /$file" "$gitignore"
|
if ! grep -Fxq "/$file" "$gitignore"; then
|
||||||
|
# Add sentinel comments if not present
|
||||||
|
if ! grep -q "# soonix" "$gitignore"; then
|
||||||
|
echo "" >> "$gitignore"
|
||||||
|
echo "# soonix" >> "$gitignore"
|
||||||
|
echo "# end soonix" >> "$gitignore"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Insert the file path before the end comment
|
||||||
|
${pkgs.gnused}/bin/sed -i "/# end soonix/i /$file" "$gitignore"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_soonix_updated=()
|
||||||
|
_soonix_failed=()
|
||||||
|
_soonix_uptodate=()
|
||||||
|
|
||||||
|
${runHooks}
|
||||||
|
|
||||||
|
local output=$'\E[msoonix:\E[38;5;8m'
|
||||||
|
local status=0
|
||||||
|
|
||||||
|
if [[ ''${#_soonix_updated[@]} -gt 0 ]]; then
|
||||||
|
output="$output [updated: ''${_soonix_updated[*]}]" >&2
|
||||||
|
if [[ "$CHECK_MODE" == "true" ]]; then
|
||||||
|
status=2
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
if [[ ''${#_soonix_uptodate[@]} -gt 0 ]]; then
|
||||||
|
output="$output [unchanged: ''${_soonix_uptodate[*]}]" >&2
|
||||||
|
fi
|
||||||
|
if [[ ''${#_soonix_failed[@]} -gt 0 ]]; then
|
||||||
|
output="$output [failed: ''${_soonix_failed[*]}]" >&2
|
||||||
|
status=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf "%s\E[m\n" "$output" >&2
|
||||||
|
|
||||||
|
if [[ $status -ne 0 ]]; then
|
||||||
|
exit $status
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
_soonix
|
||||||
_soonix_updated=()
|
unset _soonix
|
||||||
_soonix_failed=()
|
|
||||||
_soonix_uptodate=()
|
|
||||||
|
|
||||||
${runHooks}
|
|
||||||
|
|
||||||
local output=$'\E[msoonix:\E[38;5;8m'
|
|
||||||
local status=0
|
|
||||||
|
|
||||||
if [[ ''${#_soonix_updated[@]} -gt 0 ]]; then
|
|
||||||
output="$output [updated: ''${_soonix_updated[*]}]" >&2
|
|
||||||
if [[ "$CHECK_MODE" == "true" ]]; then
|
|
||||||
status=2
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [[ ''${#_soonix_uptodate[@]} -gt 0 ]]; then
|
|
||||||
output="$output [unchanged: ''${_soonix_uptodate[*]}]" >&2
|
|
||||||
fi
|
|
||||||
if [[ ''${#_soonix_failed[@]} -gt 0 ]]; then
|
|
||||||
output="$output [failed: ''${_soonix_failed[*]}]" >&2
|
|
||||||
status=1
|
|
||||||
fi
|
|
||||||
|
|
||||||
printf "%s\E[m\n" "$output" >&2
|
|
||||||
|
|
||||||
if [[ $status -ne 0 ]]; then
|
|
||||||
exit $status
|
|
||||||
fi
|
|
||||||
'';
|
'';
|
||||||
|
|
||||||
allFiles =
|
allFiles =
|
||||||
lib.mapAttrsToList (name: hook: {
|
mapAttrsToList (name: hook: {
|
||||||
src = hook.generatedDerivation;
|
src = hook.generatedDerivation;
|
||||||
path = hook.output;
|
path = hook.output;
|
||||||
})
|
})
|
||||||
|
|
@ -415,18 +419,12 @@ in {
|
||||||
'') (builtins.attrNames hooks)}
|
'') (builtins.attrNames hooks)}
|
||||||
;;
|
;;
|
||||||
update)
|
update)
|
||||||
function _soonix() {
|
${generateShellHook}
|
||||||
${generateShellHook}
|
|
||||||
}
|
|
||||||
_soonix
|
|
||||||
;;
|
;;
|
||||||
check)
|
check)
|
||||||
CHECK_MODE=true
|
CHECK_MODE=true
|
||||||
echo "Checking files..."
|
echo "Checking files..."
|
||||||
function _soonix() {
|
${generateShellHook}
|
||||||
${generateShellHook}
|
|
||||||
}
|
|
||||||
_soonix
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
'';
|
'';
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue