mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-02-16 17:14:00 +00:00
nixos/zeronet: init (#44842)
This commit is contained in:
parent
297a82f3eb
commit
17564e0ed9
@ -328,6 +328,7 @@
|
||||
qemu-libvirtd = 301;
|
||||
# kvm = 302; # unused
|
||||
# render = 303; # unused
|
||||
zeronet = 304;
|
||||
|
||||
# When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399!
|
||||
|
||||
@ -616,6 +617,7 @@
|
||||
qemu-libvirtd = 301;
|
||||
kvm = 302; # default udev rules from systemd requires these
|
||||
render = 303; # default udev rules from systemd requires these
|
||||
zeronet = 304;
|
||||
|
||||
# When adding a gid, make sure it doesn't match an existing
|
||||
# uid. Users and groups with the same name should have equal
|
||||
|
@ -620,6 +620,7 @@
|
||||
./services/networking/xl2tpd.nix
|
||||
./services/networking/xrdp.nix
|
||||
./services/networking/zerobin.nix
|
||||
./services/networking/zeronet.nix
|
||||
./services/networking/zerotierone.nix
|
||||
./services/networking/znc.nix
|
||||
./services/printing/cupsd.nix
|
||||
|
102
nixos/modules/services/networking/zeronet.nix
Normal file
102
nixos/modules/services/networking/zeronet.nix
Normal file
@ -0,0 +1,102 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
let
|
||||
cfg = config.services.zeronet;
|
||||
|
||||
zConfFile = pkgs.writeTextFile {
|
||||
name = "zeronet.conf";
|
||||
|
||||
text = ''
|
||||
[global]
|
||||
data_dir = ${cfg.dataDir}
|
||||
log_dir = ${cfg.logDir}
|
||||
'' + lib.optionalString (cfg.port != null) ''
|
||||
ui_port = ${toString cfg.port}
|
||||
'' + cfg.extraConfig;
|
||||
};
|
||||
in with lib; {
|
||||
options.services.zeronet = {
|
||||
enable = mkEnableOption "zeronet";
|
||||
|
||||
dataDir = mkOption {
|
||||
type = types.path;
|
||||
default = "/var/lib/zeronet";
|
||||
example = "/home/okina/zeronet";
|
||||
description = "Path to the zeronet data directory.";
|
||||
};
|
||||
|
||||
logDir = mkOption {
|
||||
type = types.path;
|
||||
default = "/var/log/zeronet";
|
||||
example = "/home/okina/zeronet/log";
|
||||
description = "Path to the zeronet log directory.";
|
||||
};
|
||||
|
||||
port = mkOption {
|
||||
type = types.nullOr types.int;
|
||||
default = null;
|
||||
example = 15441;
|
||||
description = "Optional zeronet port.";
|
||||
};
|
||||
|
||||
tor = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Use TOR for all zeronet traffic.";
|
||||
};
|
||||
|
||||
extraConfig = mkOption {
|
||||
type = types.lines;
|
||||
default = "";
|
||||
|
||||
description = ''
|
||||
Extra configuration. Contents will be added verbatim to the
|
||||
configuration file at the end.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
services.tor = mkIf cfg.tor {
|
||||
enable = true;
|
||||
controlPort = 9051;
|
||||
extraConfig = "CookieAuthentication 1";
|
||||
};
|
||||
|
||||
systemd.services.zeronet = {
|
||||
description = "zeronet";
|
||||
after = [ "network.target" (optionalString cfg.tor "tor.service") ];
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
|
||||
preStart = ''
|
||||
# Ensure folder exists or create it and permissions are correct
|
||||
mkdir -p ${escapeShellArg cfg.dataDir} ${escapeShellArg cfg.logDir}
|
||||
chmod 750 ${escapeShellArg cfg.dataDir} ${escapeShellArg cfg.logDir}
|
||||
chown zeronet:zeronet ${escapeShellArg cfg.dataDir} ${escapeShellArg cfg.logDir}
|
||||
'';
|
||||
|
||||
serviceConfig = {
|
||||
PermissionsStartOnly = true;
|
||||
PrivateTmp = "yes";
|
||||
User = "zeronet";
|
||||
Group = "zeronet";
|
||||
ExecStart = "${pkgs.zeronet}/bin/zeronet --config_file ${zConfFile}";
|
||||
};
|
||||
};
|
||||
|
||||
users = {
|
||||
groups.zeronet.gid = config.ids.gids.zeronet;
|
||||
|
||||
users.zeronet = {
|
||||
description = "zeronet service user";
|
||||
home = cfg.dataDir;
|
||||
createHome = true;
|
||||
group = "zeronet";
|
||||
extraGroups = mkIf cfg.tor [ "tor" ];
|
||||
uid = config.ids.uids.zeronet;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
meta.maintainers = with maintainers; [ chiiruno ];
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
python2Packages.buildPythonApplication rec {
|
||||
pname = "zeronet";
|
||||
version = "0.6.2";
|
||||
format = "other";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "HelloZeroNet";
|
||||
@ -12,9 +13,6 @@ python2Packages.buildPythonApplication rec {
|
||||
};
|
||||
|
||||
propagatedBuildInputs = with python2Packages; [ msgpack gevent ];
|
||||
|
||||
format = "other";
|
||||
|
||||
buildPhase = "${python2Packages.python.interpreter} -O -m compileall .";
|
||||
|
||||
installPhase = ''
|
||||
@ -22,14 +20,10 @@ python2Packages.buildPythonApplication rec {
|
||||
cp -r plugins src tools *.py $out/share/
|
||||
'';
|
||||
|
||||
# Wrap the main executable and set the log and data dir to something out of
|
||||
# the store
|
||||
postFixup = ''
|
||||
makeWrapper "$out/share/zeronet.py" "$out/bin/zeronet" \
|
||||
--set PYTHONPATH "$PYTHONPATH" \
|
||||
--set PATH ${python2Packages.python}/bin \
|
||||
--add-flags "--log_dir \$HOME/.local/share/zeronet/logs" \
|
||||
--add-flags "--data_dir \$HOME/.local/share/zeronet"
|
||||
--set PYTHONPATH "$PYTHONPATH" \
|
||||
--set PATH ${python2Packages.python}/bin
|
||||
'';
|
||||
|
||||
meta = with stdenv.lib; {
|
||||
|
Loading…
Reference in New Issue
Block a user