From 336566fce533984eb787c229e52ffe6bce77124f Mon Sep 17 00:00:00 2001 From: dichgrem Date: Tue, 22 Jul 2025 22:33:01 +0800 Subject: [PATCH] feat:add_aria2&syncthing_daemon --- dotfiles/.config/aria2/aria2.conf | 1 + .../{syncthingtray.nix => syncthing.nix} | 1 - hosts/dos/default.nix | 73 ++++++++++++------- modules/system/environment.nix | 1 - 4 files changed, 49 insertions(+), 27 deletions(-) rename home/gui/file-sync/{syncthingtray.nix => syncthing.nix} (78%) diff --git a/dotfiles/.config/aria2/aria2.conf b/dotfiles/.config/aria2/aria2.conf index 10f2df0..e8c3b5a 100644 --- a/dotfiles/.config/aria2/aria2.conf +++ b/dotfiles/.config/aria2/aria2.conf @@ -2,6 +2,7 @@ enable-rpc=true rpc-listen-all=true rpc-allow-origin-all=true rpc-listen-port=6800 +rpc-secret=adminadmin continue=true dir=/home/dich/Downloads input-file=/home/dich/.config/aria2/aria2.session diff --git a/home/gui/file-sync/syncthingtray.nix b/home/gui/file-sync/syncthing.nix similarity index 78% rename from home/gui/file-sync/syncthingtray.nix rename to home/gui/file-sync/syncthing.nix index d72a735..2e966fa 100644 --- a/home/gui/file-sync/syncthingtray.nix +++ b/home/gui/file-sync/syncthing.nix @@ -1,6 +1,5 @@ {pkgs, ...}: { home.packages = with pkgs; [ syncthing - syncthingtray ]; } diff --git a/hosts/dos/default.nix b/hosts/dos/default.nix index 3f69c62..4ac42a2 100644 --- a/hosts/dos/default.nix +++ b/hosts/dos/default.nix @@ -1,32 +1,55 @@ +{ lib, pkgs, username, ... }: + { - lib, - pkgs, - username, - ... -}: { - imports = - [ - ./hardware.nix - ] + imports = [ ./hardware.nix ] ++ lib.filesystem.listFilesRecursive ../../modules; - # 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" + 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" ]; - # hashedPassword = ""; - homeMode = "755"; - ignoreShellProgramCheck = true; - isNormalUser = true; - shell = pkgs.nushell; + + ExecStart = "${pkgs.aria2}/bin/aria2c --conf-path=/home/${username}/.config/aria2/aria2.conf"; + + Restart = "always"; + RestartSec = "5s"; + + NoNewPrivileges = true; + PrivateTmp = true; }; }; + + # 启用 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/system/environment.nix b/modules/system/environment.nix index a5cd6ea..eeb8dc9 100644 --- a/modules/system/environment.nix +++ b/modules/system/environment.nix @@ -53,7 +53,6 @@ in { curl nexttrace aria2 - syncthing #Blog zola