feat:add_aria2&syncthing_daemon

This commit is contained in:
dichgrem
2025-07-22 22:33:01 +08:00
parent 076593c25d
commit 336566fce5
4 changed files with 49 additions and 27 deletions

View File

@@ -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 地址
};
}