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/gerrit: init #82137

Closed
wants to merge 3 commits into from
Closed

nixos/gerrit: init #82137

wants to merge 3 commits into from

Conversation

edef1c
Copy link
Member

@edef1c edef1c commented Mar 9, 2020

Motivation for this change

Gerrit is available in nixpkgs, but isn't particularly easy to set up.
A number of people have asked me to share and/or upstream the Gerrit NixOS module we're using at @mutable.
This is an early draft, and I'd prefer not to merge this until we've refined it a bit more.
It depends on #75584, so it can't be merged by itself anyway.

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)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

cc @flokli @yorickvP

@edef1c edef1c changed the title ###### Motivation for this change nixos/gerrit: init Mar 9, 2020
@zimbatm
Copy link
Member

zimbatm commented Mar 9, 2020

good timing, I started writing a Gerrit NixOS module last week. I will take a look and see how both efforts could be merged.

Copy link
Contributor

@yorickvP yorickvP left a comment

Choose a reason for hiding this comment

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

Some review comments. Feel free to ignore.

nixos/modules/services/misc/gerrit.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/gerrit.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/gerrit.nix Show resolved Hide resolved
cache.directory = "/var/cache/gerrit";
};

users.users.gerrit = {};
Copy link
Contributor

Choose a reason for hiding this comment

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

Would DynamicUser be possible?

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe! I wasn't sure how that would interact with some parts of my target environment, so I haven't tried it yet.

nixos/modules/services/misc/gerrit.nix Outdated Show resolved Hide resolved

listenAddress = mkOption {
type = types.str;
default = "0.0.0.0:80";
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not entirely sure if exposing http to the internet on port 80 is ever a good idea. Is the intended usage behind some https reverse proxy? Or on an internal net?

Copy link
Member

Choose a reason for hiding this comment

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

It depends on your setup. The machine might be forwarded from an internal or external load-balancer. This is up to the user really.

The default when installing gerrit is *:8080

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've been using this behind an HTTPS reverse proxy. I suppose this should plausibly default to interacting with the ACME module, but I personally prefer to keep the actual TLS keys away from services themselves. My production deployment uses Google Cloud's TLS termination.

Copy link
Member

@zimbatm zimbatm left a comment

Choose a reason for hiding this comment

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

  • handle secrets.config
  • handle config folders like its/jira.config


cfg = config.services.gerrit;

cmd = "${pkgs.jre_headless}/bin/java -jar ${cfg.package}/webapps/gerrit-${cfg.package.version}.war";
Copy link
Member

Choose a reason for hiding this comment

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

What do you think of wrapping this into a script and adding it in the systemPackages? With some plugins I found that it's useful to be able to call gerrit init to set it up and discover the available options.

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'm into it, I've definitely found it annoying to have to dig the command out of systemctl cat to check stuff while debugging.

Copy link
Member

Choose a reason for hiding this comment

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

pushed to your PR as 17d73b8

I also added a jvmOpts module option because it because quickly necessary to tune the JVM for larger gerrit instances.

Comment on lines 133 to 134
serviceConfig.ExecStartPre = pkgs.writeScript "gerrit-pre" ''
#! ${pkgs.bash}/bin/bash -eu
Copy link
Member

Choose a reason for hiding this comment

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

a matter of preference

Suggested change
serviceConfig.ExecStartPre = pkgs.writeScript "gerrit-pre" ''
#! ${pkgs.bash}/bin/bash -eu
serviceConfig.ExecStartPre = pkgs.writeShellScript "gerrit-pre" ''
set -euo pipefail

nixos/modules/services/misc/gerrit.nix Outdated Show resolved Hide resolved
settingsFile = pkgs.writeText "gerrit.config" ''
${generators.toINI {} cfg.settings}
${generators.toINI { mkSectionName = mkPluginSectionName; } cfg.pluginSettings}
'';
Copy link
Member

Choose a reason for hiding this comment

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

I propose to import the git config generator from home-manager into the generators. It's quite close to the INI format but not entirely.

https://github.com/rycee/home-manager/blob/master/modules/programs/git.nix

Copy link
Member Author

Choose a reason for hiding this comment

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

That would be neat, but this might be a conversation for #75584.


listenAddress = mkOption {
type = types.str;
default = "0.0.0.0:80";
Copy link
Member

Choose a reason for hiding this comment

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

It depends on your setup. The machine might be forwarded from an internal or external load-balancer. This is up to the user really.

The default when installing gerrit is *:8080

};
httpd.inheritChannel = "true";
# TODO(edef): support SSH properly
sshd.listenAddress = "off";
Copy link
Member

Choose a reason for hiding this comment

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

What is the problem with SSH? Is it because of the socket activation?

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'm not sure how much to integrate host key generation, and it's not particularly usable for me (the underlying SSH implementation lacks support for certificate keys), so I have no strong interest in debugging it. We should probably enable WantedBy=multi-user.target if SSH is enabled.

* the module option only accepts strings as values
* make sure to also remove the plugins when it's a folder
@zimbatm zimbatm mentioned this pull request Mar 19, 2020
10 tasks
@zimbatm
Copy link
Member

zimbatm commented Mar 19, 2020

@edef1c I had too much changes to group them into logical commit so I made a separate PR. Hope that's ok! #82929

@edef1c edef1c closed this Mar 22, 2020
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