nixos/modules/chia.nix

77 lines
1.8 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 {
2024-10-19 01:21:41 +01:00
type = with lib.types; listOf str;
default = [ ];
2023-05-11 21:12:57 +01:00
};
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-09-22 21:09:31 +01:00
image = "ghcr.io/chia-network/chia:2.4.3";
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
};
};
2024-10-20 16:21:58 +01:00
systemd.tmpfiles.rules = [
"d ${cfg.path} 0700 chia chia - -"
"d ${cfg.path}/.chia 0700 chia chia - -"
];
networking.firewall = lib.mkIf cfg.openFirewall {
allowedTCPPorts = [ 8444 ];
};
2023-05-11 21:12:57 +01:00
};
}
2023-06-10 09:32:27 +01:00