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
This commit is contained in:
parent
8b6ea100ce
commit
91ee3530a7
@ -3,12 +3,19 @@
|
|||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
inherit (pkgs) ipfs;
|
inherit (pkgs) ipfs runCommand makeWrapper;
|
||||||
|
|
||||||
cfg = config.services.ipfs;
|
cfg = config.services.ipfs;
|
||||||
|
|
||||||
ipfsFlags = ''${if cfg.autoMigrate then "--migrate" else ""} ${if cfg.enableGC then "--enable-gc" else ""} ${toString cfg.extraFlags}'';
|
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
|
in
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -86,7 +93,7 @@ in
|
|||||||
###### implementation
|
###### implementation
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
environment.systemPackages = [ pkgs.ipfs ];
|
environment.systemPackages = [ wrapped ];
|
||||||
|
|
||||||
users.extraUsers = mkIf (cfg.user == "ipfs") {
|
users.extraUsers = mkIf (cfg.user == "ipfs") {
|
||||||
ipfs = {
|
ipfs = {
|
||||||
@ -116,9 +123,10 @@ in
|
|||||||
install -m 0755 -o ${cfg.user} -g ${cfg.group} -d ${cfg.dataDir}
|
install -m 0755 -o ${cfg.user} -g ${cfg.group} -d ${cfg.dataDir}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
environment = pathEnv;
|
||||||
|
|
||||||
script = ''
|
script = ''
|
||||||
if [[ ! -d ${cfg.dataDir}/.ipfs ]]; then
|
if [[ ! -d ${cfg.dataDir}/.ipfs ]]; then
|
||||||
cd ${cfg.dataDir}
|
|
||||||
${ipfs}/bin/ipfs init ${optionalString cfg.emptyRepo "-e"}
|
${ipfs}/bin/ipfs init ${optionalString cfg.emptyRepo "-e"}
|
||||||
fi
|
fi
|
||||||
${ipfs}/bin/ipfs --local config Addresses.API ${cfg.apiAddress}
|
${ipfs}/bin/ipfs --local config Addresses.API ${cfg.apiAddress}
|
||||||
@ -145,6 +153,8 @@ in
|
|||||||
|
|
||||||
path = [ pkgs.ipfs ];
|
path = [ pkgs.ipfs ];
|
||||||
|
|
||||||
|
environment = pathEnv;
|
||||||
|
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
ExecStart = "${ipfs}/bin/ipfs daemon ${ipfsFlags}";
|
ExecStart = "${ipfs}/bin/ipfs daemon ${ipfsFlags}";
|
||||||
User = cfg.user;
|
User = cfg.user;
|
||||||
@ -164,6 +174,8 @@ in
|
|||||||
|
|
||||||
path = [ pkgs.ipfs ];
|
path = [ pkgs.ipfs ];
|
||||||
|
|
||||||
|
environment = pathEnv;
|
||||||
|
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
ExecStart = "${ipfs}/bin/ipfs daemon ${ipfsFlags} --offline";
|
ExecStart = "${ipfs}/bin/ipfs daemon ${ipfsFlags} --offline";
|
||||||
User = cfg.user;
|
User = cfg.user;
|
||||||
|
Loading…
Reference in New Issue
Block a user