-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
magnetico: init package and service #64738
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,214 @@ | ||
| { config, lib, pkgs, ... }: | ||
|
|
||
| with lib; | ||
|
|
||
| let | ||
| cfg = config.services.magnetico; | ||
|
|
||
| dataDir = "/var/lib/magnetico"; | ||
|
|
||
| credFile = with cfg.web; | ||
| if credentialsFile != null | ||
| then credentialsFile | ||
| else pkgs.writeText "magnetico-credentials" | ||
| (concatStrings (mapAttrsToList | ||
| (user: hash: "${user}:${hash}\n") | ||
| cfg.web.credentials)); | ||
|
|
||
| # default options in magneticod/main.go | ||
| dbURI = concatStrings | ||
| [ "sqlite3://${dataDir}/database.sqlite3" | ||
| "?_journal_mode=WAL" | ||
| "&_busy_timeout=3000" | ||
| "&_foreign_keys=true" | ||
| ]; | ||
|
|
||
| crawlerArgs = with cfg.crawler; escapeShellArgs | ||
| ([ "--database=${dbURI}" | ||
| "--indexer-addr=${address}:${toString port}" | ||
| "--indexer-max-neighbors=${toString maxNeighbors}" | ||
| "--leech-max-n=${toString maxLeeches}" | ||
| ] ++ extraOptions); | ||
|
|
||
| webArgs = with cfg.web; escapeShellArgs | ||
| ([ "--database=${dbURI}" | ||
| (if (cfg.web.credentialsFile != null || cfg.web.credentials != { }) | ||
| then "--credentials=${toString credFile}" | ||
| else "--no-auth") | ||
| ] ++ extraOptions); | ||
|
|
||
| in { | ||
|
|
||
| ###### interface | ||
|
|
||
| options.services.magnetico = { | ||
| enable = mkEnableOption "Magnetico, Bittorrent DHT crawler"; | ||
|
|
||
| crawler.address = mkOption { | ||
| type = types.str; | ||
| default = "0.0.0.0"; | ||
| example = "1.2.3.4"; | ||
| description = '' | ||
| Address to be used for indexing DHT nodes. | ||
| ''; | ||
| }; | ||
|
|
||
| crawler.port = mkOption { | ||
| type = types.port; | ||
| default = 0; | ||
| description = '' | ||
| Port to be used for indexing DHT nodes. | ||
| This port should be added to | ||
| <option>networking.firewall.allowedTCPPorts</option>. | ||
| ''; | ||
| }; | ||
|
|
||
| crawler.maxNeighbors = mkOption { | ||
| type = types.ints.positive; | ||
| default = 1000; | ||
| description = '' | ||
| Maximum number of simultaneous neighbors of an indexer. | ||
| Be careful changing this number: high values can very | ||
| easily cause your network to be congested or even crash | ||
| your router. | ||
| ''; | ||
| }; | ||
|
|
||
| crawler.maxLeeches = mkOption { | ||
| type = types.ints.positive; | ||
| default = 200; | ||
| description = '' | ||
| Maximum number of simultaneous leeches. | ||
| ''; | ||
| }; | ||
|
|
||
| crawler.extraOptions = mkOption { | ||
| type = types.listOf types.str; | ||
| default = []; | ||
| description = '' | ||
| Extra command line arguments to pass to magneticod. | ||
| ''; | ||
| }; | ||
|
|
||
| web.address = mkOption { | ||
| type = types.str; | ||
| default = "localhost"; | ||
| example = "1.2.3.4"; | ||
| description = '' | ||
| Address the web interface will listen to. | ||
| ''; | ||
| }; | ||
|
|
||
| web.port = mkOption { | ||
| type = types.port; | ||
| default = 8080; | ||
| description = '' | ||
| Port the web interface will listen to. | ||
| ''; | ||
| }; | ||
|
|
||
| web.credentials = mkOption { | ||
| type = types.attrsOf types.str; | ||
| default = {}; | ||
| example = lib.literalExample '' | ||
| { | ||
| myuser = "$2y$12$YE01LZ8jrbQbx6c0s2hdZO71dSjn2p/O9XsYJpz.5968yCysUgiaG"; | ||
| } | ||
| ''; | ||
| description = '' | ||
| The credentials to access the web interface, in case authentication is | ||
| enabled, in the format <literal>username:hash</literal>. If unset no | ||
| authentication will be required. | ||
|
|
||
| Usernames must start with a lowercase ([a-z]) ASCII character, might | ||
| contain non-consecutive underscores except at the end, and consists of | ||
| small-case a-z characters and digits 0-9. The | ||
| <command>htpasswd</command> tool from the <package>apacheHttpd | ||
| </package> package may be used to generate the hash: <command>htpasswd | ||
| -bnBC 12 username password</command> | ||
|
|
||
| <warning> | ||
| <para> | ||
| The hashes will be stored world-readable in the nix store. | ||
| Consider using the <literal>credentialsFile</literal> option if you | ||
| don't want this. | ||
| </para> | ||
| </warning> | ||
| ''; | ||
| }; | ||
|
|
||
| web.credentialsFile = mkOption { | ||
| type = types.nullOr types.path; | ||
| default = null; | ||
| description = '' | ||
| The path to the file holding the credentials to access the web | ||
| interface. If unset no authentication will be required. | ||
|
|
||
| The file must constain user names and password hashes in the format | ||
| <literal>username:hash </literal>, one for each line. Usernames must | ||
| start with a lowecase ([a-z]) ASCII character, might contain | ||
| non-consecutive underscores except at the end, and consists of | ||
| small-case a-z characters and digits 0-9. | ||
| The <command>htpasswd</command> tool from the <package>apacheHttpd | ||
| </package> package may be used to generate the hash: | ||
| <command>htpasswd -bnBC 12 username password</command> | ||
| ''; | ||
| }; | ||
|
|
||
| web.extraOptions = mkOption { | ||
| type = types.listOf types.str; | ||
| default = []; | ||
| description = '' | ||
| Extra command line arguments to pass to magneticow. | ||
| ''; | ||
| }; | ||
|
|
||
| }; | ||
|
|
||
| ###### implementation | ||
|
|
||
| config = mkIf cfg.enable { | ||
|
|
||
| users.users.magnetico = { | ||
| description = "Magnetico daemons user"; | ||
| }; | ||
|
|
||
| systemd.services.magneticod = { | ||
| description = "Magnetico DHT crawler"; | ||
| wantedBy = [ "multi-user.target" ]; | ||
| after = [ "network-online.target" ]; | ||
|
|
||
| serviceConfig = { | ||
| User = "magnetico"; | ||
| Restart = "on-failure"; | ||
| ExecStart = "${pkgs.magnetico}/bin/magneticod ${crawlerArgs}"; | ||
| }; | ||
| }; | ||
|
|
||
| systemd.services.magneticow = { | ||
| description = "Magnetico web interface"; | ||
| wantedBy = [ "multi-user.target" ]; | ||
| after = [ "network-online.target" "magneticod.service"]; | ||
|
|
||
| serviceConfig = { | ||
| User = "magnetico"; | ||
| StateDirectory = "magnetico"; | ||
| Restart = "on-failure"; | ||
| ExecStart = "${pkgs.magnetico}/bin/magneticow ${webArgs}"; | ||
| }; | ||
| }; | ||
|
|
||
| assertions = | ||
| [ | ||
| { | ||
| assertion = cfg.web.credentialsFile != null || cfg.web.credentials != { }; | ||
| message = '' | ||
| The options services.magnetico.web.credentialsFile and | ||
| services.magnetico.web.credentials are mutually exclusives. | ||
| ''; | ||
| } | ||
| ]; | ||
|
|
||
| }; | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import ./make-test.nix ({ pkgs, ...} : { | ||
| name = "magnetico"; | ||
| meta = with pkgs.stdenv.lib.maintainers; { | ||
| maintainers = [ rnhmjoj ]; | ||
| }; | ||
|
|
||
| machine = { ... }: { | ||
| imports = [ ../modules/profiles/minimal.nix ]; | ||
|
|
||
| networking.firewall.allowedTCPPorts = [ 9000 ]; | ||
|
|
||
| services.magnetico = { | ||
| enable = true; | ||
| crawler.port = 9000; | ||
| web.credentials.user = "$2y$12$P88ZF6soFthiiAeXnz64aOWDsY3Dw7Yw8fZ6GtiqFNjknD70zDmNe"; | ||
| }; | ||
| }; | ||
|
|
||
| testScript = | ||
| '' | ||
| startAll; | ||
| $machine->waitForUnit("magneticod"); | ||
| $machine->waitForUnit("magneticow"); | ||
| $machine->succeed("${pkgs.curl}/bin/curl -u user:password http://localhost:8080"); | ||
| $machine->succeed("${pkgs.curl}/bin/curl -u user:wrongpwd http://localhost:8080") =~ "Unauthorised." or die; | ||
| $machine->shutdown(); | ||
| ''; | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| { lib, fetchFromGitHub, buildGoModule, go-bindata }: | ||
|
|
||
| buildGoModule rec { | ||
| pname = "magnetico"; | ||
| version = "0.8.1"; | ||
|
|
||
| src = fetchFromGitHub { | ||
| owner = "boramalper"; | ||
| repo = "magnetico"; | ||
| rev = "v${version}"; | ||
| sha256 = "1f7y3z9ql079ix6ycihkmd3z3da3sfiqw2fap31pbvvjs65sg644"; | ||
| }; | ||
|
|
||
| modSha256 = "1h9fij8mxlxfw7kxix00n10fkhkvmf8529fxbk1n30cxc1bs2szf"; | ||
|
|
||
| buildInputs = [ go-bindata ]; | ||
| buildPhase = '' | ||
| make magneticow magneticod | ||
| ''; | ||
|
|
||
| doCheck = true; | ||
| checkPhase = '' | ||
| make test | ||
rnhmjoj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ''; | ||
|
|
||
| meta = with lib; { | ||
| description = "Autonomous (self-hosted) BitTorrent DHT search engine suite."; | ||
| homepage = https://github.com/boramalper/magnetico; | ||
| license = licenses.agpl3; | ||
| badPlatforms = platforms.darwin; | ||
| maintainers = with maintainers; [ rnhmjoj ]; | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.