|
| 1 | +# When using this file as the base for a real deployment, |
| 2 | +# make sure to check all lines marked by 'FIXME:' |
| 3 | + |
| 4 | +# This file is used by ./deploy.sh to deploy a container with |
| 5 | +# age-encrypted secrets. |
| 6 | + |
| 7 | +{ |
| 8 | + inputs.nix-bitcoin.url = "github:fort-nix/nix-bitcoin/release"; |
| 9 | + inputs.agenix.url = "github:ryantm/agenix"; |
| 10 | + inputs.agenix.inputs.nixpkgs.follows = "nix-bitcoin/nixpkgs"; |
| 11 | + |
| 12 | + inputs.flake-utils.follows = "nix-bitcoin/flake-utils"; |
| 13 | + |
| 14 | + outputs = { self, nix-bitcoin, agenix, flake-utils }: { |
| 15 | + modules = { |
| 16 | + demoNode = { config, lib, ... }: { |
| 17 | + imports = [ |
| 18 | + # TODO-EXTERNAL: |
| 19 | + # Set this to `agenix.nixosModules.default` when |
| 20 | + # https://github.com/ryantm/agenix/pull/126 is merged |
| 21 | + agenix.nixosModules.age |
| 22 | + nix-bitcoin.nixosModules.default |
| 23 | + (nix-bitcoin + "/modules/secrets/age.nix") |
| 24 | + ]; |
| 25 | + |
| 26 | + # Use age-encrypted secrets |
| 27 | + nix-bitcoin.age = { |
| 28 | + enable = true; |
| 29 | + |
| 30 | + # The local secrets dir and its contents can be created with the |
| 31 | + # `generateAgeSecrets` flake package (defined below). |
| 32 | + # Use it like so: |
| 33 | + # nix run .#generateAgeSecrets |
| 34 | + # and commit the newly created ./secrets dir afterwards. |
| 35 | + # |
| 36 | + # This script must be rerun when adding node services that |
| 37 | + # require new secrets. |
| 38 | + # |
| 39 | + # For a real-life example, see ./deploy.sh |
| 40 | + secretsSourceDir = ./secrets; |
| 41 | + |
| 42 | + # FIXME: |
| 43 | + # Set this to a public SSH host key of your node (preferably key type `ed25519`). |
| 44 | + # You can query host keys with command `ssh-keyscan <node address>`. |
| 45 | + # The keys defined here are used to age-encrypt the secrets. |
| 46 | + publicKeys = [ |
| 47 | + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDoAaEMk8jMbg5MnvKDApWC6EpUHRJTzavy/wU2EtgtU" |
| 48 | + ]; |
| 49 | + }; |
| 50 | + |
| 51 | + # Enable services. |
| 52 | + # See ../configuration.nix for all available features. |
| 53 | + services.bitcoind.enable = true; |
| 54 | + # |
| 55 | + # See ../flakes/flake.nix for more settings useful for production nodes. |
| 56 | + |
| 57 | + |
| 58 | + # WARNING: |
| 59 | + # FIXME: |
| 60 | + # Remove the following `age.identityPaths` setting in a real deployment. |
| 61 | + # This copies a private key to the (publicly readable) Nix store, |
| 62 | + # which allows ./deploy.sh to start a age-based container in |
| 63 | + # a single deployment step. |
| 64 | + # |
| 65 | + # In a real deployment, just leave `age.identityPaths` undefined. |
| 66 | + # In this case, agenix uses the auto-generated SSH host key. |
| 67 | + age.identityPaths = [ ./host-key ]; |
| 68 | + }; |
| 69 | + }; |
| 70 | + |
| 71 | + nixosConfigurations.demoNode = nix-bitcoin.inputs.nixpkgs.lib.nixosSystem { |
| 72 | + system = "x86_64-linux"; |
| 73 | + modules = [ self.modules.demoNode ]; |
| 74 | + }; |
| 75 | + } |
| 76 | + // (nix-bitcoin.inputs.nixpkgs.lib.recursiveUpdate |
| 77 | + |
| 78 | + # Allow runnning this node as a container, used by ./deploy.sh |
| 79 | + (flake-utils.lib.eachSystem nix-bitcoin.lib.supportedSystems (system: { |
| 80 | + packages = { |
| 81 | + container = nix-bitcoin.inputs.extra-container.lib.buildContainers { |
| 82 | + inherit system; |
| 83 | + config.containers.nb-agenix = { |
| 84 | + privateNetwork = true; |
| 85 | + config.imports = [ self.modules.demoNode ]; |
| 86 | + }; |
| 87 | + # Set this when running on a NixOS container host with `system.stateVersion` <22.05 |
| 88 | + # legacyInstallDirs = true; |
| 89 | + }; |
| 90 | + }; |
| 91 | + })) |
| 92 | + |
| 93 | + # This allows generating age-encrypted secrets on systems |
| 94 | + # that differ from the target node. |
| 95 | + # E.g. manage a `x86_64-linux` node from macOS (`aarch64-darwin`) |
| 96 | + (flake-utils.lib.eachDefaultSystem (system: { |
| 97 | + packages = { |
| 98 | + generateAgeSecrets = let |
| 99 | + nodeSystem = nix-bitcoin.inputs.nixpkgs.lib.nixosSystem { |
| 100 | + inherit system; |
| 101 | + modules = [ self.modules.demoNode ]; |
| 102 | + }; |
| 103 | + in |
| 104 | + nodeSystem.config.nix-bitcoin.age.generateSecretsScript; |
| 105 | + }; |
| 106 | + })) |
| 107 | + ); |
| 108 | +} |
0 commit comments