nixos/modules/chia.nix

72 lines
1.7 KiB
Nix
Raw Permalink Normal View History

{ config, pkgs, lib, ... }:
2023-05-11 21:12:57 +01:00
let
cfg = config.custom.chia;
ctl = pkgs.writeScriptBin "chiactl" ''
#! ${pkgs.runtimeShell}
set -e
sudo ${pkgs.podman}/bin/podman exec chia chia "$@"
'';
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 {
type = with lib.types; nullOr (listOf str);
default = null;
};
openFirewall = lib.mkOption {
type = lib.types.bool;
default = false;
};
2023-05-11 21:12:57 +01:00
};
config = lib.mkIf cfg.enable {
environment.systemPackages = [ ctl ];
2023-05-11 21:12:57 +01: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";
uid = config.ids.uids.chia;
2023-05-11 21:12:57 +01:00
};
virtualisation.oci-containers.containers.chia = {
2024-07-10 10:01:16 +01:00
image = "ghcr.io/chia-network/chia:2.4.1";
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
};
};
networking.firewall = lib.mkIf cfg.openFirewall {
allowedTCPPorts = [ 8444 ];
};
2023-05-11 21:12:57 +01:00
};
}
2023-06-10 09:32:27 +01:00