From a255c43f4437c695b8406f03678b331bda6151e9 Mon Sep 17 00:00:00 2001 From: Luflosi Date: Tue, 4 Oct 2022 12:44:48 +0200 Subject: [PATCH] nixos/kubo: convert to RFC42-style settings --- .../from_md/release-notes/rl-2211.section.xml | 11 +++ .../manual/release-notes/rl-2211.section.md | 2 + .../services/network-filesystems/kubo.nix | 98 ++++++++++--------- nixos/tests/kubo.nix | 4 +- 4 files changed, 66 insertions(+), 49 deletions(-) diff --git a/nixos/doc/manual/from_md/release-notes/rl-2211.section.xml b/nixos/doc/manual/from_md/release-notes/rl-2211.section.xml index f0cd6e933293..c49012e8b925 100644 --- a/nixos/doc/manual/from_md/release-notes/rl-2211.section.xml +++ b/nixos/doc/manual/from_md/release-notes/rl-2211.section.xml @@ -561,6 +561,17 @@ this version for the entire lifecycle of the 22.11 release. + + + The ipfs package and module were renamed to kubo. The kubo + module now uses an RFC42-style settings + option instead of extraConfig and the + gatewayAddress, + apiAddress and + swarmAddress options were renamed. Using + the old names will print a warning but still work. + + pkgs.cosign does not provide the diff --git a/nixos/doc/manual/release-notes/rl-2211.section.md b/nixos/doc/manual/release-notes/rl-2211.section.md index 93faf15f9d1f..92ba0414ab5c 100644 --- a/nixos/doc/manual/release-notes/rl-2211.section.md +++ b/nixos/doc/manual/release-notes/rl-2211.section.md @@ -192,6 +192,8 @@ Available as [services.patroni](options.html#opt-services.patroni.enable). - PHP 7.4 is no longer supported due to upstream not supporting this version for the entire lifecycle of the 22.11 release. +- The ipfs package and module were renamed to kubo. The kubo module now uses an RFC42-style `settings` option instead of `extraConfig` and the `gatewayAddress`, `apiAddress` and `swarmAddress` options were renamed. Using the old names will print a warning but still work. + - `pkgs.cosign` does not provide the `cosigned` binary anymore. The `sget` binary has been moved into its own package. - Emacs now uses the Lucid toolkit by default instead of GTK because of stability and compatibility issues. diff --git a/nixos/modules/services/network-filesystems/kubo.nix b/nixos/modules/services/network-filesystems/kubo.nix index 9942e4e41ad6..51e1282db418 100644 --- a/nixos/modules/services/network-filesystems/kubo.nix +++ b/nixos/modules/services/network-filesystems/kubo.nix @@ -3,6 +3,8 @@ with lib; let cfg = config.services.kubo; + settingsFormat = pkgs.formats.json {}; + kuboFlags = utils.escapeSystemdExecArgs ( optional cfg.autoMount "--mount" ++ optional cfg.enableGC "--enable-gc" ++ @@ -117,29 +119,6 @@ in description = lib.mdDoc "Where to mount the IPNS namespace to"; }; - gatewayAddress = mkOption { - type = types.str; - default = "/ip4/127.0.0.1/tcp/8080"; - description = lib.mdDoc "Where the IPFS Gateway can be reached"; - }; - - apiAddress = mkOption { - type = types.str; - default = "/ip4/127.0.0.1/tcp/5001"; - description = lib.mdDoc "Where Kubo exposes its API to"; - }; - - swarmAddress = mkOption { - type = types.listOf types.str; - default = [ - "/ip4/0.0.0.0/tcp/4001" - "/ip6/::/tcp/4001" - "/ip4/0.0.0.0/udp/4001/quic" - "/ip6/::/udp/4001/quic" - ]; - description = lib.mdDoc "Where Kubo listens for incoming p2p connections"; - }; - enableGC = mkOption { type = types.bool; default = false; @@ -152,11 +131,38 @@ in description = lib.mdDoc "If set to true, the repo won't be initialized with help files"; }; - extraConfig = mkOption { - type = types.attrs; + settings = mkOption { + type = lib.types.submodule { + freeformType = settingsFormat.type; + + options = { + Addresses.API = mkOption { + type = types.str; + default = "/ip4/127.0.0.1/tcp/5001"; + description = lib.mdDoc "Where Kubo exposes its API to"; + }; + + Addresses.Gateway = mkOption { + type = types.str; + default = "/ip4/127.0.0.1/tcp/8080"; + description = lib.mdDoc "Where the IPFS Gateway can be reached"; + }; + + Addresses.Swarm = mkOption { + type = types.listOf types.str; + default = [ + "/ip4/0.0.0.0/tcp/4001" + "/ip6/::/tcp/4001" + "/ip4/0.0.0.0/udp/4001/quic" + "/ip6/::/udp/4001/quic" + ]; + description = lib.mdDoc "Where Kubo listens for incoming p2p connections"; + }; + }; + }; description = lib.mdDoc '' Attrset of daemon configuration to set using {command}`ipfs config`, every time the daemon starts. - These are applied last, so may override configuration set by other options in this module. + See [https://github.com/ipfs/kubo/blob/master/docs/config.md](https://github.com/ipfs/kubo/blob/master/docs/config.md) for reference. Keep in mind that this configuration is stateful; i.e., unsetting anything in here does not reset the value to the default! ''; default = { }; @@ -244,6 +250,12 @@ in then [ cfg.package.systemd_unit ] else [ cfg.package.systemd_unit_hardened ]; + services.kubo.settings = mkIf cfg.autoMount { + Mounts.FuseAllowOther = lib.mkDefault true; + Mounts.IPFS = lib.mkDefault cfg.ipfsMountDir; + Mounts.IPNS = lib.mkDefault cfg.ipnsMountDir; + }; + systemd.services.ipfs = { path = [ "/run/wrappers" cfg.package ]; environment.IPFS_PATH = cfg.dataDir; @@ -259,22 +271,10 @@ in '' + '' ipfs --offline config profile apply ${profile} >/dev/null fi - '' + optionalString cfg.autoMount '' - ipfs --offline config Mounts.FuseAllowOther --json true - ipfs --offline config Mounts.IPFS ${cfg.ipfsMountDir} - ipfs --offline config Mounts.IPNS ${cfg.ipnsMountDir} '' + '' ipfs --offline config show \ - | ${pkgs.jq}/bin/jq '. * $extraConfig' --argjson extraConfig ${ - escapeShellArg (builtins.toJSON ( - recursiveUpdate - { - Addresses.API = cfg.apiAddress; - Addresses.Gateway = cfg.gatewayAddress; - Addresses.Swarm = cfg.swarmAddress; - } - cfg.extraConfig - )) + | ${pkgs.jq}/bin/jq '. * $settings' --argjson settings ${ + escapeShellArg (builtins.toJSON cfg.settings) } \ | ipfs --offline config replace - ''; @@ -294,12 +294,12 @@ in socketConfig = { ListenStream = let - fromCfg = multiaddrToListenStream cfg.gatewayAddress; + fromCfg = multiaddrToListenStream cfg.settings.Addresses.Gateway; in [ "" ] ++ lib.optional (fromCfg != null) fromCfg; ListenDatagram = let - fromCfg = multiaddrToListenDatagram cfg.gatewayAddress; + fromCfg = multiaddrToListenDatagram cfg.settings.Addresses.Gateway; in [ "" ] ++ lib.optional (fromCfg != null) fromCfg; }; @@ -311,7 +311,7 @@ in # in the multiaddr. socketConfig.ListenStream = let - fromCfg = multiaddrToListenStream cfg.apiAddress; + fromCfg = multiaddrToListenStream cfg.settings.Addresses.API; in [ "" "%t/ipfs.sock" ] ++ lib.optional (fromCfg != null) fromCfg; }; @@ -332,15 +332,19 @@ in (mkRenamedOptionModule [ "services" "ipfs" "autoMigrate" ] [ "services" "kubo" "autoMigrate" ]) (mkRenamedOptionModule [ "services" "ipfs" "ipfsMountDir" ] [ "services" "kubo" "ipfsMountDir" ]) (mkRenamedOptionModule [ "services" "ipfs" "ipnsMountDir" ] [ "services" "kubo" "ipnsMountDir" ]) - (mkRenamedOptionModule [ "services" "ipfs" "gatewayAddress" ] [ "services" "kubo" "gatewayAddress" ]) - (mkRenamedOptionModule [ "services" "ipfs" "apiAddress" ] [ "services" "kubo" "apiAddress" ]) - (mkRenamedOptionModule [ "services" "ipfs" "swarmAddress" ] [ "services" "kubo" "swarmAddress" ]) + (mkRenamedOptionModule [ "services" "ipfs" "gatewayAddress" ] [ "services" "kubo" "settings" "Addresses" "Gateway" ]) + (mkRenamedOptionModule [ "services" "ipfs" "apiAddress" ] [ "services" "kubo" "settings" "Addresses" "API" ]) + (mkRenamedOptionModule [ "services" "ipfs" "swarmAddress" ] [ "services" "kubo" "settings" "Addresses" "Swarm" ]) (mkRenamedOptionModule [ "services" "ipfs" "enableGC" ] [ "services" "kubo" "enableGC" ]) (mkRenamedOptionModule [ "services" "ipfs" "emptyRepo" ] [ "services" "kubo" "emptyRepo" ]) - (mkRenamedOptionModule [ "services" "ipfs" "extraConfig" ] [ "services" "kubo" "extraConfig" ]) + (mkRenamedOptionModule [ "services" "ipfs" "extraConfig" ] [ "services" "kubo" "settings" ]) (mkRenamedOptionModule [ "services" "ipfs" "extraFlags" ] [ "services" "kubo" "extraFlags" ]) (mkRenamedOptionModule [ "services" "ipfs" "localDiscovery" ] [ "services" "kubo" "localDiscovery" ]) (mkRenamedOptionModule [ "services" "ipfs" "serviceFdlimit" ] [ "services" "kubo" "serviceFdlimit" ]) (mkRenamedOptionModule [ "services" "ipfs" "startWhenNeeded" ] [ "services" "kubo" "startWhenNeeded" ]) + (mkRenamedOptionModule [ "services" "kubo" "extraConfig" ] [ "services" "kubo" "settings" ]) + (mkRenamedOptionModule [ "services" "kubo" "gatewayAddress" ] [ "services" "kubo" "settings" "Addresses" "Gateway" ]) + (mkRenamedOptionModule [ "services" "kubo" "apiAddress" ] [ "services" "kubo" "settings" "Addresses" "API" ]) + (mkRenamedOptionModule [ "services" "kubo" "swarmAddress" ] [ "services" "kubo" "settings" "Addresses" "Swarm" ]) ]; } diff --git a/nixos/tests/kubo.nix b/nixos/tests/kubo.nix index e84a873a1a18..94aa24a9204f 100644 --- a/nixos/tests/kubo.nix +++ b/nixos/tests/kubo.nix @@ -9,7 +9,7 @@ import ./make-test-python.nix ({ pkgs, ...} : { enable = true; # Also will add a unix domain socket socket API address, see module. startWhenNeeded = true; - apiAddress = "/ip4/127.0.0.1/tcp/2324"; + settings.Addresses.API = "/ip4/127.0.0.1/tcp/2324"; dataDir = "/mnt/ipfs"; }; }; @@ -17,7 +17,7 @@ import ./make-test-python.nix ({ pkgs, ...} : { nodes.fuse = { ... }: { services.kubo = { enable = true; - apiAddress = "/ip4/127.0.0.1/tcp/2324"; + settings.Addresses.API = "/ip4/127.0.0.1/tcp/2324"; autoMount = true; }; };