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,14 +129,17 @@
}; };
services = { services = {
"update-flake" = { "update-flake" =
path = with pkgs; [ let
script = pkgs.writeShellApplication {
name = "update-flake-script";
runtimeInputs = with pkgs; [
git git
openssh openssh
nix config.nix.package
nixos-rebuild config.system.build.nixos-rebuild
]; ];
script = '' text = ''
[[ ! -d '/root/nixconf' ]] && git clone git@github.com:itepastra/nixconf /root/nixconf [[ ! -d '/root/nixconf' ]] && git clone git@github.com:itepastra/nixconf /root/nixconf
cd /root/nixconf cd /root/nixconf
git fetch git fetch
@ -146,9 +149,13 @@
nixos-rebuild boot -L --flake . nixos-rebuild boot -L --flake .
git push git push
''; '';
};
in
{
serviceConfig = { serviceConfig = {
Type = "oneshot"; Type = "oneshot";
User = "root"; User = "root";
ExecStart = "${script}/bin/update-flake-script";
RemainAfterExit = true; RemainAfterExit = true;
}; };
wants = [ wants = [

View file

@ -3,6 +3,7 @@
# and in the NixOS manual (accessible by running nixos-help). # and in the NixOS manual (accessible by running nixos-help).
{ {
config,
pkgs, pkgs,
... ...
}: }:
@ -75,7 +76,7 @@
serviceConfig = { serviceConfig = {
Type = "exec"; Type = "exec";
User = "root"; 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 = [ wants = [
"network-online.target" "network-online.target"

View file

@ -122,7 +122,7 @@ in
serviceConfig = { serviceConfig = {
Type = "exec"; Type = "exec";
User = "root"; 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..."''; ExecStopPost = ''shutdown -r +5 "Preparing update finished, rebooting..."'';
}; };
wants = [ wants = [