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/nginx: add cgit sub-service #109915

Closed

Conversation

afix-space
Copy link

@afix-space afix-space commented Jan 19, 2021

Motivation for this change

Similarly to module lighttpd/cgit or nginx/gitweb, add cgit sub-service to nginx

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • [ X] 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"
  • [ X] 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)
  • [ X] Ensured that relevant documentation is up to date
  • [ X] Fits CONTRIBUTING.md.

Copy link
Member

@hmenke hmenke left a comment

Choose a reason for hiding this comment

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

Ideally the module should also have a nixos integration test.

Comment on lines +38 to +53
configText = mkOption {
default = "";
example = ''
virtual-root=/
source-filter=''${pkgs.cgit}/lib/cgit/filters/syntax-highlighting.py
about-filter=''${pkgs.cgit}/lib/cgit/filters/about-formatting.sh
cache-size=1000
scan-path=/srv/git
'';
type = types.lines;
description = ''
Verbatim contents of the cgit runtime configuration file. Documentation
(with cgitrc example file) is available in "man cgitrc". Or online:
http://git.zx2c4.com/cgit/tree/cgitrc.5.txt
'';
};
Copy link
Member

Choose a reason for hiding this comment

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

This way of configuring services is discouraged (see RFC0042). Since the config file has an INI-like format, it should be easy to generate it from Nix expressions. See also https://nixos.org/manual/nixos/stable/index.html#sec-freeform-modules

Comment on lines +55 to +61
virtualHost = mkOption {
default = "_";
type = types.str;
description = ''
VirtualHost to serve cgit on. Default is catch-all.
'';
};
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't scale well. What if a user wants to run multiple cGit instances?

environment.systemPackages = [ pkgs.cgit ];

services.fcgiwrap.enable = true;
services.fcgiwrap.socketAddress = "/run/fcgiwrap.cgit.socket";
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
services.fcgiwrap.socketAddress = "/run/fcgiwrap.cgit.socket";

Leave this at the default or at least use mkDefault.

fastcgi_param SCRIPT_FILENAME ${pkgs.cgit}/cgit/cgit.cgi;
fastcgi_param QUERY_STRING $args;
fastcgi_param HTTP_HOST $server_name;
fastcgi_pass unix:/run/fcgiwrap.cgit.socket;
Copy link
Member

Choose a reason for hiding this comment

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

Use the system default here.

Suggested change
fastcgi_pass unix:/run/fcgiwrap.cgit.socket;
fastcgi_pass unix:${config.services.fcgiwrap.socketAddress}

locations."${cfg.location}" = {
extraConfig =
''
gzip off;
Copy link
Member

Choose a reason for hiding this comment

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

Why do you turn off gzip?

@afix-space
Copy link
Author

Thanks for this interesting feedback, i'll try to improve it. (and also fix the error with my git rebase).

@hmenke
Copy link
Member

hmenke commented Jan 19, 2021

I had a go at this myself, since I'm also using cgit. Here you can see the result:
https://gist.github.com/hmenke/de2db3e303192a29e4bb6837e0bf48ff

@afix-space
Copy link
Author

I had a go at this myself, since I'm also using cgit. Here you can see the result:
https://gist.github.com/hmenke/de2db3e303192a29e4bb6837e0bf48ff

thank you, it's great, I started to watch Freeform submodule but here is a clear example with a test.
thanks again, i will review this sub-service very soon.
Also i might have to open a new pull request because i messed up with git rebase :(
I will be able to learn to use git now with cgit :-)

@hmenke
Copy link
Member

hmenke commented Jan 19, 2021

That's actually not a test (I guess test.nix was a misnomer) but a profile to run a VM using nixos-shell. A nixos test has to built separately still. Let me know if you need any help with that.

@afix-space
Copy link
Author

it seems to me that the new cgit.nix is a very good base to add to nixpkgs modules. If test needed (or not) i'll play a bit with it.
starting by seeing examples in sources.

@afix-space
Copy link
Author

in fact there are still some bug to be fixed, I continue to test and I do a summary later.

@afix-space
Copy link
Author

The problem is that some settings could be multiple (section, repo.url, repo.path, repo.desc, repo.owner...).
This could have been solved by coercedTo like ini in pkgs/pkgs-lib/formats.nix, but they also have to be in a specific order.
Suddenly I need to take a nix pill or a hmenke gist before. :-)

@hmenke
Copy link
Member

hmenke commented Jan 20, 2021

@afix-space I've updated the Gist which should reflect the required changes. For anything that needs to be ordered you can use the include directive to include a cgitrc from a file. It also includes a NixOS test to ensure the functionality. Let me know what you think.

@afix-space
Copy link
Author

Nice changes, well done !
I learn a lot with your nix gist and it will be great this sub-service.

@aanderse
Copy link
Member

@hmenke I think a fair bit of the settingsFormat work you have done there is now merged right into nixpkgs. Something like this is equivalent:

format = pkgs.formats.ini { listAsDuplicates = true; };

See https://github.com/NixOS/nixpkgs/blob/ba5f50a76c352df9bbe8ca5771a20d014c10aa99/pkgs/pkgs-lib/formats.nix#L59..L84 for details.

@afix-space
Copy link
Author

afix-space commented Jan 21, 2021

I think that's why it allows more types than necessary.

@afix-space
Copy link
Author

I had to make a new pull request. (I broke my branche, it's messy to repair)
#110270
I just corrected a few small oversights.

@hmenke
Copy link
Member

hmenke commented Jan 21, 2021

@aanderse Unfortunately, none of the existing settings formats can be used here, because the cgitrc is not quite an INI (no [sections]). Note that I'm using lib.generators.toKeyValue to generate the file instead of lib.generators.toINI (as pkgs.formats.ini would do).

@hmenke
Copy link
Member

hmenke commented Jan 22, 2021

Duplicate of #110270

@hmenke hmenke marked this as a duplicate of #110270 Jan 22, 2021
@hmenke hmenke closed this Jan 22, 2021
@afix-space afix-space deleted the add/nginx-cgit-sub-service branch January 22, 2021 17:57
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

4 participants