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/gitea: add nginx configuration #218020

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Izorkin
Copy link
Contributor

@Izorkin Izorkin commented Feb 24, 2023

Description of changes

Add nginx configuration.

Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.05 Release Notes (or backporting 22.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

nixos/modules/services/misc/gitea.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/gitea.nix Show resolved Hide resolved
nixos/modules/services/misc/gitea.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/gitea.nix Show resolved Hide resolved
nixos/modules/services/misc/gitea.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/gitea.nix Outdated Show resolved Hide resolved
@Izorkin
Copy link
Contributor Author

Izorkin commented Mar 8, 2023

Don't need access to /var/empty.

@Izorkin Izorkin marked this pull request as ready for review March 8, 2023 18:03
Comment on lines 484 to 573
locations."^~ /avatars/" = {
alias = "${cfg.stateDir}/data/avatars/";
tryFiles = "$uri =404";

extraConfig = ''
default_type "image";
'' + nginxCommonHeaders;
};

locations."^~ ${cfg.settings.server.STATIC_URL_PREFIX}/assets/" = {
alias = "${cfg.package.data}/public/";
tryFiles = "$uri =404";
Copy link
Member

Choose a reason for hiding this comment

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

I thought about it a few days, and I really do not see that much value in letting nginx serve static files directly.
As mentioned in #218020 (comment), even big instances don't seem to enable this feature.
And in the context of nixpkgs, it just makes this config unnecessarily complex.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If possible, I always prefer to serve static files directly through nginx. In this case the file will be transferred a little faster.

Copy link
Member

Choose a reason for hiding this comment

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

/avatars/ (and /repo-avatars/, for that matter) isn't static, though.
It dynamically resizes the image based on the ?size uri parameter.

And can be overwritten via picture.AVATAR_UPLOAD_PATH (picture.REPOSITORY_AVATAR_UPLOAD_PATH), which would break "${cfg.stateDir}/data/avatars/".

Furthermore, those could be stored remotely using an entirely different storage driver using AVATAR_STORAGE_TYPE (REPOSITORY_AVATAR_STORAGE_TYPE).

I stand by what I said and do not understand why this nixos/gitea module needs to be made more complex than it needs to be.

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 can later try to test the operation with these parameters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

/avatars/ (and /repo-avatars/, for that matter) isn't static, though.
It dynamically resizes the image based on the ?size uri parameter.

Image processing is done by the browser, the gitea service is not involved.

And can be overwritten via picture.AVATAR_UPLOAD_PATH (picture.REPOSITORY_AVATAR_UPLOAD_PATH), which would break "${cfg.stateDir}/data/avatars/".

Furthermore, those could be stored remotely using an entirely different storage driver using AVATAR_STORAGE_TYPE (REPOSITORY_AVATAR_STORAGE_TYPE).

Fixed!

Copy link
Member

@emilylange emilylange Mar 17, 2023

Choose a reason for hiding this comment

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

If Gravatar is enabled, then /avatar/<email-hash>?size=96 redirects (http/303) to https://secure.gravatar.com/avatar/<email-hash>?d=identicon&s=96

You are, however, correct, that the local storage does not resize the images server-side (yet?1)

Your avatar-serving breaks if

  • Gravatar isn't disabled (DISABLE_GRAVATAR), which as of v1.18 moved to the database, meaning you can no longer assert it from the nixos config. OR
  • OFFLINE_MODE is enabled, which also disables Gravatar as side effect. OR
  • AVATAR_STORAGE_TYPE/REPOSITORY_AVATAR_STORAGE_TYPE is to something custom/not local

Plus, the docs for STATIC_URL_PREFIX explicitly state

[...] Avatar images are dynamic resources and still served by Gitea. [...]

Footnotes

  1. Could change in the future, see https://github.com/go-gitea/gitea/issues/20918

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If gravatar is used, the link will have an address like this - https://www.gravatar.com/avatar/... As a result, the rule location ^~ /avatars/ { will not work for them.

Plus, the docs for STATIC_URL_PREFIX explicitly state

If avatar handling in gitea changes in the future, we can fix the nginx configuration.

Added small fix.

Copy link
Member

Choose a reason for hiding this comment

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

oh lol sorry -- my bad, yes, you are right.
I somehow overlooked that additional s in /avatars/ compared to /avatar/ 😅

I would still prefer this to be dropped altogether.
But I also don't want to annoy you anymore regarding this.
Just keep it however you imagined it originally and let the other reviewers decide.
Sorry for the noise (and the whole back and forth)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Your comments helped improve PR. I didn't take into account possible changes to the defaults when I created the PR.

nixos/modules/services/misc/gitea.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/gitea.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/gitea.nix Outdated Show resolved Hide resolved
@Izorkin Izorkin force-pushed the add-gitea-nginx branch 2 times, most recently from 9e825b3 to 907ff8f Compare March 10, 2023 20:46
@Ma27
Copy link
Member

Ma27 commented Mar 11, 2023

Just two minor things. I guess it'd be nice to extend the VM test to check if e.g. avatars are served correctly, but other than that it looks good to me, thanks 👍

@Izorkin
Copy link
Contributor Author

Izorkin commented Mar 11, 2023

Just two minor things. I guess it'd be nice to extend the VM test to check if e.g. avatars are served correctly, but other than that it looks good to me, thanks 👍

Tested on a test virtual machine, no problems with avatars

root = "/var/empty";

locations."/" = {
proxyPass = (if cfg.enableUnixSocket then "http://unix:/run/gitea/gitea.sock" else "http://127.0.0.1:${toString cfg.httpPort}");
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
proxyPass = (if cfg.enableUnixSocket then "http://unix:/run/gitea/gitea.sock" else "http://127.0.0.1:${toString cfg.httpPort}");
proxyPass = if cfg.enableUnixSocket then "http://unix:/run/gitea/gitea.sock" else "http://127.0.0.1:${toString cfg.httpPort}";

Copy link
Member

Choose a reason for hiding this comment

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

One could also use "http://unix:${cfg.settings.server.HTTP_ADDR}" instead of
"http://unix:/run/gitea/gitea.sock".

And if we go down that route, it might also be worth setting cfg.httpAddress = "127.0.0.1" (which in turn sets cfg.settings.server.HTTP_ADDR) when cfg.configureNginx is enabled to further deduplicate the addresses used and allow something like:

proxyPass = "http://" +
  (lib.optionalString cfg.enableUnixSocket "unix:") +
  cfg.settings.server.HTTP_ADDR +
  (lib.optionalString (!cfg.enableUnixSocket) ":${toString cfg.httpPort}");

Or assert cfg.enableUnixSocket = true when cfg.configureNginx = true instead of just setting the default for it.
That would at least simplify the logic /shrug

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update to:

proxyPass = if cfg.enableUnixSocket then "http://unix:${cfg.settings.server.HTTP_ADD}" else "http://127.0.0.1:${toString cfg.httpPort}";

And if we go down that route, it might also be worth setting cfg.httpAddress = "127.0.0.1" (which in turn sets cfg.settings.server.HTTP_ADDR) when cfg.configureNginx is enabled to further deduplicate the addresses used and allow something like:

By default HTTP_ADDR = "0.0.0.0";, not 127.0.0.1.

Or assert cfg.enableUnixSocket = true when cfg.configureNginx = true instead of just setting the default for it.
That would at least simplify the logic /shrug

Change to:

     enableUnixSocket = mkOption {
        type = types.bool;
        default = cfg.configureNginx;

or:

     enableUnixSocket = mkOption {
        type = types.bool;
        default = true;

?

@Izorkin Izorkin force-pushed the add-gitea-nginx branch 2 times, most recently from b1d4414 to 3e6c62b Compare March 20, 2023 12:08
@Izorkin
Copy link
Contributor Author

Izorkin commented Dec 24, 2023

Remove includeSubDomains from Strict-Transport-Security header.

@RaitoBezarius
Copy link
Member

@emilylange @Ma27 Do you think we can come to a conclusion on this change? Either, we decrease the scope into smaller PRs so that authors can at least dispatch some useful changes and then for the more controversial stuff, we can keep this PR.

@emilylange
Copy link
Member

@RaitoBezarius see #218020 (comment).
I dismissed my review with "I'm no longer maintaining gitea" roughly 2 months ago.

I guess I could have been more explicit, but back then I figured this wording alone with the context surrounding it is clear enough.

My bad, let me give it another go:

I completely withdrew my code ownership of gitea and no longer intent to contribute to gitea (in nixpkgs).

Any remaining reviews, objections, whatever, of open or not-yet-merged PRs can and should be ignored.
I don't want to hinder the actual gitea maintainers (anymore?). And I also don't intend to spend any more time on this.
Especially given this simply isn't my realm anymore.

I maintain forgejo, not gitea -- and while forgejo initially did use almost everything from gitea in nixpkgs (drv, module, VM test), this is no longer the case.

@RaitoBezarius
Copy link
Member

@RaitoBezarius see #218020 (comment). I dismissed my review with "I'm no longer maintaining gitea" roughly 2 months ago.

I guess I could have been more explicit, but back then I figured this wording alone with the context surrounding it is clear enough.

My bad, let me give it another go:

I completely withdrew my code ownership of gitea and no longer intent to contribute to gitea (in nixpkgs).

Any remaining reviews, objections, whatever, of open or not-yet-merged PRs can and should be ignored. I don't want to hinder the actual gitea maintainers (anymore?). And I also don't intend to spend any more time on this. Especially given this simply isn't my realm anymore.

I maintain forgejo, not gitea -- and while forgejo initially did use almost everything from gitea in nixpkgs (drv, module, VM test), this is no longer the case.

My apologies, I will not do this mistake again.

@Izorkin
Copy link
Contributor Author

Izorkin commented Jan 17, 2024

Update PR.

@Izorkin
Copy link
Contributor Author

Izorkin commented Feb 16, 2024

@Izorkin Izorkin force-pushed the add-gitea-nginx branch 2 times, most recently from 4511526 to 52f37bb Compare May 12, 2024 10:40
@Izorkin Izorkin requested review from Ma27 and SuperSandro2000 and removed request for Ma27 and SuperSandro2000 May 12, 2024 10:45
@Izorkin Izorkin requested review from Ma27 and SuperSandro2000 and removed request for Ma27 and SuperSandro2000 October 4, 2024 20: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.

6 participants