From c69e0e2c7c840024b66a2ef8125587f0559b505f Mon Sep 17 00:00:00 2001 From: Dominik Polakovics Date: Sat, 23 Sep 2023 17:39:34 +0200 Subject: [PATCH] change phone config --- hosts/phone/configuration.nix | 8 ++--- hosts/phone/modules/bento.nix | 60 +++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 hosts/phone/modules/bento.nix diff --git a/hosts/phone/configuration.nix b/hosts/phone/configuration.nix index 915f583..969ec99 100644 --- a/hosts/phone/configuration.nix +++ b/hosts/phone/configuration.nix @@ -4,10 +4,10 @@ imports = [ (import { device = "pine64-pinephone"; }) ./hardware-configuration.nix - - # ./modules/sway - # - # ./utils/bento.nix + # + ./modules/sway + + ./modules/bento.nix ]; networking.hostName = "mobile-nixos"; diff --git a/hosts/phone/modules/bento.nix b/hosts/phone/modules/bento.nix new file mode 100644 index 0000000..9e7b919 --- /dev/null +++ b/hosts/phone/modules/bento.nix @@ -0,0 +1,60 @@ +{ + lib, + pkgs, + ... +}: let + timer = "*:0/15"; +in { + environment.sessionVariables = rec { + NIX_PATH = [ + "nixos-config=/var/bento/configuration.nix" + ]; + }; + + systemd.services.bento-upgrade = { + enable = true; + startAt = lib.mkDefault "${timer}"; + path = with pkgs; [openssh git nixos-rebuild nix gzip]; + serviceConfig.Type = "oneshot"; + script = '' + cd /var/bento + /bin/sh update.sh + sed -i 's/ --upgrade//g' bootstrap.sh + ''; + restartIfChanged = false; + }; + + systemd.services.bento-reboot = { + # this is disabled by default + # to avoid wrong expectations from users + enable = false; + startAt = "04:00"; + path = with pkgs; [coreutils systemd]; + serviceConfig.Type = "oneshot"; + script = '' + booted="$(readlink /run/booted-system/{initrd,kernel,kernel-modules})" + built="$(readlink /nix/var/nix/profiles/system/{initrd,kernel,kernel-modules})" + if [ ! "$booted" = "$built" ] + then + systemctl kexec || systemctl reboot + fi + ''; + }; + + + systemd.sockets.listen-update = { + enable = true; + wantedBy = ["sockets.target"]; + requires = ["network.target"]; + listenStreams = ["51337"]; + socketConfig.Accept = "yes"; + }; + + systemd.services."listen-update@" = { + path = with pkgs; [systemd]; + enable = true; + serviceConfig.StandardInput = "socket"; + serviceConfig.ExecStart = "${pkgs.systemd.out}/bin/systemctl start bento-upgrade.service"; + serviceConfig.ExecStartPost = "${pkgs.systemd.out}/bin/journalctl -f --no-pager -u bento-upgrade.service"; + }; +}