2017-02-10 70 views
0

問題

我一直工作在一個Web服務器的抽象,但使用lib.mapAttrsToList總是返回一個無限遞歸錯誤:lib.mapAttrsToList和無限遞歸

# nixos-rebuild build 
building Nix... 
error: infinite recursion encountered, at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/modules.nix:59:71 
(use ‘--show-trace’ to show detailed location information) 
error: infinite recursion encountered, at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/modules.nix:59:71 
(use ‘--show-trace’ to show detailed location information) 
building the system configuration... 
error: infinite recursion encountered, at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/modules.nix:59:71 
(use ‘--show-trace’ to show detailed location information) 

我已經添加的所有其他版本代碼,沒有返回infinite recursion錯誤,這是我不明白。

所以這裏是我的代碼:

configuration.nix

imports = 
    [ # Include the results of the hardware scan. 
     ./hardware-configuration.nix 
     /home/joachim/Desktop/projects/nixcloud/nixcloud-webservices-abstraction/nextcloud.nix 
    ]; 

    services.nextcloud = { 
    enable=true; 
    networks = { 
     net1 = { name = "foo"; }; 
     net2 = { name = "bar"; }; 
    }; 

nixcloud.nix

{ config, options, lib, pkgs, ... }: 

with lib; 

let 
    mergeListToAttrs = fold (c: el: recursiveUpdate el c) {}; 
    cfg = config.services.nextcloud; 
in 

{ 
options = { 
    services.nextcloud = { 
     networks = mkOption { 
     default = {}; 
#   type = types.loaOf types.submodule; 
     options = { 
      name = mkOption { 
      default = ""; 
      type = types.str; 
      }; 
     }; 
     }; 
     enable = mkOption { 
     default = true; 
     type=types.bool; 
     description = '' 
      Whether to enable the cntlm, which start a local proxy. 
     ''; 
     }; 
    }; 
    }; 

# example 1 - works 
# config = { 
#  systemd.services = { 
#  bar = { 
#   wantedBy  = [ "multi-user.target" ]; 
#   after   = [ "" ]; 
#  }; 
#  foo = { 
#   wantedBy  = [ "multi-user.target" ]; 
#   after   = [ "" ]; 
#  }; 
#  }; 
# }; 



# example 2 - works 
# config = { 
#  systemd.services = lib.flip lib.mapAttrs cfg.networks (network: data: 
#  { 
#   wantedBy  = [ "multi-user.target" ]; 
#   after   = [ "network.target" ]; 
#   serviceConfig = { 
#    ExecStart = ""; 
#    ExecReload = ""; 
#    Restart = "always"; 
#    RestartSec = "10s"; 
#    StartLimitInterval = "1min"; 
#   }; 
#  } 
# ); 
# }; 


# example 3 - works  
# config = { 
#  systemd.services = flip mapAttrs' cfg.networks (network: data: nameValuePair 
#  ("tinc.${network}") 
#  ({ 
#    wantedBy  = [ "multi-user.target" ]; 
#    after   = [ "network.target" ]; 
#    serviceConfig = { 
#    ExecStart = ""; 
#    ExecReload = ""; 
#    Restart = "always"; 
#    RestartSec = "10s"; 
#    StartLimitInterval = "1min"; 
#    }; 
#   }) 
#  ); 
# }; 

# example 4 - works  
#  config = 
#  mergeListToAttrs (
#   [ 
#   { systemd.services.a = { 
#    wantedBy  = [ "multi-user.target" ]; 
#    after   = [ "network.target" ]; 
#    serviceConfig = { 
#    ExecStart = ""; 
#    ExecReload = ""; 
#    Restart = "always"; 
#    RestartSec = "10s"; 
#    StartLimitInterval = "1min"; 
#    }; 
#   }; 
#   } 
#   { 
#   systemd.services.b = { 
#    wantedBy  = [ "multi-user.target" ]; 
#    after   = [ "network.target" ]; 
#    serviceConfig = { 
#    ExecStart = ""; 
#    ExecReload = ""; 
#    Restart = "always"; 
#    RestartSec = "10s"; 
#    StartLimitInterval = "1min"; 
#    }; 
#   }; 
#   } 
#   ]); 

# example 5 - fails! 
# XXXXXXXX the failing function XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 
    config = 
     mergeListToAttrs (
     lib.flip lib.mapAttrsToList cfg.networks (wsName: wsConfig: { 
      systemd.services.${wsName} = { 
      wantedBy  = [ "multi-user.target" ]; 
      after   = [ "network.target" ]; 
      serviceConfig = { 
       ExecStart = ""; 
       ExecReload = ""; 
       Restart = "always"; 
       RestartSec = "10s"; 
       StartLimitInterval = "1min"; 
      }; 
      }; 
     }) 
    ); 

} 
+1

據我可以看到唯一的區別是'mergeListToAttrs'函數;如果您替換它會發生什麼,例如由'頭'? – Profpatsch

回答

0

根據aszlig問題是example 5變化,並從配置在讀同時。解決方法是不這樣做,但要麼使用硬編碼的'右側值',如example 4或將systemd.services =指定爲右側值。