mirror of
https://github.com/librephoenix/nixos-config
synced 2025-10-18 17:44:06 +05:30
trying to make an automatic system updater/builder
This commit is contained in:
parent
3e63f2385f
commit
e5d9995856
2 changed files with 34 additions and 0 deletions
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
# dotfiles
|
# dotfiles
|
||||||
dotfilesDir = "/etc/nixos";
|
dotfilesDir = "/etc/nixos";
|
||||||
|
systemBuilder.enable = true;
|
||||||
|
|
||||||
# security
|
# security
|
||||||
security = {
|
security = {
|
||||||
|
|
|
@ -13,11 +13,18 @@
|
||||||
description = "Absolute path to my secrets flake";
|
description = "Absolute path to my secrets flake";
|
||||||
type = lib.types.path;
|
type = lib.types.path;
|
||||||
};
|
};
|
||||||
|
systemBuilder.enable = lib.mkEnableOption "Enable automatic config updater and builder";
|
||||||
|
systemBuilder.buildCronExpression = lib.mkOption {
|
||||||
|
default = "Sat *-*-* 02:00:00"; # Sat morning at 2am
|
||||||
|
description = "Cron expression for when the system should auto build config";
|
||||||
|
type = lib.types.str;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
config = {
|
config = {
|
||||||
environment.systemPackages = with pkgs; [
|
environment.systemPackages = with pkgs; [
|
||||||
attic-client
|
attic-client
|
||||||
|
git
|
||||||
(pkgs.writeScriptBin "phoenix" ''
|
(pkgs.writeScriptBin "phoenix" ''
|
||||||
if [[ $EUID -ne 0 ]]; then
|
if [[ $EUID -ne 0 ]]; then
|
||||||
echo "Error: This script must be run as root" 1>&2
|
echo "Error: This script must be run as root" 1>&2
|
||||||
|
@ -115,5 +122,31 @@
|
||||||
fi
|
fi
|
||||||
'')
|
'')
|
||||||
];
|
];
|
||||||
|
systemd.services."phoenix-system-builder" = lib.mkIf config.systemSettings.systemBuilder.enable {
|
||||||
|
script = ''
|
||||||
|
pushd /etc/nixos;
|
||||||
|
/run/current-system/sw/bin/git pull;
|
||||||
|
nix flake update;
|
||||||
|
/run/current-system/sw/bin/git stage *;
|
||||||
|
/run/current-system/sw/bin/git commit -m "Updated system";
|
||||||
|
/run/current-system/sw/bin/git push;
|
||||||
|
popd;
|
||||||
|
pushd /etc/nixos.secrets;
|
||||||
|
/run/current-system/sw/bin/git pull;
|
||||||
|
popd;
|
||||||
|
/run/current-system/sw/bin/phoenix build;
|
||||||
|
'';
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "simple";
|
||||||
|
User = "root";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
systemd.timers."phoenix-system-builder-auto" = lib.mkIf config.systemSettings.systemBuilder.enable {
|
||||||
|
wantedBy = [ "timers.target" ];
|
||||||
|
timerConfig = {
|
||||||
|
OnCalendar = config.systemSettings.systemBuilder.buildCronExpression;
|
||||||
|
Unit = "phoenix-system-builder.service";
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue