43 lines
1.1 KiB
Nix
43 lines
1.1 KiB
Nix
pkgs: {
|
|
rebuidWithSopsSubmodule =
|
|
configPath: secretsPath:
|
|
pkgs.writeShellScriptBin "rebuidWithSopsSubmodule" ''
|
|
#!/bin/bash
|
|
|
|
export my_wd=$PWD
|
|
cd ${configPath}
|
|
|
|
if [ ! -d ./${secretsPath} ]; then
|
|
echo "Error: ${secretsPath} directory not found in ${configPath}"
|
|
echo "System not updated!"
|
|
cd $my_wd
|
|
unset my_wd
|
|
exit 1
|
|
fi
|
|
|
|
if [ -z "$(find ./${secretsPath} -maxdepth 1 -name '*.yaml' -print -quit)" ]; then
|
|
echo "Error: No .yaml files found in ${secretsPath} directory"
|
|
echo "System not updated!"
|
|
cd $my_wd
|
|
unset my_wd
|
|
exit 1
|
|
fi
|
|
|
|
mkdir ./secrets
|
|
cp ./${secretsPath}/*.yaml ./secrets/
|
|
git add ./secrets/*.yaml
|
|
|
|
if sudo nixos-rebuild switch --flake . "$@"; then
|
|
echo "Success: System successfully updated with new configuration!"
|
|
else
|
|
echo "Error: Failed to rebuild NixOS configuration"
|
|
echo "System not updated!"
|
|
fi
|
|
|
|
git reset ./secrets/*.yaml
|
|
rm ./secrets/*.yaml
|
|
rm -d ./secrets
|
|
cd $my_wd
|
|
unset my_wd
|
|
'';
|
|
}
|