Skip to content
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

syncthing: Add discovery/relay servers, improve build #34831

Merged
merged 9 commits into from Feb 15, 2018

Conversation

andrew-d
Copy link
Contributor

@andrew-d andrew-d commented Feb 11, 2018

Motivation for this change

I wanted to be able to run the Syncthing discovery / relay servers on my own infrastructure. In the process, I also fixed the silly $GOPATH check that the Syncthing build does (see here), and included man pages in the package.

cc @pshendry @jokogr @peterhoeg (existing maintainers of this package)

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
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • 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.

@peterhoeg
Copy link
Member

I'm not sure if the use of multiple outputs to do this is the right way. The "proper" way IMHO would be to create separate derivations (and an additional "cli" derivation for the stcli tool).

@andrew-d
Copy link
Contributor Author

Sure, happy to switch to separate derivations if you'd prefer - mind pointing me to an example of what this would look like (e.g. a package that does this)?

@andrew-d
Copy link
Contributor Author

(I was also considering just not bothering splitting things up and building everything in the main package, since the build is only a couple seconds slower here - thoughts on that approach?)

@peterhoeg
Copy link
Member

peterhoeg commented Feb 12, 2018

mind pointing me to an example of what this would look like (e.g. a package that does this)?

Here is one where a shared source is used by multiple derivations: #34611

building everything in the main package

From my point of view - "it depends". The go binaries are pretty big so the nice thing to do is to split it up and people can pull in just what they need.

@andrew-d
Copy link
Contributor Author

@peterhoeg - Apologies for the wait on this one, but I just pushed a commit that splits up things into a common core, and different packages for syncthing-relay and syncthing-discovery. Thoughts on this approach?

@peterhoeg
Copy link
Member

Nothing to apologize for - we all get busy with other things.

It makes sense to split them up if they are likely to be used independently.

As for the approach using common.nix - there is technically nothing wrong with it, it just isn't how most of the other packages are done. Have a look at https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/compilers/cudatoolkit/default.nix as an example of using a function.

@andrew-d
Copy link
Contributor Author

Ah, that's helpful to see - thanks! Just pushed another commit that uses a common function in a single file. The diff without whitespace might be helpful.

};
stdenv.mkDerivation rec {
version = "0.14.44";
name = "${args.name}-${version}";
Copy link
Member

Choose a reason for hiding this comment

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

You can just use name instead of args.name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't able to do this, since I got an infinite recursion error (presumably with the value of the name attribute itself); instead, I renamed the parameter.

sha256 = "1gdkx6lbzmdz2hqc9slbq41rwgkxmdisnj0iywx4mppmc2b4v6wh";
};

buildInputs = [ go removeReferencesTo ];
Copy link
Member

Choose a reason for hiding this comment

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

removeReferencesTo should be in nativeBuildInputs.

env GOPATH= go run build.go -no-upgrade -version v${version} build ${target}
'';

inherit (args) installPhase;
Copy link
Member

Choose a reason for hiding this comment

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

You're passing in installPhase so you can do inherit installPhase.

homepage = https://www.syncthing.net/;
description = "Open Source Continuous File Synchronization";
license = licenses.mpl20;
maintainers = with maintainers; [ pshendry joko peterhoeg ];
Copy link
Member

Choose a reason for hiding this comment

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

You don't want to add yourself?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't sure what the etiquette here is - if you're okay with it, I've added myself.

Copy link
Member

Choose a reason for hiding this comment

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

Absolutely! We need all the maintainers we can get.


installPhase = ''
mkdir -p $out/lib/systemd/{system,user}
Copy link
Member

Choose a reason for hiding this comment

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

This should move into the linux specific section below.

find $out/bin -type f -exec remove-references-to -t ${go} '{}' '+'
'';
installPhase = ''
mkdir -p $out/lib/systemd/system $out/bin
Copy link
Member

Choose a reason for hiding this comment

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

This should also move down.

inherit (callPackages ../applications/networking/syncthing { })
syncthing
syncthing-discovery
syncthing-relay;
Copy link
Member

Choose a reason for hiding this comment

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

Please also create syncthing-cli with stcli inside.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! It needed a small patch since it wasn't a build target by default.

name = "syncthing-${version}";
let
common =
args@{ name, target, installPhase }:
Copy link
Member

Choose a reason for hiding this comment

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

  1. You don't need args@
  2. Please join the 2 lines to become:
common = { name, target, installPhase }:

@andrew-d
Copy link
Contributor Author

@peterhoeg - Okay, I believe that I've addressed all of your feedback - let me know if I missed anything. During the process, I also noticed a bit of an impurity in the build - the build script sets linker flags based on the current username and host name, so I've added a commit to override those to both be nix.

Copy link
Member

@peterhoeg peterhoeg left a comment

Choose a reason for hiding this comment

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

We've officially gone into nitpick territory now - thanks for your patience!

ln -s $(pwd) src/github.com/syncthing/syncthing
export GOPATH=$(pwd)
installPhase = ''
mkdir -p $out/bin
Copy link
Member

Choose a reason for hiding this comment

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

You don't need mkdir here. install -D will take care of it.

target = "stcli";

installPhase = ''
mkdir -p $out/bin
Copy link
Member

Choose a reason for hiding this comment

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

Or here

target = "stdiscosrv";

installPhase = ''
mkdir -p $out/bin
Copy link
Member

Choose a reason for hiding this comment

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

Or here

find $out/bin -type f -exec remove-references-to -t ${go} '{}' '+'
'';
installPhase = ''
mkdir -p $out/bin
Copy link
Member

Choose a reason for hiding this comment

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

Or here

version = "0.14.44";
name = "syncthing-${version}";
let
common = { stname, target, installPhase, patches ? null}:
Copy link
Member

Choose a reason for hiding this comment

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

patches is a list so it should be [] instead of null.

@andrew-d
Copy link
Contributor Author

@peterhoeg - Changes made! 😀

@peterhoeg
Copy link
Member

current username and host name, so I've added a commit to override those to both be nix.

Nicely spotted!

I had a look at everything in its entirety and noticed that for every derivation, you essentially call what is:

install -Dm755 ${target} $out/bin/${target}

So that can be standardized in the common function and the 2 derivations that do more can instead pass in a postInstall for the other bits. That would rip out a few lines and reduce duplication.

@andrew-d
Copy link
Contributor Author

Ah, yeah, that's a good idea - just pushed a commit that does that 👍

@peterhoeg peterhoeg merged commit 394a881 into NixOS:master Feb 15, 2018
@andrew-d andrew-d deleted the adunham/syncthing branch February 15, 2018 08:21
@andrew-d
Copy link
Contributor Author

Awesome! Thank you very much for the reviews 😀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants