Nixos

Nix 值不是“有符號整數的屬性集”類型

  • March 23, 2019

我正在嘗試設置:

 networking.firewall.allowedTCPPortRanges = [ 80 81 5900];

但是我收到以下錯誤:

錯誤:選項值 networking.firewall.allowedTCPPortRanges.[definition 1-entry 1]' in /etc/nixos/configuration.nix’ 不是“有符號整數的屬性集”類型。

它似乎在這裡定義https://github.com/NixOS/nixos/blob/5f444a4d8d49a497bcfabe2544bda264c845653e/modules/services/networking/firewall.nix#L118為:

networking.firewall.allowedTCPPorts = mkOption {
 default = [];
 example = [ 22 80 ];
 type = types.listOf types.int;
 description =
   ''
     List of TCP ports on which incoming connections are
     accepted.
   '';
};

我使用的語法有什麼問題?

中有兩個名稱相似的屬性networking.firewall

  • 允許的 TCP 埠
  • allowedTCPPortRanges

前者是一個列表,因此 的值是[80 81 5900]可以接受的。但是,後者是一個定義如下的集合:

allowedTCPPortRanges = mkOption {
 type = types.listOf (types.attrsOf types.int);
 default = [ ];
 example = [ { from = 8999; to = 9003; } ];
 description =
   ''
     A range of TCP ports on which incoming connections are
     accepted.
   '';
};

引用自:https://unix.stackexchange.com/questions/508179