diff --git a/machine/not522/default.nix b/machine/not522/default.nix index a9ae4ade..23e188f1 100644 --- a/machine/not522/default.nix +++ b/machine/not522/default.nix @@ -12,4 +12,5 @@ ]; system.stateVersion = "24.11"; nixpkgs.config.allowUnsupportedSystem = true; + boot.initrd.timesync.enable = true; } diff --git a/machine/not522/installer/default.nix b/machine/not522/installer/default.nix index 1b560dff..194664af 100644 --- a/machine/not522/installer/default.nix +++ b/machine/not522/installer/default.nix @@ -26,6 +26,7 @@ in { "${nixos-config}/machine/not522/cross-packages.nix" ./disko.nix ]; + boot.initrd.timesync.enable = true; system.stateVersion = config.system.nixos.version; diff --git a/modules/boot/timesync.nix b/modules/boot/timesync.nix new file mode 100644 index 00000000..a5d9e69f --- /dev/null +++ b/modules/boot/timesync.nix @@ -0,0 +1,36 @@ +{ + config, + lib, + ... +}: +with lib; { + options.boot.initrd.timesync = { + enable = mkEnableOption "Enables time synchronization in initrd"; + }; + + config = mkIf config.boot.initrd.timesync.enable { + boot.initrd.systemd.network = { + enable = true; + wait-online.enable = true; + }; + boot.initrd.systemd.services.sync-time = { + description = "Network Time Synchronization"; + wantedBy = [ + "initrd.target" + "rootfs-cleanup.service" + ]; + wants = [ + "network-online.target" + ]; + after = [ + "network-online.target" + ]; + before = [ + "rootfs-cleanup.service" + ]; + unitConfig.DefaultDependencies = "no"; + environment.SYSTEMD_NSS_RESOLVE_VALIDATE = "0"; + serviceConfig.ExecStart = "${config.boot.initrd.systemd.package}/lib/systemd/systemd-timesyncd"; + }; + }; +} diff --git a/modules/default.nix b/modules/default.nix index 77243d2f..7fbae655 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -1,5 +1,6 @@ {disko, ...}: { imports = [ + ./boot/timesync.nix ./riscv.nix ./containers/autoconfig.nix ./nix diff --git a/modules/environment/impermanence.nix b/modules/environment/impermanence.nix index 18b636d7..98eb0731 100644 --- a/modules/environment/impermanence.nix +++ b/modules/environment/impermanence.nix @@ -18,6 +18,7 @@ with lib; { } (mkIf config.environment.impermanence { boot.initrd.systemd.services.rootfs-cleanup = { + description = "Clean file system root"; wantedBy = [ "initrd.target" ];