How to host a file located in ~/ with nginx via nix on a nixos-server?

Viewed 79

In my previous nixos server install, the answer suggested in this article like adding systemd.services.nginx.serviceConfig.ProtectHome = "read-only"; to my config worked for me, but isn't working on my current install.

 - system: `"x86_64-linux"`
 - host os: `Linux 5.15.59, NixOS, 22.11 (Raccoon), 22.11pre398667.39d7f929fbc`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.10.3`
 - channels(root): `"nixos-22.11pre398667.39d7f929fbc"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

I want to host files placed from my user's ~/ so I could easly update/edit files without root privileges.

2 Answers

I would recommend hosting the file in /var/www (or whatever the default path for hosting is in your distro, if this even changes between distros), create an nginx group and add the user nginx to this group (if there isn't one already), change the group ownership of the files in /var/www to nginx, and then add your user to the nginx group.

Okay, nginx can read from /var so my workaround is to use /var/www/website and ln -s /var/www/website ~/website .

*quoting from discourse.nixos.org

Related