@ -3,12 +3,19 @@
with lib ;
let
inherit ( pkgs ) ipfs ;
inherit ( pkgs ) ipfs runCommand makeWrapper ;
cfg = config . services . ipfs ;
ipfsFlags = '' ${ if cfg . autoMigrate then " - - m i g r a t e " else " " } ${ if cfg . enableGC then " - - e n a b l e - g c " 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 " i p f s " { buildInputs = [ makeWrapper ] ; } ''
mkdir - p " $ o u t / b i n "
makeWrapper " ${ ipfs } / b i n / i p f s " " $ o u t / b i n / i p f s " - - 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 == " i p f s " ) {
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 } / b i n / i p f s d a e m o n ${ ipfsFlags } " ;
User = cfg . user ;
@ -164,6 +174,8 @@ in
path = [ pkgs . ipfs ] ;
environment = pathEnv ;
serviceConfig = {
ExecStart = " ${ ipfs } / b i n / i p f s d a e m o n ${ ipfsFlags } - - o f f l i n e " ;
User = cfg . user ;