-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
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
nixos/imaginary: init #215222
Merged
Merged
nixos/imaginary: init #215222
Changes from all commits
Commits
Show all changes
2 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 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
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,110 @@ | ||
{ lib, config, pkgs, utils, ... }: | ||
|
||
let | ||
inherit (lib) mdDoc mkEnableOption mkIf mkOption types; | ||
|
||
cfg = config.services.imaginary; | ||
in { | ||
options.services.imaginary = { | ||
enable = mkEnableOption (mdDoc "imaginary image processing microservice"); | ||
|
||
address = mkOption { | ||
type = types.str; | ||
default = ""; | ||
description = mdDoc "Bind address. Corresponds to the `-a` flag."; | ||
example = "localhost"; | ||
}; | ||
|
||
port = mkOption { | ||
type = types.port; | ||
default = 8088; | ||
description = mdDoc "Bind port. Corresponds to the `-p` flag."; | ||
}; | ||
|
||
settings = mkOption { | ||
description = mdDoc '' | ||
Command line arguments passed to the imaginary executable, stripped of | ||
the prefix `-`. See upstream's | ||
[README](https://github.com/h2non/imaginary#command-line-usage) for all | ||
options. | ||
''; | ||
type = types.submodule { | ||
freeformType = with types; attrsOf (oneOf [ | ||
bool | ||
int | ||
(nonEmptyListOf str) | ||
str | ||
]); | ||
|
||
options = { | ||
return-size = mkOption { | ||
type = types.bool; | ||
default = false; | ||
description = mdDoc "Return the image size in the HTTP headers."; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}; | ||
|
||
config = mkIf cfg.enable { | ||
assertions = [ { | ||
assertion = ! lib.hasAttr "a" cfg.settings; | ||
message = "Use services.imaginary.address to specify the -a flag."; | ||
} { | ||
assertion = ! lib.hasAttr "p" cfg.settings; | ||
message = "Use services.imaginary.port to specify the -p flag."; | ||
} ]; | ||
|
||
systemd.services.imaginary = { | ||
after = [ "network.target" ]; | ||
wantedBy = [ "multi-user.target" ]; | ||
serviceConfig = rec { | ||
ExecStart = let | ||
args = lib.mapAttrsToList (key: val: | ||
"-" + key + "=" + lib.concatStringsSep "," (map toString (lib.toList val)) | ||
) (cfg.settings // { a = cfg.address; p = cfg.port; }); | ||
in "${pkgs.imaginary}/bin/imaginary ${utils.escapeSystemdExecArgs args}"; | ||
ProtectProc = "invisible"; | ||
BindReadOnlyPaths = lib.optional (cfg.settings ? mount) cfg.settings.mount; | ||
CapabilityBoundingSet = if cfg.port < 1024 then | ||
[ "CAP_NET_BIND_SERVICE" ] | ||
else | ||
[ "" ]; | ||
AmbientCapabilities = CapabilityBoundingSet; | ||
NoNewPrivileges = true; | ||
DynamicUser = true; | ||
ProtectSystem = "strict"; | ||
ProtectHome = true; | ||
TemporaryFileSystem = [ "/:ro" ]; | ||
PrivateTmp = true; | ||
PrivateDevices = true; | ||
PrivateUsers = cfg.port >= 1024; | ||
ProtectHostname = true; | ||
ProtectClock = true; | ||
ProtectKernelTunables = true; | ||
ProtectKernelModules = true; | ||
ProtectKernelLogs = true; | ||
ProtectControlGroups = true; | ||
RestrictAddressFamilies = [ | ||
"AF_INET" | ||
"AF_INET6" | ||
]; | ||
RestrictNamespaces = true; | ||
LockPersonality = true; | ||
MemoryDenyWriteExecute = true; | ||
RestrictRealtime = true; | ||
PrivateMounts = true; | ||
SystemCallFilter = [ | ||
"@system-service" | ||
"~@privileged" | ||
]; | ||
DevicePolicy = "closed"; | ||
}; | ||
}; | ||
}; | ||
|
||
meta = { | ||
maintainers = with lib.maintainers; [ dotlambda ]; | ||
}; | ||
} |
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
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.
Does emptry string equal to localhost? If I understand the nextcloud doc correct it sounds like you want to run imaginary always bound on localhost.
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.
Yes, it does mean that according to https://pkg.go.dev/net#Dial. I went with upstream's default: https://github.com/h2non/imaginary/blob/master/imaginary.go#L20
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.
Never mind, it means any address. That's also what it says in https://github.com/h2non/imaginary#command-line-usage.
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 guess it should be changed to
localhost
by default. See #100192. But the problem is thatlocalhost
means127.0.0.1
and doesn't include::1
.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 we use
[::1]
?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.
oh, gotta love it. golang/go#9334
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.
Should we set
address = "localhost"
by default anyway?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.
if it's primarily not meant to be accessed from other hosts, probably? don't know enough about the service to be sure. but then again, if it makes for such interesting complications it might just be better to rely on the firewall existing and a note that by default all addresses are bound? 😕
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.
#217339
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.
For the nextcloud use case it is only accessed through localhost.