From c1100c81a4a25f2e22fec8b1c5daec470edfd3a4 Mon Sep 17 00:00:00 2001 From: dichgrem Date: Wed, 23 Jul 2025 19:40:28 +0800 Subject: [PATCH] chore:misc_services --- hosts/dos/default.nix | 73 ++++++++++++++------------------------- modules/services/misc.nix | 39 ++++++++++++++++++++- modules/services/ntp.nix | 2 +- 3 files changed, 64 insertions(+), 50 deletions(-) diff --git a/hosts/dos/default.nix b/hosts/dos/default.nix index 4ac42a2..3f69c62 100644 --- a/hosts/dos/default.nix +++ b/hosts/dos/default.nix @@ -1,55 +1,32 @@ -{ lib, pkgs, username, ... }: - { - imports = [ ./hardware.nix ] + lib, + pkgs, + username, + ... +}: { + imports = + [ + ./hardware.nix + ] ++ lib.filesystem.listFilesRecursive ../../modules; - users.users."${username}" = { - extraGroups = [ "libvirtd" "networkmanager" "wheel" ]; - homeMode = "755"; - ignoreShellProgramCheck = true; - isNormalUser = true; - shell = pkgs.nushell; - }; - - # 不加载官方 aria2 模块 - services.aria2.enable = false; - - # 自定义 systemd 单元:aria2 - systemd.services.aria2 = { - description = "Aria2 Download Manager (dich)"; - after = [ "network.target" ]; - wants = [ "network.target" ]; - wantedBy = [ "multi-user.target" ]; - - serviceConfig = { - Type = "simple"; - User = username; - - ExecStartPre = [ - "${pkgs.coreutils}/bin/mkdir -p /home/${username}/.config/aria2" - "${pkgs.coreutils}/bin/touch /home/${username}/.config/aria2/aria2.session" + # Define users + # If use nixos-anywhere to install, hashedPassword should be declared before installation + users = { + # users.root = { + # hashedPassword = "xxxxxx"; could be generated by mkpasswd + # }; + users."${username}" = { + extraGroups = [ + "libvirtd" + "networkmanager" + "wheel" ]; - - ExecStart = "${pkgs.aria2}/bin/aria2c --conf-path=/home/${username}/.config/aria2/aria2.conf"; - - Restart = "always"; - RestartSec = "5s"; - - NoNewPrivileges = true; - PrivateTmp = true; + # hashedPassword = ""; + homeMode = "755"; + ignoreShellProgramCheck = true; + isNormalUser = true; + shell = pkgs.nushell; }; }; - - # 启用 Syncthing,为用户运行 - services.syncthing = { - enable = true; - user = username; - dataDir = "/home/${username}/Sync"; # Syncthing 默认同步文件夹 - configDir = "/home/${username}/.config/syncthing"; - guiAddress = "127.0.0.1:8384"; # Web UI 地址 - }; } - - - diff --git a/modules/services/misc.nix b/modules/services/misc.nix index 16a8dfe..541f0a7 100644 --- a/modules/services/misc.nix +++ b/modules/services/misc.nix @@ -1,4 +1,6 @@ -_: { +{ lib, pkgs, username, ... }: + +{ services = { # fgrim = { # enable = true; @@ -10,4 +12,39 @@ _: { scheduler = "scx_lavd"; }; }; + + services.aria2.enable = false; + systemd.services.aria2 = { + description = "Aria2 Download Manager (dich)"; + after = [ "network.target" ]; + wants = [ "network.target" ]; + wantedBy = [ "multi-user.target" ]; + + serviceConfig = { + Type = "simple"; + User = username; + + ExecStartPre = [ + "${pkgs.coreutils}/bin/mkdir -p /home/${username}/.config/aria2" + "${pkgs.coreutils}/bin/touch /home/${username}/.config/aria2/aria2.session" + ]; + + ExecStart = "${pkgs.aria2}/bin/aria2c --conf-path=/home/${username}/.config/aria2/aria2.conf"; + + Restart = "always"; + RestartSec = "5s"; + + NoNewPrivileges = true; + PrivateTmp = true; + }; + }; + + services.syncthing = { + enable = true; + user = username; + dataDir = "/home/${username}/Sync"; + configDir = "/home/${username}/.config/syncthing"; + guiAddress = "127.0.0.1:8384"; + }; } + diff --git a/modules/services/ntp.nix b/modules/services/ntp.nix index 5d9ca24..30649d0 100644 --- a/modules/services/ntp.nix +++ b/modules/services/ntp.nix @@ -5,7 +5,7 @@ _: { source = [ { address = "pool.ntp.org"; - mode = "pool"; + mode = "server"; } { address = "time.cloudflare.com";