From df8a7d956d491eab0321319511b8ae4e808ff9c8 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Wed, 24 May 2017 20:51:02 +0200 Subject: [PATCH] ipfs service: dataDir backwards compatibility (#25782) Fixes dataDir existance detection. Fixes #25759, #26069. --- nixos/doc/manual/release-notes/rl-1709.xml | 10 +++++++++ .../services/network-filesystems/ipfs.nix | 22 ++++++++++--------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/nixos/doc/manual/release-notes/rl-1709.xml b/nixos/doc/manual/release-notes/rl-1709.xml index 257664397599..d0f0216686a5 100644 --- a/nixos/doc/manual/release-notes/rl-1709.xml +++ b/nixos/doc/manual/release-notes/rl-1709.xml @@ -68,6 +68,16 @@ following incompatible changes: db-config.sqlite which will be automatically recreated. + + + The ipfs package now doesn't ignore the dataDir 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 + +dataDir=<valueOfDataDir> +mv /var/lib/ipfs/.ipfs/* $dataDir +rmdir /var/lib/ipfs/.ipfs + + + diff --git a/nixos/modules/services/network-filesystems/ipfs.nix b/nixos/modules/services/network-filesystems/ipfs.nix index bd46147c6bc6..10c1d751ac5d 100644 --- a/nixos/modules/services/network-filesystems/ipfs.nix +++ b/nixos/modules/services/network-filesystems/ipfs.nix @@ -9,7 +9,10 @@ let ipfsFlags = ''${if cfg.autoMigrate then "--migrate" else ""} ${if cfg.enableGC then "--enable-gc" else ""} ${toString cfg.extraFlags}''; - pathEnv = { IPFS_PATH = cfg.dataDir; }; + # Before Version 17.09, ipfs would always use "/var/lib/ipfs/.ipfs" as it's dataDir + defaultDataDir = if versionAtLeast config.system.stateVersion "17.09" then + "/var/lib/ipfs" else + "/var/lib/ipfs/.ipfs"; # 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 ]; } '' @@ -42,7 +45,7 @@ in dataDir = mkOption { type = types.str; - default = "/var/lib/ipfs"; + default = defaultDataDir; description = "The data dir for IPFS"; }; @@ -117,16 +120,15 @@ in after = [ "local-fs.target" ]; before = [ "ipfs.service" "ipfs-offline.service" ]; + environment.IPFS_PATH = cfg.dataDir; + path = [ pkgs.ipfs pkgs.su pkgs.bash ]; preStart = '' install -m 0755 -o ${cfg.user} -g ${cfg.group} -d ${cfg.dataDir} ''; - - environment = pathEnv; - script = '' - if [[ ! -d ${cfg.dataDir}/.ipfs ]]; then + if [[ ! -f ${cfg.dataDir}/config ]]; then ${ipfs}/bin/ipfs init ${optionalString cfg.emptyRepo "-e"} fi ${ipfs}/bin/ipfs --local config Addresses.API ${cfg.apiAddress} @@ -151,9 +153,9 @@ in conflicts = [ "ipfs-offline.service" ]; wants = [ "ipfs-init.service" ]; - path = [ pkgs.ipfs ]; + environment.IPFS_PATH = cfg.dataDir; - environment = pathEnv; + path = [ pkgs.ipfs ]; serviceConfig = { ExecStart = "${ipfs}/bin/ipfs daemon ${ipfsFlags}"; @@ -172,9 +174,9 @@ in conflicts = [ "ipfs.service" ]; wants = [ "ipfs-init.service" ]; - path = [ pkgs.ipfs ]; + environment.IPFS_PATH = cfg.dataDir; - environment = pathEnv; + path = [ pkgs.ipfs ]; serviceConfig = { ExecStart = "${ipfs}/bin/ipfs daemon ${ipfsFlags} --offline";