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 0000000..18f33bf Binary files /dev/null and b/secrets/chia/farmer.key.age differ 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 ]; }