From 91ee3530a721b51fff72ddedea41172aab08b151 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Fri, 5 May 2017 11:23:46 +0200 Subject: [PATCH] ipfs service: Fix dataDir being ignored IPFS uses the environment variable IPFS_PATH to determine where to look for it's data, which wasn't set previously therefore ignoring the dataDir attribute --- .../services/network-filesystems/ipfs.nix | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/nixos/modules/services/network-filesystems/ipfs.nix b/nixos/modules/services/network-filesystems/ipfs.nix index e6e04248854e..bd46147c6bc6 100644 --- a/nixos/modules/services/network-filesystems/ipfs.nix +++ b/nixos/modules/services/network-filesystems/ipfs.nix @@ -3,12 +3,19 @@ with lib; let - inherit (pkgs) ipfs; + inherit (pkgs) ipfs runCommand makeWrapper; cfg = config.services.ipfs; ipfsFlags = ''${if cfg.autoMigrate then "--migrate" else ""} ${if cfg.enableGC then "--enable-gc" else ""} ${toString cfg.extraFlags}''; + pathEnv = { IPFS_PATH = cfg.dataDir; }; + + # Wrapping the ipfs binary with the environment variable IPFS_PATH set to dataDir because we can't set it in the user environment + wrapped = runCommand "ipfs" { buildInputs = [ makeWrapper ]; } '' + mkdir -p "$out/bin" + makeWrapper "${ipfs}/bin/ipfs" "$out/bin/ipfs" --set IPFS_PATH ${cfg.dataDir} + ''; in { @@ -86,7 +93,7 @@ in ###### implementation config = mkIf cfg.enable { - environment.systemPackages = [ pkgs.ipfs ]; + environment.systemPackages = [ wrapped ]; users.extraUsers = mkIf (cfg.user == "ipfs") { ipfs = { @@ -116,9 +123,10 @@ in install -m 0755 -o ${cfg.user} -g ${cfg.group} -d ${cfg.dataDir} ''; + environment = pathEnv; + script = '' if [[ ! -d ${cfg.dataDir}/.ipfs ]]; then - cd ${cfg.dataDir} ${ipfs}/bin/ipfs init ${optionalString cfg.emptyRepo "-e"} fi ${ipfs}/bin/ipfs --local config Addresses.API ${cfg.apiAddress} @@ -145,6 +153,8 @@ in path = [ pkgs.ipfs ]; + environment = pathEnv; + serviceConfig = { ExecStart = "${ipfs}/bin/ipfs daemon ${ipfsFlags}"; User = cfg.user; @@ -164,6 +174,8 @@ in path = [ pkgs.ipfs ]; + environment = pathEnv; + serviceConfig = { ExecStart = "${ipfs}/bin/ipfs daemon ${ipfsFlags} --offline"; User = cfg.user;