Something went wrong. Try again.
lol
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191# Run:# nix-instantiate --eval lib/services/test.nixlet lib = import ../.;
inherit (lib) mkOption types;
portable-lib = import ./lib.nix { inherit lib; };
configured = portable-lib.configure { serviceManagerPkgs = throw "do not use pkgs in this test"; extraRootModules = [ ]; extraRootSpecialArgs = { }; };
dummyPkg = name: derivation { system = "dummy"; name = name; builder = "/bin/false"; };
exampleConfig = { services = { service1 = { process = { argv = [ "/usr/bin/echo" # *giggles* "hello" ]; }; assertions = [ { assertion = false; message = "you can't enable this for that reason"; } ]; warnings = [ "The `foo' service is deprecated and will go away soon!" ]; }; service2 = { process = { # No meta.mainProgram, because it's supposedly an executable script _file_, # not a directory with a bin directory containing the main program. argv = [ (dummyPkg "cowsay.sh") "world" ]; }; }; service3 = { process = { argv = [ "/bin/false" ]; }; services.exclacow = { process = { argv = [ (lib.getExe ( dummyPkg "cowsay-ng" // { meta.mainProgram = "cowsay"; } )) "!" ]; }; assertions = [ { assertion = false; message = "you can't enable this for such reason"; } ]; warnings = [ "The `bar' service is deprecated and will go away soon!" ]; }; }; }; };
exampleEval = lib.evalModules { modules = [ { options.services = mkOption { type = types.attrsOf configured.serviceSubmodule; }; } exampleConfig ]; };
filterEval = config: lib.optionalAttrs (config ? process) { inherit (config) assertions warnings process; } // { services = lib.mapAttrs (k: filterEval) config.services; };
test = assert filterEval exampleEval.config == { services = { service1 = { process = { argv = [ "/usr/bin/echo" "hello" ]; }; services = { }; assertions = [ { assertion = false; message = "you can't enable this for that reason"; } ]; warnings = [ "The `foo' service is deprecated and will go away soon!" ]; }; service2 = { process = { argv = [ "${dummyPkg "cowsay.sh"}" "world" ]; }; services = { }; assertions = [ ]; warnings = [ ]; }; service3 = { process = { argv = [ "/bin/false" ]; }; services.exclacow = { process = { argv = [ "${dummyPkg "cowsay-ng"}/bin/cowsay" "!" ]; }; services = { }; assertions = [ { assertion = false; message = "you can't enable this for such reason"; } ]; warnings = [ "The `bar' service is deprecated and will go away soon!" ]; }; assertions = [ ]; warnings = [ ]; }; }; };
assert portable-lib.getWarnings [ "service1" ] exampleEval.config.services.service1 == [ "in service1: The `foo' service is deprecated and will go away soon!" ];
assert portable-lib.getAssertions [ "service1" ] exampleEval.config.services.service1 == [ { message = "in service1: you can't enable this for that reason"; assertion = false; } ];
assert portable-lib.getWarnings [ "service3" ] exampleEval.config.services.service3 == [ "in service3.services.exclacow: The `bar' service is deprecated and will go away soon!" ]; assert portable-lib.getAssertions [ "service3" ] exampleEval.config.services.service3 == [ { message = "in service3.services.exclacow: you can't enable this for such reason"; assertion = false; } ];
"ok";
intest