Skip to content

ipfs service: dataDir backwards compatibility, fix dataDir existance detection #25782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 24, 2017

Conversation

infinisil
Copy link
Member

Motivation for this change

Because of #25531, older instances of IPFS directories weren't being detected (see #25759). Also the check for the existance was incorrect originally. This PR fixes both of these issues.

I tested this on the release-17.03 branch, since master currently doesn't build for me, the change is pretty trivial though.

Things done
  • Tested using sandboxing
    (nix.useSandbox on NixOS,
    or option build-use-sandbox in nix.conf
    on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • Linux
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

Sorry, something went wrong.

@mention-bot
Copy link

@infinisil, thanks for your PR! By analyzing the history of the files in this pull request, we identified @mguentner to be a potential reviewer.

script = ''
if [[ ! -d ${cfg.dataDir}/.ipfs ]]; then
if [[ ! -d ${cfg.dataDir}/config ]]; then
Copy link
Member Author

@infinisil infinisil May 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The standard IPFS implementation does the same (for now)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for checking that!

@infinisil
Copy link
Member Author

Pinging @mguentner

Copy link
Contributor

@mguentner mguentner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

# 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";

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

However, that means that users need to rename the IPFS directory (manually) when upgrading.
We could also put a [[ -d /var/lib/ipfs/.ipfs ]] && mv /var/lib/ipfs/.ipfs/* /var/lib/ipfs && rmdir /var/lib/ipfs/.ipfs in the
ipfs-init service.
But given that IPFS is not used that much currently in the Nix community (I presume), we should keep that out (this just creates technical debt).

Copy link
Member Author

@infinisil infinisil May 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mguentner Shouldn't stateVersion generally stay the same? If the user decides to change it they'll have to look through what breaks themselves, because I think NixOS doesn't need to provide any stability guarantees with stateful data beyond this option. Also it's just the default, if the user sets it explicitly later they'll have to move it themselves. I think that's really the intended way of using stateVersion, citing from the description of the option:

Every once in a while, a new NixOS release may change configuration defaults in a way incompatible with stateful data. [...] To prevent such breakage, you can set the value of this option to the NixOS release with which you want to be compatible. [...]

Copy link
Member Author

@infinisil infinisil May 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I know what you mean now, but the script should be more like

if [[ -d /var/lib/ipfs/.ipfs ]] then
  mv /var/lib/ipfs/.ipfs/* "${cfg.dataDir}"
  rmdir /var/lib/ipfs/.ipfs
fi

Don't know where we would put this though, maybe when cfg.enable == true?

I think such a script wouldn't be too bad, could be run once at build time. Even if there aren't many users, I think it would be a shame to have it break when upgrading.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I keep thinking about this and I just can't come up with a nice solution, maybe just put it in the release notes?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I forgot the cfg.dataDir again. You are perfectly right.

Let's put it in the release notes. I don't think that any reason justifies adding more unnecessary complexity. IPFS is alpha software, so the NixOS module should be alpha as well. KISS 💋

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Release notes would be located in ./nixos/doc/manual/release-notes/rl-1709.xml

script = ''
if [[ ! -d ${cfg.dataDir}/.ipfs ]]; then
if [[ ! -d ${cfg.dataDir}/config ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for checking that!

@infinisil
Copy link
Member Author

infinisil commented May 19, 2017

Added a release note for this change including the script to migrate, ready to merge.

Edit: No scratch that, I still found something wrong, gonna update

@@ -128,7 +128,7 @@ in
install -m 0755 -o ${cfg.user} -g ${cfg.group} -d ${cfg.dataDir}
'';
script = ''
if [[ ! -d ${cfg.dataDir}/config ]]; then
if [[ ! -f ${cfg.dataDir}/config ]]; then
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bash knowledge isn't great, so I didn't notice this before, config is a file, not a directory

Copy link
Member

@fpletz fpletz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fixes and the comments! LGTM 👍

The commits should be squashed, though. :)

@infinisil
Copy link
Member Author

@fpletz Did it, used squashing for the first time, it's not as bad as I thought it would be :D

@fpletz
Copy link
Member

fpletz commented May 24, 2017

Cool, thanks. I just finished some tests. Let's merge this.

@fpletz fpletz merged commit df8a7d9 into NixOS:master May 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants