From 1c7d449c6f091d6dd27088e8ae30c5b1e18be9e2 Mon Sep 17 00:00:00 2001 From: Jake Hillion Date: Thu, 11 May 2023 21:12:57 +0100 Subject: [PATCH] chia: create service and start syncing --- .../default.nix | 14 +++ modules/chia.nix | 81 ++++++++++++++++++ modules/default.nix | 1 + secrets/chia/farmer.key.age | Bin 0 -> 1190 bytes secrets/secrets.nix | 3 + 5 files changed, 99 insertions(+) create mode 100644 modules/chia.nix create mode 100644 secrets/chia/farmer.key.age diff --git a/hosts/tywin.storage.ts.hillion.co.uk/default.nix b/hosts/tywin.storage.ts.hillion.co.uk/default.nix index 4e7d02e..8eb3809 100644 --- a/hosts/tywin.storage.ts.hillion.co.uk/default.nix +++ b/hosts/tywin.storage.ts.hillion.co.uk/default.nix @@ -56,5 +56,19 @@ }; in builtins.map (mkFolder) folderNames; + + ## Chia + age.secrets."chia/farmer.key" = { + file = ../../secrets/chia/farmer.key.age; + owner = "chia"; + group = "chia"; + }; + custom.chia = { + enable = true; + path = "/data/chia"; + keyFile = config.age.secrets."chia/farmer.key".path; + targetAddress = "xch1tl87mjd9zpugs7qy2ysc3j4qlftqlyjn037jywq6v2y4kp22g74qahn6sw"; + plotDirectories = [ ]; + }; }; } diff --git a/modules/chia.nix b/modules/chia.nix new file mode 100644 index 0000000..e33a0e8 --- /dev/null +++ b/modules/chia.nix @@ -0,0 +1,81 @@ +{ config, pkgs, lib, ... }: + +let + cfg = config.custom.chia; +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; + }; + targetAddress = lib.mkOption { + type = with lib.types; nullOr str; + default = null; + }; + plotDirectories = lib.mkOption { + type = with lib.types; nullOr (listOf str); + default = null; + }; + }; + + config = lib.mkIf cfg.enable { + environment.systemPackages = with pkgs; [ chia ]; + + users.groups.chia = { }; + users.users.chia = { + home = cfg.path; + createHome = true; + isSystemUser = true; + group = "chia"; + }; + + systemd.services.chia = { + description = "Chia daemon."; + wantedBy = [ "multi-user.target" ]; + + preStart = with pkgs; lib.strings.concatStringsSep "\n" ([ "${pkgs.chia}/bin/chia init" ] + ++ (if cfg.keyFile == null then [ ] else [ "${pkgs.chia}/bin/chia keys add -f ${cfg.keyFile}" ]) + ++ (if cfg.targetAddress == null then [ ] else [ + '' + ${pkgs.yq-go}/bin/yq e \ + '.farmer.xch_target_address = "${cfg.targetAddress}" | .pool.xch_target_address = "${cfg.targetAddress}"' \ + -i ${cfg.path}/.chia/mainnet/config/config.yaml + '' + ]) ++ (if cfg.plotDirectories == null then [ ] else [ + '' + ${pkgs.yq-go}/bin/yq e \ + '.harvester.plot_directories = [${lib.strings.concatMapStringsSep "," (x: "\"" + x + "\"") cfg.plotDirectories}]' \ + -i ${cfg.path}/.chia/mainnet/config/config.yaml + '' + ])); + script = with pkgs; "${pkgs.chia}/bin/chia start farmer"; + preStop = with pkgs; "${pkgs.chia}/bin/chia stop -d farmer"; + + serviceConfig = { + Type = "forking"; + + User = "chia"; + Group = "chia"; + + WorkingDirectory = cfg.path; + + Restart = "always"; + RestartSec = 10; + TimeoutStopSec = 120; + OOMScoreAdjust = 1000; + + Nice = 2; + IOSchedulingClass = "best-effort"; + IOSchedulingPriority = 7; + }; + }; + }; +} + diff --git a/modules/default.nix b/modules/default.nix index 6e9039b..63aed6a 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -3,6 +3,7 @@ { imports = [ ./backups/default.nix + ./chia.nix ./desktop/awesome/default.nix ./locations.nix ./resilio.nix diff --git a/secrets/chia/farmer.key.age b/secrets/chia/farmer.key.age new file mode 100644 index 0000000000000000000000000000000000000000..18f33bf68e1d20022f6941c2dcde2cab3137aced GIT binary patch literal 1190 zcmYk4%j??&0LO=TF}htuaZ|S6Vc?vHHi;M^G=#JueM2b4D_Ps zZOTLx@iM&VWDK{9;1tC9H1e#Cm6h+X?3u}k01cDZU0v~X?2o0TbYjex6>xGcrh`rfR-MAqSqlRE1NipNs zn5|EyOewS*DnxQDP17>W#}i;+IkCAmCpku;s3jBgG=o%?aw=G9_L1&?sL5d6Drjsj}3 zm?BY|b6U48N>yutD>3Jc6xLr%Y-_+dnNw*&A^VhUjs##G_J{bw9wXRc5z^p}J@MwDQ=mWy_zfQ-yI{RDo%NYk3{l7jx`2N9ftv64dXijg8U%7nb zz@N(1duZ}f{NvAm9Juh+i+4YD{oF3nwy#`1{OYlrADs;M%CFtL^xd=Xp9}Ckdp^8D cf75}UJW*V*f*+py{o2`|{yt5g%+KHVFYz|0&j0`b literal 0 HcmV?d00001 diff --git a/secrets/secrets.nix b/secrets/secrets.nix index a3fe273..031073f 100644 --- a/secrets/secrets.nix +++ b/secrets/secrets.nix @@ -77,4 +77,7 @@ in "mastodon/social.hillion.co.uk/secret_key_base.age".publicKeys = jake_users ++ [ ts.strangervm.vm ]; "mastodon/social.hillion.co.uk/vapid_private_key.age".publicKeys = jake_users ++ [ ts.strangervm.vm ]; "mastodon/social.hillion.co.uk/mastodon_at_social.hillion.co.uk.age".publicKeys = jake_users ++ [ ts.strangervm.vm ]; + + # Chia Secrets + "chia/farmer.key.age".publicKeys = jake_users ++ [ ts.storage.tywin ]; }