-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapply
executable file
·39 lines (38 loc) · 1.67 KB
/
apply
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/run/current-system/sw/bin/bash
baseDir=$(readlink -f $(dirname $0)) # pwd of shell script
nixosConfigPath=/etc/nixos
# local nixosPath = /etc/nixos
hard-link-recursive() {
local srcDir=$1
local destDir=$2
local nixFiles=$(find $srcDir -maxdepth 1 -type f -not -name "*.md" -a -not -name ".*" -a -name "*\.*")
if [ ! -d ${destDir} ]; then
echo "Creating directory: $destDir"
sudo mkdir ${destDir}
fi
# echo "linking [ ${basename $nixFiles} ] to $destDir"
sudo ln -fn $nixFiles ${destDir}
local dirs=$(find $srcDir -maxdepth 1 -type d -not -path '*.*' -not -path $srcDir) # all directories except the current one and hidden ones
for dir in $dirs; do
hard-link-recursive $dir $destDir/$(basename $dir)
done
}
echo "This script's parent directory: $baseDir"
echo "Deleting: $nixosConfigPath/* ..."
sudo rm -rf $nixosConfigPath/* # Clear everything in your nixos config and remake.
hard-link-recursive $baseDir $nixosConfigPath
echo "Finished config linking to $nixosConfigPath"
echo "Removing $nixosConfigPath/hardware-configuration.nix..."
sudo rm /etc/nixos/hardware-configuration.nix # remove hardware config
sudo nixos-generate-config # to get your hardware config back
# rebuild and switch
echo "Rebuilding and switching to new config..."
if [ -z $1 ]; then # -z true if len of str is 0
sudo nixos-rebuild --show-trace switch --flake $nixosConfigPath/#$NIXOS_FLAKE_CONFIGURATION
exit 0
fi
sudo systemctl stop docker-port-website.service
sudo docker stop $(sudo docker ps -a -q)
sudo docker system prune --all
# sudo docker volumes rm $(sudo docker ps -a -q)
sudo nixos-rebuild --show-trace switch --flake $nixosConfigPath/#$1