fix (user scripts): refactor update nixos script & remove comments

This commit is contained in:
Kirill Samoylenkov 2025-09-29 01:29:22 +05:00
parent 41ea5804e5
commit a52c868ecf
2 changed files with 17 additions and 17 deletions

View file

@ -15,7 +15,6 @@ let
type = config.sops.secrets."sing_box/type".path;
in
{
# Sops
sops.secrets = {
"sing_box/flow" = { };
"sing_box/packet_encoding" = { };
@ -33,7 +32,6 @@ in
httpProxy = "http://127.0.0.1:12634";
};
# Sing-box
services.sing-box = {
enable = true;
package = pkgs.old.sing-box;

View file

@ -1,40 +1,42 @@
pkgs: {
updateSystem =
rebuidWithSopsSubmodule =
configPath: secretsPath:
pkgs.writeShellScriptBin "updateSystem" ''
pkgs.writeShellScriptBin "rebuidWithSopsSubmodule" ''
#!/bin/bash
export my_wd=$PWD
cd ${configPath}
if [ ! -d "${secretsPath}" ]; then
echo "!!! Error !!! NixConfigSecrets directory not found in ${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 NixConfigSecrets -maxdepth 1 -name '*.yaml' -print -quit)" ]; then
echo "!!! Error !!! No .yaml files found in NixConfigSecrets directory"
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 -r NixConfigSecrets/*.yaml secrets/
git add secrets/*.yaml
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"
echo "Success: System successfully updated with new configuration!"
else
echo "!!! Failure !!! Failed to apply NixOS configuration"
echo "System version remains unchanged"
echo "Error: Failed to rebuild NixOS configuration"
echo "System not updated!"
fi
git reset secrets/*.yaml
rm secrets/*.yaml
rm -d secrets
git reset ./secrets/*.yaml
rm ./secrets/*.yaml
rm -d ./secrets
cd $my_wd
unset my_wd
'';