|
| 1 | +{ ... }: |
| 2 | +{ |
| 3 | + flake.modules.nixos.pharos = |
| 4 | + { |
| 5 | + config, |
| 6 | + lib, |
| 7 | + pkgs, |
| 8 | + ... |
| 9 | + }: |
| 10 | + let |
| 11 | + cfg = config.services.pharos; |
| 12 | + # In order to get the hash and digest of the image, use: |
| 13 | + # nix run nixpkgs#nix-prefetch-docker -- --image-name 'public.ecr.aws/k2g7b7g1/pharos' --image-tag latest |
| 14 | + # The url can be found in the pharos documentation |
| 15 | + # https://docs.pharosnetwork.xyz/node-and-validator-guide/validator-node-deployment/using-docker-testnet |
| 16 | + # https://docs.pharosnetwork.xyz/node-and-validator-guide/validator-node-deployment/using-docker-devnet |
| 17 | + images = { |
| 18 | + "testnet" = { |
| 19 | + image = "public.ecr.aws/k2g7b7g1/pharos/testnet"; |
| 20 | + tag = "63b85b6b"; |
| 21 | + digest = "sha256:547a8519a11ab455871594580f7f5342863fb84d4a07c936969afe05f3aab358"; |
| 22 | + sha256 = "sha256-WNCWeoQnT7TLmVQY+NuMtOXBtJ8TFlSNCekNWX90gDk="; |
| 23 | + }; |
| 24 | + "devnet" = { |
| 25 | + image = "public.ecr.aws/k2g7b7g1/pharos"; |
| 26 | + tag = "latest"; |
| 27 | + digest = "sha256:82c7d84fc7d7f17056e947030c4a67bf23a139fe19539a6b237ab42df8215e7b"; |
| 28 | + sha256 = "1lh9hna57y9n3h0lhmvy8grlg02caq6p1k9whgwp0av67wllk5km"; |
| 29 | + }; |
| 30 | + }; |
| 31 | + in |
| 32 | + { |
| 33 | + options.services.pharos = with lib; { |
| 34 | + enable = mkEnableOption (lib.mdDoc "Pharos"); |
| 35 | + network = mkOption { |
| 36 | + type = types.enum [ |
| 37 | + "testnet" |
| 38 | + "devnet" |
| 39 | + "mainnet" |
| 40 | + ]; |
| 41 | + default = "testnet"; |
| 42 | + description = "Network to connect to"; |
| 43 | + }; |
| 44 | + }; |
| 45 | + config = { |
| 46 | + virtualisation.oci-containers.containers."pharos-${cfg.network}" = { |
| 47 | + image = with images."${cfg.network}"; "${image}:${tag}"; |
| 48 | + |
| 49 | + imageFile = |
| 50 | + with images."${cfg.network}"; |
| 51 | + pkgs.dockerTools.pullImage { |
| 52 | + imageName = image; |
| 53 | + imageDigest = digest; |
| 54 | + sha256 = sha256; |
| 55 | + finalImageName = image; |
| 56 | + finalImageTag = tag; |
| 57 | + }; |
| 58 | + volumes = [ |
| 59 | + "/var/lib/pharos-${cfg.network}:/data" |
| 60 | + ]; |
| 61 | + ports = [ |
| 62 | + "18100:18100" |
| 63 | + "18200:18200" |
| 64 | + "19000:19000" |
| 65 | + ]; |
| 66 | + }; |
| 67 | + assertions = [ |
| 68 | + { |
| 69 | + assertion = cfg.network != "mainnet"; |
| 70 | + message = "Pharos is not available on mainnet yet"; |
| 71 | + } |
| 72 | + ]; |
| 73 | + systemd.tmpfiles.rules = [ |
| 74 | + "d /var/lib/pharos-${cfg.network} 0700 root root - -" |
| 75 | + ]; |
| 76 | + }; |
| 77 | + }; |
| 78 | +} |
0 commit comments