Search code examples
asp.netnixnixos

How to build a working Nix package from an ASP.NET project?


I am able to build the project using buildDotnetModule and then install it by adding to environment.systemPackages. But when run from the terminal the website does not work properly:

Request finished HTTP/2 GET https://my.app/css/site.css - 404 0

This seems to be because MyApp does not know where to find wwwroot. I am not even sure it gets copied to the derivation.


Solution

  • Turns out ASP.NET allows you to override wwwroot location by setting environment variable WEBROOT.

    When you are building a NixOS service, you can set it using

    WEBROOT = "${myapp}/lib/myapp/wwwroot";
    

    where myapp is your package/derivation.

    I've added this info with more details and a complete example to https://wiki.nixos.org/wiki/DotNET