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

nginx service: add nested locations support #40303

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

Conversation

sshisk
Copy link
Contributor

@sshisk sshisk commented May 10, 2018

Motivation for this change

Copy locations from vhost-options.nix so can be nested.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option build-use-sandbox in nix.conf on non-NixOS)
  • 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 nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

Copy link
Member

@infinisil infinisil left a comment

Choose a reason for hiding this comment

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

What are nested locations used for?

getSubOptions = prefix: {};
getSubModules = null;
};

Copy link
Member

Choose a reason for hiding this comment

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

You can just override the description of the type (type // { description = "custom descr"; }) to get rid of the infinite recursion, no function in lib needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This doesn't work. Recursion occurs in manual generation when it tries to generate options description for locations._name_.locations._name_ etc.

Copy link
Member

Choose a reason for hiding this comment

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

There's potentially a more thorough solution now, in

Look for recursive = in types.nix.

cc @ncfavier

@sshisk
Copy link
Contributor Author

sshisk commented May 31, 2019

@infinisil I use them to restrict access to sublocations with password. They are useful for other settings too.

@sshisk
Copy link
Contributor Author

sshisk commented Aug 18, 2019

Any update?

@stale
Copy link

stale bot commented Jun 1, 2020

Thank you for your contributions.
This has been automatically marked as stale because it has had no activity for 180 days.
If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.
Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the
    related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse. 3. Ask on the #nixos channel on
    irc.freenode.net.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 1, 2020
@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Oct 3, 2020
@stale
Copy link

stale bot commented Jun 4, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 4, 2021
@abbradar
Copy link
Member

I have used this for sub-locations like those:

          locations = {
            "/private/" = {
              extraConfig = ''
                auth_basic "Secret area";
                auth_basic_user_file /root/private-htpasswd;
              '';
              locations."/private/files/".extraConfig = "autoindex on;";
            };

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Dec 22, 2021
This function is helpful for infinitely recursive types to stop traversing early.
Without this infinitely recursive options crash Nix during documentation build.
@sshisk
Copy link
Contributor Author

sshisk commented Dec 23, 2021

I rebased tree atop latest master.

@abbradar
Copy link
Member

abbradar commented Jan 8, 2022

@infinisil kind ping -- I'd like to merge because I use this patch, but not sure you are okay with this. Also I'm not sure hideSubTree is the good way here.

Copy link
Member

@infinisil infinisil left a comment

Choose a reason for hiding this comment

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

I'd like to merge this once these points are addressed :)

@@ -111,6 +112,21 @@ with lib;
'';
};

locations = mkOption {
type = types.attrsOf (types.hideSubTree (types.submodule self));
Copy link
Member

Choose a reason for hiding this comment

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

The hideSubTree hack is not necessary anymore thanks to @roberth with 64dfd98. Now you can do

Suggested change
type = types.attrsOf (types.hideSubTree (types.submodule self));
type = types.attrsOf (types.submodule self);
visible = "shallow";

@@ -7,6 +7,7 @@

with lib;

let self =
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: Instead of doing the recursion here, do it in ./vhost-options.nix by doing

diff --git a/nixos/modules/services/web-servers/nginx/vhost-options.nix b/nixos/modules/services/web-servers/nginx/vhost-options.nix
index c4e8285dc48..d687cb8ab2d 100644
--- a/nixos/modules/services/web-servers/nginx/vhost-options.nix
+++ b/nixos/modules/services/web-servers/nginx/vhost-options.nix
@@ -271,9 +271,12 @@ with lib;
     };
 
     locations = mkOption {
-      type = types.attrsOf (types.submodule (import ./location-options.nix {
-        inherit lib;
-      }));
+      type =
+        let
+          locationsType = types.attrsOf (types.submodule (import ./location-options.nix {
+            inherit lib locationsType;
+          }));
+        in locationsType;
       default = {};
       example = literalExpression ''
         {

Then you can take the locationsType argument in this module (though it's passed a bit unconventional, but that's another issue), and use that directly as the type for the locations option.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Sep 21, 2022
@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 5, 2023
@kirillrdy
Copy link
Member

kirillrdy commented Jan 23, 2024

This branch has conflicts that must be resolved ( damn English )

@infinisil
Copy link
Member

It looks like the PR author isn't active anymore. I encourage others to pick this up.

@wegank wegank added 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 2.status: merge conflict labels Mar 19, 2024
@wegank wegank marked this pull request as draft March 20, 2024 16:12
@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 20, 2024
@wegank wegank added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 20, 2024
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

9 participants