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

nixos/spacecookie: convert into settings-style service module #107766

Merged
merged 8 commits into from Apr 10, 2021

Conversation

sternenseemann
Copy link
Member

@sternenseemann sternenseemann commented Dec 27, 2020

Motivation for this change
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • 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 nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

Copy link
Member

@aanderse aanderse left a comment

Choose a reason for hiding this comment

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

Just a few points. Let me know if you need any additional information, if you're not familiar with pkgs.formats, etc...

nixos/modules/services/networking/spacecookie.nix Outdated Show resolved Hide resolved
nixos/modules/services/networking/spacecookie.nix Outdated Show resolved Hide resolved
@sternenseemann sternenseemann marked this pull request as draft March 10, 2021 21:20
@sternenseemann sternenseemann marked this pull request as ready for review March 10, 2021 21:21
@sternenseemann
Copy link
Member Author

Okay, I have yet again refactored the service massively and am eager to hear feedback on it. Sorry, I took a bit, but since I was in the middle of making a new release for spacecookie anyways, I held back until I had everything sort of figured out (not released yet, but I know at least what the configuration changes will be).

New options:

  • package, allowing to change the derivation
  • openFirewall, doing the allowedTCPPorts dance for you
  • address, allowing to customize the address to listen on

I also moved everything except port into the settings attribute which is converted into the config file using pkgs.formats.json.

The thing I'm a bit bothered about is the question of port and address. The problem here is that we don't actually use the capabilities of spacecookie for these options, as the socket is handled by systemd which is why I currently have it outside of settings, but this could be confusing for users possibly.

Another reason for this is, that in the next spacecookie release the top level port option will be deprecated in favor of something like this:

{
  "listen": {
    "port" : 70,
    "addr" : "::1"
  }
}

…where addr does what address does in this version of the service, but won't have any effect if socket activation is used which we do (we only need to pass the port to spacecookie because this is relevant to know at runtime). I've thought about hijacking the listen set from settings, removing addr (because if set it generates a warning if socket activation is used) and using the information gathered to set up spacecookie.socket. However, the catch here is that the syntax for IPv6 addresses in getaddrinfo(3) and systemd.socket(5) is slightly different, so I feel like separating our socket configuration from the settings set makes things a bit clearer, but I'm interested to hear opinions on this.

I have the adjustments for the next version on a separate branch and will PR them when the update hits haskellPackages, but there's no rush or timing to consider as the configuration will stay compatible (even for port).

@sternenseemann sternenseemann changed the title nixos/spacecookie: add extraConfig, openFirewall and package options nixos/spacecookie: convert into settings-style service module Mar 10, 2021
@aanderse
Copy link
Member

@GrahamcOfBorg test spacecookie

@aanderse
Copy link
Member

@sternenseemann not sure what to say about that failed test... 🤷‍♂️

@sternenseemann
Copy link
Member Author

@sternenseemann not sure what to say about that failed test... man_shrugging

That's really weird, since the curl call seems to produce the correct output, but then fails with 56 (“Failure in receiving network data”). I'll ponder this some more tomorrow, I guess.

@sternenseemann
Copy link
Member Author

sternenseemann commented Mar 13, 2021

Seems like the curl -f call is flaky sometimes, I can't reproduce it locally and it doesn't happen on ofborg every time. Maybe we should remove the succeed and just check the output for curl to make sure we never block the channel accidentally?

Edit: Done, see also sternenseemann/spacecookie#42

@sternenseemann sternenseemann force-pushed the spacecookie-flexible branch 2 times, most recently from bb3a22e to b38fc39 Compare March 15, 2021 00:59
@sternenseemann
Copy link
Member Author

Found a less ugly workaround for the curl problem, namely using netcat. Upstream issue is also fixed, really need to get this release out the door now :)

@sternenseemann
Copy link
Member Author

With #116096 we have spacecookie 1.0.0.0 including a fix for the curl flakiness making the test fail! I've reverted the workaround for that in the test and added the new options' description to settings.

@sternenseemann
Copy link
Member Author

@ofborg test spacecookie

* Use proper gopher urls
* The client vms name is also controlled in a single place now
* fileContent holds the precise file content now
* wait for the spacecookie unit instead of the port
  * avoids sending an empty request
  * since spacecookie is a notify service it only is fully started when
    the socket has been set up.
This allows to change the derivation to use for the spacecookie server
binary. We probably should also use justStaticExecutables by default to
reduce the runtime closure of the service.
Convenience shortcut which automatically configures the firewall to open
the port which is also configured for the spacecookie service.
This configuration option reflects a new feature from the unreleased
spacecookie version allowing to customize the address spacecookie will
listen on (e. g. "::1" to bind on link-local addresses only). We will
not use this feature in the future, since the configuration option of
spacecookie naturally only has an effect if we don't use socket
activation (and spacecookie sets up its own socket), but having the same
functionality in the service seems like a good idea.

We can luckily emulate this behavior with socket activation as well.
* Move `hostname` and `root` into a settings submodule with a freeform
  type, allowing users to also use options not known to the NixOS
  service. Compatibility with a warning for the renamed options is also
  trivial to achieve.
* `port` stays where it is as we don't actually use the `port` option of
  spacecookie to set up the socket, but only to inform spacecookie about
  the port we have set in the `systemd.socket` file, this makes more
  sense. Additionally the configuration of the listening port and
  address change in the next spacecookie release — we can dodge this
  issue altogether by doing our own thing, but I'm interested to hear
  opinions on this.
  To ensure that this is not misconfigured, we add an assertion for
  the port option.
* Add an assertion for `user` in settings which has no effect the way
  we are starting spacecookie as it wouldn't be able to call setuid.
  The message also explains how a specific user can be used with
  spacecookie if desired.
* New log options
* The old port option has been deprecated in favor of listen -> port

https://github.com/sternenseemann/spacecookie/blob/master/CHANGELOG.md#1000
The haskellPackages.spacecookie derivation also includes a library and
thus a lot of propagated haskell dependencies. The top-level attribute
uses haskell.lib.justStaticExecutables and therefore only the
executable. This should reduce the runtime closure users have to
download considerably if they only want the server.
Copy link
Member

@aanderse aanderse left a comment

Choose a reason for hiding this comment

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

Sorry this slipped off my radar... Are we good to merge? Are you planning on squashing any commits (I'm indifferent)?

@sternenseemann
Copy link
Member Author

Yes! Almost forgot it as well.

@sternenseemann sternenseemann merged commit 9c989f2 into NixOS:master Apr 10, 2021
@sternenseemann sternenseemann deleted the spacecookie-flexible branch April 10, 2021 13:44
Comment on lines +18950 to +18951
spacecookie =
haskell.lib.justStaticExecutables haskellPackages.spacecookie;
Copy link
Member

Choose a reason for hiding this comment

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

This newline is not required.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't understand why you keep pointing out formatting “issues” on already merged PRs. We have no established formatting guideline in the first place and especially with merged PRs this serves really nothing other than wasting the time of everyone involved.

Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why you keep pointing out formatting “issues” on already merged PRs.

If I have 50 tabs open GitHub sometimes just forgets to refresh them and they are only updated after I posted a comment.

We have no established formatting guideline in the first place

Just do reasonable formatting and that new line there is just because nixfmt enforces a 80 line length which we are not following in nixpkgs anyway.

@sternenseemann sternenseemann restored the spacecookie-flexible branch July 24, 2021 13:38
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