-
-
Notifications
You must be signed in to change notification settings - Fork 442
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
services/yggdrasil: init #1001
Open
Rubikoid
wants to merge
1
commit into
LnL7:master
Choose a base branch
from
Rubikoid:add/yggdrasil-module
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
services/yggdrasil: init #1001
Changes from all commits
Commits
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 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 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,127 @@ | ||
{ config, lib, pkgs, ... }: | ||
with lib; | ||
let | ||
cfg = config.services.yggdrasil; | ||
|
||
settingsProvided = cfg.settings != { }; | ||
configFileProvided = cfg.configFile != null; | ||
|
||
format = pkgs.formats.json { }; | ||
in | ||
{ | ||
meta.maintainers = [ "rubikoid" ]; | ||
|
||
options = with types; { | ||
services.yggdrasil = { | ||
enable = mkEnableOption "the yggdrasil system service"; | ||
|
||
settings = mkOption { | ||
type = format.type; | ||
default = { }; | ||
example = { | ||
Peers = [ | ||
"tcp://aa.bb.cc.dd:eeeee" | ||
"tcp://[aaaa:bbbb:cccc:dddd::eeee]:fffff" | ||
]; | ||
Listen = [ | ||
"tcp://0.0.0.0:xxxxx" | ||
]; | ||
}; | ||
description = '' | ||
Configuration for yggdrasil, as a Nix attribute set. | ||
|
||
Warning: this is stored in the WORLD-READABLE Nix store! | ||
Therefore, it is not appropriate for private keys. If you | ||
wish to specify the keys, use {option}`configFile`. | ||
|
||
If no keys are specified then ephemeral keys are generated | ||
and the Yggdrasil interface will have a random IPv6 address | ||
each time the service is started. This is the default. | ||
|
||
If both {option}`configFile` and {option}`settings` | ||
are supplied, they will be combined, with values from | ||
{option}`configFile` taking precedence. | ||
|
||
You can use the command `nix-shell -p yggdrasil --run "yggdrasil -genconf"` | ||
to generate default configuration values with documentation. | ||
''; | ||
}; | ||
|
||
configFile = mkOption { | ||
type = nullOr path; | ||
Enzime marked this conversation as resolved.
Show resolved
Hide resolved
|
||
default = null; | ||
example = "/run/keys/yggdrasil.conf"; | ||
description = lib.mdDoc '' | ||
A file which contains JSON or HJSON configuration for yggdrasil. See | ||
the {option}`settings` option for more information. | ||
|
||
On NixOS, file in this option is limited to 1 MB due to limitations | ||
in systemd. If you would like to share your yggdrasil configuration | ||
between nix-darwin and NixOS, you should keep this limitation in mind, | ||
even though there is no equivalent limit on macOS. | ||
''; | ||
}; | ||
|
||
package = mkPackageOption pkgs "yggdrasil" { }; | ||
|
||
extraArgs = mkOption { | ||
type = listOf str; | ||
default = [ ]; | ||
example = [ "-loglevel" "info" ]; | ||
description = lib.mdDoc "Extra command line arguments."; | ||
}; | ||
|
||
logFile = mkOption { | ||
type = nullOr path; | ||
default = null; | ||
example = "/var/log/yggdrasil.log"; | ||
description = "Path to logfile with stdout and stderr of yggdrsail daemon"; | ||
}; | ||
}; | ||
}; | ||
|
||
config = mkIf cfg.enable ( | ||
let | ||
yggdrasilConf = "/run/yggdrasil/yggdrasil.conf"; | ||
binYggdrasil = "${cfg.package}/bin/yggdrasil"; | ||
binHjson = "${pkgs.hjson-go}/bin/hjson-cli"; | ||
binJq = "${pkgs.jq}/bin/jq"; | ||
in | ||
{ | ||
environment.systemPackages = [ cfg.package ]; | ||
|
||
# have to write it in that way to not interfere with brew's (or idk github?) ygg.plist | ||
launchd.daemons.ygg = | ||
{ | ||
script = '' | ||
set -euo pipefail | ||
|
||
mkdir -p $(dirname ${yggdrasilConf}) | ||
|
||
# prepare config file | ||
${(if settingsProvided || configFileProvided then | ||
"echo " | ||
|
||
+ (lib.optionalString settingsProvided | ||
"'${builtins.toJSON cfg.settings}'") | ||
+ (lib.optionalString configFileProvided | ||
"$(${binHjson} -c ${cfg.configFile})") | ||
+ " | ${binJq} -s add | ${binYggdrasil} -normaliseconf -useconf > ${yggdrasilConf}" | ||
else | ||
"if [ ! -f '${yggdrasilConf}' ]; then ${binYggdrasil} -genconf > ${yggdrasilConf}; fi")} | ||
|
||
# start yggdrasil | ||
${binYggdrasil} -useconffile ${yggdrasilConf} ${lib.strings.escapeShellArgs cfg.extraArgs} | ||
''; | ||
|
||
serviceConfig = { | ||
ProcessType = "Interactive"; | ||
StandardOutPath = cfg.logFile; | ||
StandardErrorPath = cfg.logFile; | ||
KeepAlive = true; | ||
RunAtLoad = true; | ||
}; | ||
}; | ||
} | ||
); | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add yourself as a maintainer for this module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not contributed to nixpkgs yet, so I have no
lib.maintainers
record, so I leaved simple string with my username, is this okay?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you change it to
maintainers.rubikoid or "rubikoid"
so if you ever end up maintaining packages in Nixpkgs it'll still refer to you