ipfs service: dataDir backwards compatibility (#25782)

Fixes dataDir existance detection. Fixes #25759, #26069.

authored by Silvan Mosberger and committed by Franz Pletz df8a7d95 179c504a

+22 -10
+10
nixos/doc/manual/release-notes/rl-1709.xml
··· 68 <literal>db-config.sqlite</literal> which will be automatically recreated. 69 </para> 70 </listitem> 71 </itemizedlist> 72 73
··· 68 <literal>db-config.sqlite</literal> which will be automatically recreated. 69 </para> 70 </listitem> 71 + <listitem> 72 + <para> 73 + The ipfs package now doesn't ignore the <literal>dataDir</literal> option anymore. If you've ever set this option to anything other than the default you'll have to either unset it (so the default gets used) or migrate the old data manually with 74 + <programlisting> 75 + dataDir=&lt;valueOfDataDir&gt; 76 + mv /var/lib/ipfs/.ipfs/* $dataDir 77 + rmdir /var/lib/ipfs/.ipfs 78 + </programlisting> 79 + </para> 80 + </listitem> 81 </itemizedlist> 82 83
+12 -10
nixos/modules/services/network-filesystems/ipfs.nix
··· 9 10 ipfsFlags = ''${if cfg.autoMigrate then "--migrate" else ""} ${if cfg.enableGC then "--enable-gc" else ""} ${toString cfg.extraFlags}''; 11 12 - pathEnv = { IPFS_PATH = cfg.dataDir; }; 13 14 # Wrapping the ipfs binary with the environment variable IPFS_PATH set to dataDir because we can't set it in the user environment 15 wrapped = runCommand "ipfs" { buildInputs = [ makeWrapper ]; } '' ··· 42 43 dataDir = mkOption { 44 type = types.str; 45 - default = "/var/lib/ipfs"; 46 description = "The data dir for IPFS"; 47 }; 48 ··· 117 after = [ "local-fs.target" ]; 118 before = [ "ipfs.service" "ipfs-offline.service" ]; 119 120 path = [ pkgs.ipfs pkgs.su pkgs.bash ]; 121 122 preStart = '' 123 install -m 0755 -o ${cfg.user} -g ${cfg.group} -d ${cfg.dataDir} 124 ''; 125 - 126 - environment = pathEnv; 127 - 128 script = '' 129 - if [[ ! -d ${cfg.dataDir}/.ipfs ]]; then 130 ${ipfs}/bin/ipfs init ${optionalString cfg.emptyRepo "-e"} 131 fi 132 ${ipfs}/bin/ipfs --local config Addresses.API ${cfg.apiAddress} ··· 151 conflicts = [ "ipfs-offline.service" ]; 152 wants = [ "ipfs-init.service" ]; 153 154 path = [ pkgs.ipfs ]; 155 156 - environment = pathEnv; 157 - 158 serviceConfig = { 159 ExecStart = "${ipfs}/bin/ipfs daemon ${ipfsFlags}"; 160 User = cfg.user; ··· 172 conflicts = [ "ipfs.service" ]; 173 wants = [ "ipfs-init.service" ]; 174 175 - path = [ pkgs.ipfs ]; 176 177 - environment = pathEnv; 178 179 serviceConfig = { 180 ExecStart = "${ipfs}/bin/ipfs daemon ${ipfsFlags} --offline";
··· 9 10 ipfsFlags = ''${if cfg.autoMigrate then "--migrate" else ""} ${if cfg.enableGC then "--enable-gc" else ""} ${toString cfg.extraFlags}''; 11 12 + # Before Version 17.09, ipfs would always use "/var/lib/ipfs/.ipfs" as it's dataDir 13 + defaultDataDir = if versionAtLeast config.system.stateVersion "17.09" then 14 + "/var/lib/ipfs" else 15 + "/var/lib/ipfs/.ipfs"; 16 17 # Wrapping the ipfs binary with the environment variable IPFS_PATH set to dataDir because we can't set it in the user environment 18 wrapped = runCommand "ipfs" { buildInputs = [ makeWrapper ]; } '' ··· 45 46 dataDir = mkOption { 47 type = types.str; 48 + default = defaultDataDir; 49 description = "The data dir for IPFS"; 50 }; 51 ··· 120 after = [ "local-fs.target" ]; 121 before = [ "ipfs.service" "ipfs-offline.service" ]; 122 123 + environment.IPFS_PATH = cfg.dataDir; 124 + 125 path = [ pkgs.ipfs pkgs.su pkgs.bash ]; 126 127 preStart = '' 128 install -m 0755 -o ${cfg.user} -g ${cfg.group} -d ${cfg.dataDir} 129 ''; 130 script = '' 131 + if [[ ! -f ${cfg.dataDir}/config ]]; then 132 ${ipfs}/bin/ipfs init ${optionalString cfg.emptyRepo "-e"} 133 fi 134 ${ipfs}/bin/ipfs --local config Addresses.API ${cfg.apiAddress} ··· 153 conflicts = [ "ipfs-offline.service" ]; 154 wants = [ "ipfs-init.service" ]; 155 156 + environment.IPFS_PATH = cfg.dataDir; 157 + 158 path = [ pkgs.ipfs ]; 159 160 serviceConfig = { 161 ExecStart = "${ipfs}/bin/ipfs daemon ${ipfsFlags}"; 162 User = cfg.user; ··· 174 conflicts = [ "ipfs.service" ]; 175 wants = [ "ipfs-init.service" ]; 176 177 + environment.IPFS_PATH = cfg.dataDir; 178 179 + path = [ pkgs.ipfs ]; 180 181 serviceConfig = { 182 ExecStart = "${ipfs}/bin/ipfs daemon ${ipfsFlags} --offline";