Moved scripts to the overlay folder to be used as packages
All scripts have been moved to the overlay folder in the top level directory Overlay is now instantiated per configuration to make use of the host variable
This commit is contained in:
36
overlay/scripts/nix/fetchfromgh.nix
Normal file
36
overlay/scripts/nix/fetchfromgh.nix
Normal file
@@ -0,0 +1,36 @@
|
||||
{ pkgs ? import <nixpkgs> { } }:
|
||||
|
||||
pkgs.writeShellApplication {
|
||||
name = "fetchfromgh";
|
||||
runtimeInputs = [ pkgs.nix-prefetch-scripts ];
|
||||
text = ''
|
||||
if [ $# -ne 1 ] || ! echo "$1" | grep -qE "[A-Za-z0-9_-]+/[A-Za-z0-9_-]+"; then
|
||||
echo "Usage: fetchfromgh someuser/somerepo"
|
||||
echo " - i.e. fetchfromgh pagedMov/nixos-config"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! curl -s -o /dev/null -w "%{http_code}" "https://github.com/$1" | grep -q "200"; then
|
||||
echo "Couldn't find that repository, curl returned 404."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
json=$(nix-prefetch-git --quiet "https://github.com/$1")
|
||||
|
||||
url=$(echo "$json" | jq '.url' | tr -d '"')
|
||||
owner=$(echo "$url" | awk -F'/' '{print $(NF-1)}')
|
||||
repo=$(echo "$url" | awk -F'/' '{print $NF}')
|
||||
rev=$(echo "$json" | jq '.rev' | tr -d '"')
|
||||
hash=$(echo "$json" | jq '.hash' | tr -d '"')
|
||||
|
||||
output="\
|
||||
src = pkgs.fetchFromGitHub {
|
||||
owner = \"$owner\";
|
||||
repo = \"$repo\";
|
||||
rev = \"$rev\";
|
||||
hash = \"$hash\";
|
||||
};
|
||||
"
|
||||
echo "$output"
|
||||
'';
|
||||
}
|
||||
50
overlay/scripts/nix/garbage-collect.nix
Executable file
50
overlay/scripts/nix/garbage-collect.nix
Executable file
@@ -0,0 +1,50 @@
|
||||
{ pkgs }:
|
||||
pkgs.writeShellApplication {
|
||||
name = "garbage-collect";
|
||||
runtimeInputs = with pkgs; [
|
||||
bash
|
||||
coreutils
|
||||
gnugrep
|
||||
bc
|
||||
alsa-utils
|
||||
findutils
|
||||
nix
|
||||
];
|
||||
text = ''
|
||||
#!/run/current-system/sw/bin/bash
|
||||
|
||||
echo "This will delete all unused paths in the nix store and delete any files in the gtrash folder."
|
||||
echo -e "\033[1;4;38;2;243;139;168mThis process is irreversible.\033[0m Are you sure?"
|
||||
select yn in "Yes" "No"; do
|
||||
case $yn in
|
||||
Yes ) echo "Sweeping system..."; scheck && runbg aplay "$HOME/assets/sound/sys/collectgarbage.wav"; break;;
|
||||
No ) echo "Canceling garbage collection."; return;;
|
||||
esac
|
||||
done
|
||||
|
||||
output=$(nix-collect-garbage | tee /dev/tty)
|
||||
nix_freed=$(echo "$output" | grep -oP '\d+(\.\d+)? MiB freed' | cut -d' ' -f1)
|
||||
|
||||
# Get the size of the trash folder before deleting
|
||||
if [ "$(ls -A ~/.local/share/Trash/files/ 2>/dev/null)" ]; then
|
||||
rm_freed=$(du -sm ~/.local/share/Trash/files | awk '{print $1}')
|
||||
/run/current-system/sw/bin/rm -rfv ~/.local/share/Trash/files/* # Verbose output
|
||||
mkdir -p ~/.local/share/Trash/files
|
||||
else
|
||||
rm_freed="0"
|
||||
fi
|
||||
|
||||
total_freed=$(echo "$nix_freed + $rm_freed" | bc)
|
||||
|
||||
units=("MB" "GB" "TB" "PB")
|
||||
divisions=0
|
||||
while [ "$(echo "$total_freed >= 1024.0" | bc -l)" -eq 1 ]; do
|
||||
total_freed=$(echo "scale=2; $total_freed / 1024" | bc -l)
|
||||
divisions=$((divisions + 1))
|
||||
done
|
||||
|
||||
echo -e "System cleaning complete, freed \033[1;4;38;2;166;227;161m$total_freed ''${units[$divisions]}\033[0m in total"
|
||||
|
||||
scheck && runbg aplay "$HOME/assets/sound/sys/rm.wav"
|
||||
'';
|
||||
}
|
||||
9
overlay/scripts/nix/nsp.nix
Executable file
9
overlay/scripts/nix/nsp.nix
Executable file
@@ -0,0 +1,9 @@
|
||||
{ pkgs }:
|
||||
pkgs.writeShellApplication {
|
||||
name = "nsp";
|
||||
text = ''
|
||||
#!/run/current-system/sw/bin/bash
|
||||
|
||||
nix-shell -p "$@" --run zsh
|
||||
'';
|
||||
}
|
||||
19
overlay/scripts/nix/rebuild.nix
Executable file
19
overlay/scripts/nix/rebuild.nix
Executable file
@@ -0,0 +1,19 @@
|
||||
{ host, self, pkgs, }:
|
||||
pkgs.writeShellApplication {
|
||||
name = "rebuild";
|
||||
text = ''
|
||||
hooray() { scheck && runbg aplay ${self}/assets/sound/update.wav; }
|
||||
damn() { scheck && runbg aplay ${self}/assets/sound/error.wav; }
|
||||
[ $# -eq 0 ] && echo -e "\033[1;4;38;2;243;139;168mUsage\033[0m: rebuild -h for home config, rebuild -s for sys config, rebuild -a for both. Adding 'n' before the flag does a dry run, i.e. rebuild -nh" && damn && exit 1
|
||||
scheck && runbg aplay ${self}/assets/sound/nixswitch-start.wav
|
||||
case $1 in
|
||||
"-h" ) if nh home switch -c ${host}Home "$FLAKEPATH"; then hooray; else damn; fi;;
|
||||
"-s" ) if nh os switch -H ${host} "$FLAKEPATH"; then hooray; else damn; fi;;
|
||||
"-a" ) if sudo sleep 0.1 && nh os switch -H ${host} "$FLAKEPATH" && nh home switch -c ${host}Home "$FLAKEPATH"; then hooray; else damn; fi;;
|
||||
"-nh" ) if nh home switch -n -c ${host}Home "$FLAKEPATH"; then hooray; else damn; fi;;
|
||||
"-ns" ) if nh os switch -n -H ${host} "$FLAKEPATH"; then hooray; else damn; fi;;
|
||||
"-na" ) if sudo sleep 0.1 && nh os switch -n -H ${host} "$FLAKEPATH" && nh home switch -n -c ${host}Home "$FLAKEPATH"; then hooray; else damn; fi;;
|
||||
* ) echo -e "\033[1;4;38;2;243;139;168mUsage\033[0m: rebuild -h for home config, rebuild -s for sys config. Adding 'n' before the flag does a dry run, i.e. rebuild -nh" && damn && exit 1;;
|
||||
esac
|
||||
'';
|
||||
}
|
||||
Reference in New Issue
Block a user