2024-02-08 21:30:20 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
2023-05-11 21:12:57 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.custom.chia;
|
2023-07-23 15:28:11 +01:00
|
|
|
|
|
|
|
ctl = pkgs.writeScriptBin "chiactl" ''
|
|
|
|
#! ${pkgs.runtimeShell}
|
2024-02-08 21:30:20 +00:00
|
|
|
set -e
|
|
|
|
sudo ${pkgs.podman}/bin/podman exec chia chia "$@"
|
2023-07-23 15:28:11 +01:00
|
|
|
'';
|
2023-05-11 21:12:57 +01:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options.custom.chia = {
|
|
|
|
enable = lib.mkEnableOption "chia";
|
|
|
|
|
|
|
|
path = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = "/var/lib/chia";
|
|
|
|
};
|
|
|
|
keyFile = lib.mkOption {
|
|
|
|
type = with lib.types; nullOr str;
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
plotDirectories = lib.mkOption {
|
2024-10-19 01:21:41 +01:00
|
|
|
type = with lib.types; listOf str;
|
|
|
|
default = [ ];
|
2023-05-11 21:12:57 +01:00
|
|
|
};
|
2023-06-04 21:36:07 +01:00
|
|
|
openFirewall = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
|
|
|
default = false;
|
|
|
|
};
|
2023-05-11 21:12:57 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
2023-07-23 15:28:11 +01:00
|
|
|
environment.systemPackages = [ ctl ];
|
2023-05-11 21:12:57 +01:00
|
|
|
|
2024-02-08 21:30:20 +00:00
|
|
|
users.groups.chia = {
|
|
|
|
gid = config.ids.gids.chia;
|
|
|
|
};
|
2023-05-11 21:12:57 +01:00
|
|
|
users.users.chia = {
|
|
|
|
home = cfg.path;
|
|
|
|
createHome = true;
|
|
|
|
isSystemUser = true;
|
|
|
|
group = "chia";
|
2024-02-08 21:30:20 +00:00
|
|
|
uid = config.ids.uids.chia;
|
2023-05-11 21:12:57 +01:00
|
|
|
};
|
|
|
|
|
2024-02-08 21:30:20 +00:00
|
|
|
virtualisation.oci-containers.containers.chia = {
|
2024-09-22 21:09:31 +01:00
|
|
|
image = "ghcr.io/chia-network/chia:2.4.3";
|
2024-02-08 21:30:20 +00:00
|
|
|
ports = [ "8444" ];
|
|
|
|
extraOptions = [
|
|
|
|
"--uidmap=0:${toString config.users.users.chia.uid}:1"
|
|
|
|
"--gidmap=0:${toString config.users.groups.chia.gid}:1"
|
|
|
|
];
|
|
|
|
volumes = [
|
|
|
|
"${cfg.keyFile}:/run/keyfile"
|
|
|
|
"${cfg.path}/.chia:/root/.chia"
|
|
|
|
] ++ lib.lists.imap0 (i: v: "${v}:/plots${toString i}") cfg.plotDirectories;
|
|
|
|
environment = {
|
|
|
|
keys = "/run/keyfile";
|
|
|
|
plots_dir = lib.strings.concatImapStringsSep ":" (i: v: "/plots${toString i}") cfg.plotDirectories;
|
2023-05-11 21:12:57 +01:00
|
|
|
};
|
|
|
|
};
|
2023-06-04 21:36:07 +01:00
|
|
|
|
2024-10-20 16:21:58 +01:00
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d ${cfg.path} 0700 chia chia - -"
|
|
|
|
"d ${cfg.path}/.chia 0700 chia chia - -"
|
|
|
|
];
|
|
|
|
|
2023-06-04 21:36:07 +01:00
|
|
|
networking.firewall = lib.mkIf cfg.openFirewall {
|
|
|
|
allowedTCPPorts = [ 8444 ];
|
|
|
|
};
|
2023-05-11 21:12:57 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-06-10 09:32:27 +01:00
|
|
|
|