Transfer values from webhook command arguments to environment variables

I’m trying to transfer some data via HTTP(s) into NixOS, that’s why I’m using webhook(pkgs.webhook) doing so. I configured webhook to listen for such request:

environment.etc."webhook.conf".text = ''
  [
    {
      "id": "setupConfigs",
      "execute-command": "${pkgs.setupConfigsScript}/bin/setupConfigsScript",
      "command-working-directory": "/tmp"
      "pass-arguments-to-command":
     [
        {
          "source": "header",
	      "name": "X-Domain"
        },
	    {
          "source": "header",
	      "name": "X-User"
	    },
	    {
          "source": "header",
	      "name": "X-Auth"
	    }
     ]
  }
 ]
  '';

That’s why, if I’ll send HTTP request, similar to this:

GET /hooks/setupConfigs HTTP/1.1
X-Domain: example.com
X-User: user
X-Auth: verySecurePassphrase

webhook will execute setupConfigsScript. It’s content defined using overlays:

nixpkgs.overlays = [(self: super: {

    setupConfigsScript = pkgs.writeScriptBin "setupConfigsScript" ''
      #!${pkgs.stdenv.shell}

      ${pkgs.wget}/bin/wget https://bitbucket.org/ilchub/serverdata/raw/b297b4026794c5420da97d7d06a393a5bf7e0819/configuration.nix
      ${pkgs.wget}/bin/wget https://bitbucket.org/ilchub/serverdata/raw/b297b4026794c5420da97d7d06a393a5bf7e0819/mailserver.nix
      ${pkgs.wget}/bin/wget https://bitbucket.org/ilchub/serverdata/raw/b297b4026794c5420da97d7d06a393a5bf7e0819/restic.nix

      sed -i '17s/.*/    fqdn = "'"$DOMAIN"'";/' mailserver.nix
      sed -i '18s/.*/    domains = [ "'"$DOMAIN"'" ];/' mailserver.nix
      sed -i '23s/.*/\t"'"$USER"'@'"$DOMAIN"'" = {/' mailserver.nix
      sed -i "24s,.*,\t\    hashedPassword = \"${PASSWORD}\";," mailserver.nix
      sed -i '33s/.*/\t\t"'"$DOMAIN"'"/' mailserver.nix
      sed -i '50s/.*/\t "admin@'"$DOMAIN"'" = "'"$USER"'@'"$DOMAIN"'";/' mailserver.nix
      sed -i '72s/.*/    email = "'"$USER"'@'"$DOMAIN"'";/' mailserver.nix

    '';
  })];

So, the thing, I need to do, is to assign data that I received from headers X-Domain, X-User, X-Auth to environment variables $USER, $DOMAIN, $PASSWORD.

Is there’s a way in webhook, or in NixOS declarative programming to do so?

Got the problem solution. As the ability of NixPkgs package manager to replace variables in .nix config files handled by usual preprocessor, you can’t modify variables dynamically. Variable names in .nix configs, being replaced with their values only once, on the configuration apply. That’s why, there’s no possibility to solve problem this way.