Skip to content

Add lotide, hitide and service definitions for both #107505

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

Closed
wants to merge 5 commits into from

Conversation

matthiasbeyer
Copy link
Contributor

Add lotide, hitide and service definitions for both.

As I do not often write service definitions, please someone have a look at those.
I did not yet test them. I don't know how, tbh. Maybe by rebasing these patches to nixos-stable and then building my system from it? Isn't there a smoother way for that?

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.

Sorry, something went wrong.

@ofborg ofborg bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Dec 23, 2020
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.

Thanks for the contribution. I have left some comments I hope that you will find helpful. If you need any clarification, etc... please don't hesitate to ask.

There are a few options to test this. You could use build-vm, include these modules into your current system using overlays and imports, build your system against this branch, etc... In addition to any of these ways a NixOS test would be greatly appreciated. See the nixos/tests folder for examples of NixOS tests. These tests give committers unfamiliar with the software greater confidence in merging updates to your packages in the future.

backendHost = mkOption {
default = null;
type = types.string;
description = "URL path to lotide";
Copy link
Member

Choose a reason for hiding this comment

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

Please consistently use a trailing period for all descriptions, except for those with mkEnableOption.


port = mkOption {
default = 4333;
type = types.int;
Copy link
Member

Choose a reason for hiding this comment

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

types.port please.

Comment on lines 39 to 42
Environment = [
"BACKEND_HOST=${cfg.backendHost}"
"PORT=${cfg.port}"
];
Copy link
Member

Choose a reason for hiding this comment

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

I prefer to use systemd.services.<name>.environment here instead, like so:

systemd.services.hitide = {
  environment = {
    BACKEND_HOST = cfg.backendHost;
    PORT = cfg.port;
  };
};

options.services.hitide = {
enable = mkEnableOption "the hitide service";

package = mkOption {
Copy link
Member

Choose a reason for hiding this comment

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

There is only one version of hitide available, and there are no variants on it. This option provides no value, in my opinion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I disagree... I started contributing to lotide/hitide development and would like to run development versions of it on my server, where I overwrite the package to build from different sources. This option gives me the abiltity to easily deploy different versions.
I would like to keep it therefore.

Copy link
Member

Choose a reason for hiding this comment

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

Sure, it is fine to keep... but it sounds like what you really want is an overlay 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After some more thinking, I guess you're right here.

};

config = mkIf cfg.enable {
systemd.services.hitide = {
Copy link
Member

Choose a reason for hiding this comment

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

Would you consider submitting a change upstream to include a systemd unit in their repo? If so, we could eventually (mostly) drop the unit from nixpkgs an utilize systemd.packages = [ pkgs.hitide ];. If you're up for that full bonus points will be awarded 🎉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure whether they would accept such patches upstream, but I will see what I can do and then report back here.

Copy link
Member

Choose a reason for hiding this comment

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

Fantastic! Thanks.

};

config = mkIf cfg.enable {
systemd.services.lotide = {
Copy link
Member

Choose a reason for hiding this comment

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

Would you consider submitting a change upstream to include a systemd unit in their repo? If so, we could eventually (mostly) drop the unit from nixpkgs an utilize systemd.packages = [ pkgs.lotide ];. If you're up for that full bonus points will be awarded 🎉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you give some more detail on that? Does that mean that the lotide.service or hitide.service file from upstream can be included here? How can I point to the actual path in the upstream repository? How can I make them configurable from nix?

Copy link
Member

Choose a reason for hiding this comment

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

Sure. If pkgs.lotide any .service files under $out/lib/systemd/system and you specify systemd.packages = [ pkgs.lotide ]; then these systemd unit files will be included in your system when built.

Checkout this commit where I made use of the upstream systemd unit, but then provided a few changes on top of the upstream unit specifically for NixOS.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So the package needs to install them properly, okay.
And there's no way for a user of the service definition to overwrite values in the definition?

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 think so.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm. After some more thinking about the whole thing, I guess it is not a good idea to include a .service file from upstream - because lotide/hitide is configured via environment variables... A user actually wants to overwrite the environment of the services. Having a .service file prevents that (from my understanding).

Copy link
Member

Choose a reason for hiding this comment

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

Both NixOS and systemd excel here. Both allow extensive overriding to handle situations like this, both from the perspective of the distro and the perspective of the sysadmin.

Here is a reasonable starting point to learn about this: https://serverfault.com/questions/413397/how-to-set-environment-variable-in-systemd-service

Let me know if you have any questions.

@matthiasbeyer
Copy link
Contributor Author

Thanks for your suggestions, I will resolve them in the coming days.


BTW: What did the github engineers think when they built the "Commit suggestion" feature? Why doesn't this create !fixup commits by default? This feature is complete bullshit if it does not create fixup commits...
(not your fault of course, I just wanted to say this loud)

@matthiasbeyer
Copy link
Contributor Author

matthiasbeyer commented Dec 28, 2020

Okay, so I just pushed some fixups (for example I used the deprecated types.string, which was replaced with types.str now).
Unfortunately, I fail to build a testing VM with lotide and hitide:

I tried to use nixos-shell with:

{ config, pkgs, ... }:
{
  boot.kernelPackages = pkgs.linuxPackages_latest;

  services.lotide = {
    enable = true;
    databaseUrl = "postgresql://user@passwort@localhost:5432/lotidedb";
    hostUrlActivityPub = "https://lotide.example.com";
    hostUrlAPI = "https://lotide.example.com/api";
    apubProxyRewrites = true;
    allowForwarded = true;
  };

  services.hitide = {
    enable = true;
    backendHost = "localhost"; # default
      port = 4333; # default
  };

  services.nginx = {
    enable = true;
    virtualHosts = {
      "lotide.example.com" = {
        locations."/".proxyPass = "http://localhost:${builtins.toString config.services.hitide.port}";
      };
    };
  };

  services.postgresql = {
    enable = true;
    package = pkgs.postgresql_12;
    dataDir = "/var/db-lotide";

    initialScript = pkgs.writeText "psql-init" ''
      CREATE USER user PASSWORD 'password' LOGIN;
    CREATE DATABASE lotidedb WITH OWNER user;
    '';
  };
}

Edit: It errors with "expected set, got list" or something like that. But I do not know why.

@ofborg ofborg bot added 8.has: package (new) This PR adds a new package 11.by: package-maintainer This PR was created by the maintainer of the package it changes 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 labels Dec 28, 2020
@aanderse
Copy link
Member

aanderse commented Jan 3, 2021

@matthiasbeyer apply this to fix: a5c9b67

matthiasbeyer and others added 5 commits February 1, 2021 15:23

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
@matthiasbeyer matthiasbeyer deleted the init-lohitide branch April 13, 2021 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 8.has: package (new) This PR adds a new package 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 11.by: package-maintainer This PR was created by the maintainer of the package it changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants