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 68 <literal>db-config.sqlite</literal> which will be automatically recreated. 69 69 </para> 70 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> 71 81 </itemizedlist> 72 82 73 83
+12 -10
nixos/modules/services/network-filesystems/ipfs.nix
··· 9 9 10 10 ipfsFlags = ''${if cfg.autoMigrate then "--migrate" else ""} ${if cfg.enableGC then "--enable-gc" else ""} ${toString cfg.extraFlags}''; 11 11 12 - pathEnv = { IPFS_PATH = cfg.dataDir; }; 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"; 13 16 14 17 # Wrapping the ipfs binary with the environment variable IPFS_PATH set to dataDir because we can't set it in the user environment 15 18 wrapped = runCommand "ipfs" { buildInputs = [ makeWrapper ]; } '' ··· 42 45 43 46 dataDir = mkOption { 44 47 type = types.str; 45 - default = "/var/lib/ipfs"; 48 + default = defaultDataDir; 46 49 description = "The data dir for IPFS"; 47 50 }; 48 51 ··· 117 120 after = [ "local-fs.target" ]; 118 121 before = [ "ipfs.service" "ipfs-offline.service" ]; 119 122 123 + environment.IPFS_PATH = cfg.dataDir; 124 + 120 125 path = [ pkgs.ipfs pkgs.su pkgs.bash ]; 121 126 122 127 preStart = '' 123 128 install -m 0755 -o ${cfg.user} -g ${cfg.group} -d ${cfg.dataDir} 124 129 ''; 125 - 126 - environment = pathEnv; 127 - 128 130 script = '' 129 - if [[ ! -d ${cfg.dataDir}/.ipfs ]]; then 131 + if [[ ! -f ${cfg.dataDir}/config ]]; then 130 132 ${ipfs}/bin/ipfs init ${optionalString cfg.emptyRepo "-e"} 131 133 fi 132 134 ${ipfs}/bin/ipfs --local config Addresses.API ${cfg.apiAddress} ··· 151 153 conflicts = [ "ipfs-offline.service" ]; 152 154 wants = [ "ipfs-init.service" ]; 153 155 156 + environment.IPFS_PATH = cfg.dataDir; 157 + 154 158 path = [ pkgs.ipfs ]; 155 159 156 - environment = pathEnv; 157 - 158 160 serviceConfig = { 159 161 ExecStart = "${ipfs}/bin/ipfs daemon ${ipfsFlags}"; 160 162 User = cfg.user; ··· 172 174 conflicts = [ "ipfs.service" ]; 173 175 wants = [ "ipfs-init.service" ]; 174 176 175 - path = [ pkgs.ipfs ]; 177 + environment.IPFS_PATH = cfg.dataDir; 176 178 177 - environment = pathEnv; 179 + path = [ pkgs.ipfs ]; 178 180 179 181 serviceConfig = { 180 182 ExecStart = "${ipfs}/bin/ipfs daemon ${ipfsFlags} --offline";