Merge pull request #25531 from Infinisil/fix/ipfs-dataDir
ipfs service: Fix dataDir being ignored
This commit is contained in:
commit
7b211da119
1 changed files with 15 additions and 3 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue