Can't configure element-web

Greetings,

I’m trying to install and configure the element web package.

I added the package to environment.systemPackages in configuration.nix and in my nginx.nix I added a location:

"/element/" = {
   alias = pkgs.element-web.outPath + "/";
   index = "index.html";
};

And it’s working fine! Now I’m trying to configure it, but I don’t understand how I’m supposed to do it.

There is the following line in element-web’s package:
configOverrides = writeText "element-config-overrides.json" (builtins.toJSON (noPhoningHome // conf));

And at the beginning of the file:
{ lib, stdenv, fetchurl, writeText, jq, conf ? {} }:

So I guess I need to add my config to the conf set; I tried to insert this in environment.systemPackages but it didn’t work:

(let conf = {
    	   default_server_config = "my.custom.homeserver.com";
     }; in
    element-web)

(I’m guessing this doesn’t affect the import of the nix, so conf isn’t passed to element-web.nix)

If anyone knows how to do this, or can give me some pointers I’ll be grateful!

I tried adding the following line to environment.systemPackages in configuration.nix, it compile but it doesn’t work (the config file is not modified)

(import <nixpkgs/pkgs/applications/networking/instant-messengers/element/element-web.nix> {
        inherit lib stdenv fetchurl writeText jq;
        conf = {
            default_server_config = "my.custom.homeserver.com";  
        };
    })

I’m not sure why at this point, I mean conf should be passed to element.nix now right ?

Ok so I’m making some progress here:
In my previous post, I was defining and installing a custom element derivation however nginx was still refering to the old (uncustomized) derivation.

So I need to refer to this custom derivation and from what I’ve read mkDerivation seems the way to go : it install a derivation, and should produce an outPath that I can use in my nginx.nix

I did it this way :

{ stdenv, config, lib, pkgs, writeText, jq, fetchurl, ... }:

let element-web-custom = stdenv.mkDerivation (import <nixpkgs/pkgs/applications/networking/instant-messengers/element/element-web.nix> {
  inherit lib stdenv fetchurl writeText jq;
  conf = {
    default_server_config = "my.custom.homeserver.com";
  };
});
in
{
services.nginx = {
  enable = true;
  virtualHosts."my.custom.homeserver.com" = {
    locations = {
      "/element/" = {
        alias = "${element-web-custom}/";
        index = "index.html";
      };
    };
  };
};

It doesn’t compile, I get the following (slightly cryptic) error:

attribute 'stdenv' missing, at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:305:28

I found in the IRC log a solution to this problem: replace stdenv by pkgs.stdenv

However I must do this for every variable used by the derivation or else I get a attribute missing error.
My derivation now look like this

let element-web-custom = pkgs.stdenv.mkDerivation (import <nixpkgs/pkgs/applications/networking/instant-messengers/element/element-web.nix> {
	lib = pkgs.lib;	
	fetchurl = pkgs.fetchurl;
	writeText = pkgs.writeText;
	jq = pkgs.jq;
	stdenv = pkgs.stdenv;
	conf = {
        	default_server_config = "my.custom.homeserver.com";
	};
});

However I get this time another error :

cannot coerce a set to a string, at /nix/store/3ivi8sgbmddkmwzpaxazxw48rqpr16pm-nixos-21.11pre294109.fbfb79400a0/nixos/pkgs/stdenv/generic/make-derivation.nix:201:11

Maybe this is because I’m using unstable ?

I ended up just using a simple override and it works great:

nixpkgs.config.packageOverrides = pkgs: {
   element-web = pkgs.element-web.override {
      conf = {
         default_server_config = "my.custom.homeserver.com";			
      };
   };
};