diff options
author | Matthew Bauer <mjbauer95@gmail.com> | 2020-06-11 15:45:39 -0500 |
---|---|---|
committer | Matthew Bauer <mjbauer95@gmail.com> | 2020-06-12 17:15:27 -0500 |
commit | b36ef706fb8d10d3602179c1975eb62b1c3a9ac3 (patch) | |
tree | f25d0d9ff57fba2657cb1aac9cf558c6d98ba096 /nixos/modules/services/network-filesystems/ipfs.nix | |
parent | c5f40198f384697bc96faf3e29a1e69c29e2ca6c (diff) | |
download | nixpkgs-b36ef706fb8d10d3602179c1975eb62b1c3a9ac3.tar nixpkgs-b36ef706fb8d10d3602179c1975eb62b1c3a9ac3.tar.gz nixpkgs-b36ef706fb8d10d3602179c1975eb62b1c3a9ac3.tar.bz2 nixpkgs-b36ef706fb8d10d3602179c1975eb62b1c3a9ac3.tar.lz nixpkgs-b36ef706fb8d10d3602179c1975eb62b1c3a9ac3.tar.xz nixpkgs-b36ef706fb8d10d3602179c1975eb62b1c3a9ac3.tar.zst nixpkgs-b36ef706fb8d10d3602179c1975eb62b1c3a9ac3.zip |
nixos/ipfs: add startWhenNeeded option
This makes it possible to only start IPFS when needed. So a user’s IPFS daemon only starts when they actually use it. A few important warnings though: - This probably shouldn’t be mixed with services.ipfs.autoMount since you want /ipfs and /ipns aren’t activated like this - ipfs.socket assumes that you are using ports 5001 and 8080 for the API and gateway respectively. We could do some parsing to figure out what is in apiAddress and gatewayAddress, but that’s kind of difficult given the nonstandard address format. - Apparently? this doesn’t work with the --api commands used in the tests. Of course you can always start automatically with startWhenNeeded = false, or just running ‘systemctl start ipfs.service’. Tested with the following test (modified from tests/ipfs.nix): import ./make-test-python.nix ({ pkgs, ...} : { name = "ipfs"; nodes.machine = { ... }: { services.ipfs = { enable = true; startWhenNeeded = true; }; }; testScript = '' start_all() machine.wait_until_succeeds("ipfs id") ipfs_hash = machine.succeed("echo fnord | ipfs add | awk '{ print $2 }'") machine.succeed(f"ipfs cat /ipfs/{ipfs_hash.strip()} | grep fnord") ''; }) Fixes #90145 Update nixos/modules/services/network-filesystems/ipfs.nix Co-authored-by: Florian Klink <flokli@flokli.de>
Diffstat (limited to 'nixos/modules/services/network-filesystems/ipfs.nix')
-rw-r--r-- | nixos/modules/services/network-filesystems/ipfs.nix | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/nixos/modules/services/network-filesystems/ipfs.nix b/nixos/modules/services/network-filesystems/ipfs.nix index 9b8fe6d5f10..f7a61139992 100644 --- a/nixos/modules/services/network-filesystems/ipfs.nix +++ b/nixos/modules/services/network-filesystems/ipfs.nix @@ -136,6 +136,12 @@ in { example = 64*1024; }; + startWhenNeeded = mkOption { + type = types.bool; + default = false; + description = "Whether to use socket activation to start IPFS when needed."; + }; + }; }; @@ -192,6 +198,8 @@ in { fi ''; + wantedBy = [ "default.target" ]; + serviceConfig = { Type = "oneshot"; RemainAfterExit = true; @@ -207,8 +215,6 @@ in { wants = [ "ipfs-init.service" ]; after = [ "ipfs-init.service" ]; - wantedBy = [ "default.target" ]; - preStart = optionalString cfg.autoMount '' ipfs --local config Mounts.FuseAllowOther --json true ipfs --local config Mounts.IPFS ${cfg.ipfsMountDir} @@ -235,6 +241,18 @@ in { User = cfg.user; Group = cfg.group; } // optionalAttrs (cfg.serviceFdlimit != null) { LimitNOFILE = cfg.serviceFdlimit; }; + } // optionalAttrs (!cfg.startWhenNeeded) { + wantedBy = [ "default.target" ]; + }; + + # Note the upstream service assumes default host / port + # we should override it when a custom is provided above. + systemd.sockets.ipfs-gateway = mkIf cfg.startWhenNeeded { + wantedBy = [ "sockets.target" ]; + }; + + systemd.sockets.ipfs-api = mkIf cfg.startWhenNeeded { + wantedBy = [ "sockets.target" ]; }; }; |