use system configured nix and nixos-rebuild

This commit is contained in:
Noa Aarts 2025-05-09 10:11:47 +02:00
parent 40c48532b6
commit 16ba56e9dc
Signed by: noa
GPG key ID: 1850932741EFF672
3 changed files with 39 additions and 31 deletions

View file

@ -129,36 +129,43 @@
};
services = {
"update-flake" = {
path = with pkgs; [
git
openssh
nix
nixos-rebuild
];
script = ''
[[ ! -d '/root/nixconf' ]] && git clone git@github.com:itepastra/nixconf /root/nixconf
cd /root/nixconf
git fetch
git reset --hard origin/main
git pull
nix flake update --commit-lock-file
nixos-rebuild boot -L --flake .
git push
'';
serviceConfig = {
Type = "oneshot";
User = "root";
RemainAfterExit = true;
"update-flake" =
let
script = pkgs.writeShellApplication {
name = "update-flake-script";
runtimeInputs = with pkgs; [
git
openssh
config.nix.package
config.system.build.nixos-rebuild
];
text = ''
[[ ! -d '/root/nixconf' ]] && git clone git@github.com:itepastra/nixconf /root/nixconf
cd /root/nixconf
git fetch
git reset --hard origin/main
git pull
nix flake update --commit-lock-file
nixos-rebuild boot -L --flake .
git push
'';
};
in
{
serviceConfig = {
Type = "oneshot";
User = "root";
ExecStart = "${script}/bin/update-flake-script";
RemainAfterExit = true;
};
wants = [
"network-online.target"
];
after = [
"network-online.target"
];
restartIfChanged = false;
};
wants = [
"network-online.target"
];
after = [
"network-online.target"
];
restartIfChanged = false;
};
};
user.services.polkit-gnome-authentication-agent-1 = {
description = "polkit-gnome-authentication-agent-1";

View file

@ -3,6 +3,7 @@
# and in the NixOS manual (accessible by running nixos-help).
{
config,
pkgs,
...
}:
@ -75,7 +76,7 @@
serviceConfig = {
Type = "exec";
User = "root";
ExecStart = "${pkgs.nixos-rebuild-ng}/bin/nixos-rebuild switch --flake github:itepastra/nixconf";
ExecStart = "${config.system.build.nixos-rebuild}/bin/nixos-rebuild switch --flake github:itepastra/nixconf";
};
wants = [
"network-online.target"

View file

@ -122,7 +122,7 @@ in
serviceConfig = {
Type = "exec";
User = "root";
ExecStart = "${pkgs.nixos-rebuild-ng}/bin/nixos-rebuild boot --flake github:itepastra/nixconf";
ExecStart = "${config.system.build.nixos-rebuild}/bin/nixos-rebuild switch --flake github:itepastra/nixconf";
ExecStopPost = ''shutdown -r +5 "Preparing update finished, rebooting..."'';
};
wants = [