From 7df1ce5088f3404b985aac4bb1814f98463a43a0 Mon Sep 17 00:00:00 2001 From: Matej Cotman Date: Thu, 3 Apr 2014 18:54:10 +0200 Subject: [PATCH] syncthing: new package and nixos module --- nixos/modules/module-list.nix | 1 + .../modules/services/networking/syncthing.nix | 73 +++++++++++++++++++ .../networking/syncthing/default.nix | 51 +++++++++++++ pkgs/top-level/all-packages.nix | 2 + 4 files changed, 127 insertions(+) create mode 100644 nixos/modules/services/networking/syncthing.nix create mode 100644 pkgs/applications/networking/syncthing/default.nix diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 652a99e7c5a6..5d8461bb8856 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -198,6 +198,7 @@ ./services/networking/sabnzbd.nix ./services/networking/searx.nix ./services/networking/supybot.nix + ./services/networking/syncthing.nix ./services/networking/ssh/lshd.nix ./services/networking/ssh/sshd.nix ./services/networking/tftpd.nix diff --git a/nixos/modules/services/networking/syncthing.nix b/nixos/modules/services/networking/syncthing.nix new file mode 100644 index 000000000000..345693fec767 --- /dev/null +++ b/nixos/modules/services/networking/syncthing.nix @@ -0,0 +1,73 @@ +{ config, pkgs, ... }: + +with pkgs.lib; + +let + + cfg = config.services.syncthing; + +in + +{ + + ###### interface + + options = { + + services.syncthing = { + + enable = mkOption { + default = false; + description = '' + Whether to enable the Syncthing, self-hosted open-source alternative + to Dropbox and BittorrentSync. Initial interface will be + available on http://127.0.0.1:8080/. + ''; + }; + + user = mkOption { + default = "syncthing"; + description = '' + Syncthing will be run under this user (user must exist, + this can be your user name). + ''; + }; + + dataDir = mkOption { + default = "/var/lib/syncthing"; + description = '' + Path where the `.syncthing` (settings and keys) and `Sync` + (your synced files) directories will exist. This can be your home + directory. + ''; + }; + + }; + + }; + + + ###### implementation + + config = mkIf config.services.syncthing.enable { + + systemd.services.syncthing = + { + description = "Syncthing service"; + after = [ "network.target" ]; + wantedBy = [ "multi-user.target" ]; + environment.STNORESTART = "placeholder"; # do not self-restart + environment.HOME = "${config.services.syncthing.dataDir}"; + serviceConfig = { + User = "${config.services.syncthing.user}"; + ExecStart = "${pkgs.syncthing}/bin/syncthing -home=${config.services.syncthing.dataDir}/.syncthing"; + Restart = "always"; + }; + + }; + + environment.systemPackages = [ pkgs.syncthing ]; + + }; + +} diff --git a/pkgs/applications/networking/syncthing/default.nix b/pkgs/applications/networking/syncthing/default.nix new file mode 100644 index 000000000000..50bc61eeeff0 --- /dev/null +++ b/pkgs/applications/networking/syncthing/default.nix @@ -0,0 +1,51 @@ +{ stdenv, fetchurl, fetchgit, go }: + +stdenv.mkDerivation rec { + name = "syncthing-${version}"; + version = "0.7.1"; + + src = fetchgit { + url = "git://github.com/calmh/syncthing.git"; + rev = "refs/tags/v${version}"; + sha256 = "1rja837kimiq15km8cridbm5yxvkm6mkvkwywdi76qf9rm0pcjl1"; + }; + + buildInputs = [ go ]; + + buildPhase = '' + mkdir -p "./dependencies/src/github.com/calmh/syncthing" + + cp -r "./auto" "./dependencies/src/github.com/calmh/syncthing" + cp -r "./buffers" "./dependencies/src/github.com/calmh/syncthing" + cp -r "./cid" "./dependencies/src/github.com/calmh/syncthing" + cp -r "./discover" "./dependencies/src/github.com/calmh/syncthing" + cp -r "./files" "./dependencies/src/github.com/calmh/syncthing" + cp -r "./lamport" "./dependencies/src/github.com/calmh/syncthing" + cp -r "./protocol" "./dependencies/src/github.com/calmh/syncthing" + cp -r "./scanner" "./dependencies/src/github.com/calmh/syncthing" + cp -r "./mc" "./dependencies/src/github.com/calmh/syncthing" + cp -r "./xdr" "./dependencies/src/github.com/calmh/syncthing" + + export GOPATH="`pwd`/Godeps/_workspace:`pwd`/dependencies" + + go test -cpu=1,2,4 ./... + + mkdir ./bin + + go build -o ./bin/syncthing -ldflags "-w -X main.Version v${version}" ./cmd/syncthing + go build -o ./bin/stcli -ldflags "-w -X main.Version v${version}" ./cmd/stcli + ''; + + installPhase = '' + ensureDir $out/bin + cp -r ./bin $out + ''; + + meta = { + homepage = http://syncthing.net/; + description = "Syncthing replaces Dropbox and BitTorrent Sync with something open, trustworthy and decentralized"; + license = with stdenv.lib.licenses; mit; + maintainers = with stdenv.lib.maintainers; [ matejc ]; + platforms = with stdenv.lib.platforms; linux; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index efe5e3834eaf..5c43aa90d2cc 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -9111,6 +9111,8 @@ let gpgSupport = true; }; + syncthing = callPackage ../applications/networking/syncthing { }; + # linux only by now synergy = callPackage ../applications/misc/synergy { };