[Nix-dev] How to pass arguments to services?

Marc Weber marco-oweber at gmx.de
Tue Nov 27 05:51:37 CET 2007


I've writte a small nix service which looks roughly like this - you can
see the new service interface proposal in action here as well;

=============  =======================================================G
  args: with args;
  if (!config ? configuration) then throw "squid needs configuration attribute in its config"
  else
  with pkgs.lib_unstable; [ ( let 
    # is this ugly? It's very verbose. It ensures that more valid arguments are passed compared to
    # extraArgs = "-s -D -R"; ..
    opts = createArgs config [
      [ "syslog" "" (whenFlip "-s") ] 
      [ "icpPort" "" (x : "-u ${x}") ] 
      [ "createSwapDirectories" "" (whenFlip "-z") ]
      [ "disableInitialDNStests" "" (whenFlip "-D") ]
      [ "dontServeAnyRequestsUntilStoreIsRebuild" "" (whenFlip "-F") ]
      [ "dontSetREUSEADDRonPort" "" (whenFlip "-R") ]
      [ "doubleCheckSwapOnRebuild" "" (whenFlip "-S") ]
      [ "forceFullDebugging" "" (whenFlip "-X") ]
      [ "onlyReturnUDP_HITorUDP_MISS_NOFETCHduringFastReload" "" (whenFlip "-X") ]
      [ "extraArgs" "" id ]
      ]
    in; rec {
    name = "synergys";

    extraEtc = [ (autoGeneratedEtcFile { name = name + ".conf"; content = config.configuration; }) ];

    # TODO start only when X Server has started as well
    job = "
  description \"${name}\"

  start on network-interfaces/started and xserver/started
  stop on network-interfaces/stop or xserver/stop

  exec ${pkgs.squid}/sbin/synergys -N -f /etc/${name}.conf ${opts}
    ";
    
  } ) ]
=============  =======================================================

However after finishing adding the options I reallized that it's very
verbose.
So which way do you prefer?
  services = { 
    sequid = { dontServeAnyRequestsUntilStoreIsRebuild = true; };
  };
or
  services = { 
    # -F Don't serve any requests until store is rebuilt.
    extraArgs = "-F";
  };

The first one ensures that valid arguments are passed as long as the
value is correct.
But the second one seems much nicer to me because it's quicker to write,
if you need to you can add the comments decsribing the options
yourself or you can just run squick --help to get the list

I'm asking because niksnut has proposed splitting the tag in fetchcvs
into tag= or date= compared to tag="-D<date>" or tag="<tag>"

Do you agree that using extraArgs="" is the better solution (except
setting very common args such as port=8080) ?


How do you feel about the createArgs function?
1. arg: attribute name
2. arg: value to be used if configuration is not set
3. arg: function turning the value into a command line arg

Marc



More information about the nix-dev mailing list