[SOLVED] Error: syntax error, unexpected '=', expecting end of file

I’m trying to configure a simple Caddy server using a very simple module. The error message in the SSH console is as follows:


       error: syntax error, unexpected '=', expecting end of file

       at /etc/nixos/caddy.nix:1:16:

            1| services.caddy = {
             |                ^
            2|   enable = true;
building the system configuration...
error:
       … while evaluating the attribute 'config.system.build.toplevel'

         at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:322:9:

For the following caddy.nix:

services.caddy = {   
  enable = true;
  email = admin@mydomain.net;
  config =
    ''
      mydomain.net {
        root /var/www/
      }
    '';
}

Your email is not quoted.

2 Likes

Do you have a ; at the end of your statement?

It should be

services.caddy = {   
  enable = true;
  email = "admin@mydomain.net";
  config =
    ''
      mydomain.net {
        root /var/www/
      }
    '';
};
1 Like

Also, if this is erroring on line 1 that means you didn’t put it in an attrset.
The file should be

{
  services.caddy = {   
    enable = true;
    email = "admin@mydomain.net";
    config =
      ''
        mydomain.net {
          root /var/www/
        }
      '';
  };
}

i.e. you need curly-braces at the top-level, as every module should be an attrset or a function that returns one

2 Likes

@waffle8946 Yes, that worked!

Thanks for the help!