Loading nixos/doc/manual/development/modular-services.md +1 −1 Original line number Diff line number Diff line Loading @@ -48,7 +48,7 @@ It is possible to write service modules that are portable. This is done by eithe { config, options, lib, ... }: { _class = "service"; config = { process.executable = "${lib.getExe config.foo.program}"; process.argv = [ (lib.getExe config.foo.program) ]; } // lib.optionalAttrs (options?systemd) { # ... systemd-specific definitions ... }; Loading nixos/modules/system/service/portable/service.nix +6 −21 Original line number Diff line number Diff line Loading @@ -7,18 +7,6 @@ let inherit (lib) mkOption types; pathOrStr = types.coercedTo types.path (x: "${x}") types.str; program = types.coercedTo ( types.package // { # require mainProgram for this conversion check = v: v.type or null == "derivation" && v ? meta.mainProgram; } ) lib.getExe pathOrStr // { description = "main program, path or command"; descriptionClass = "conjunction"; }; in { # https://nixos.org/manual/nixos/unstable/#modular-services Loading @@ -45,18 +33,15 @@ in visible = "shallow"; }; process = { executable = mkOption { type = program; description = '' The path to the executable that will be run when the service is started. ''; }; args = lib.mkOption { argv = lib.mkOption { type = types.listOf pathOrStr; example = lib.literalExpression ''[ (lib.getExe config.package) "--nobackground" ]''; description = '' Arguments to pass to the `executable`. Command filename and arguments for starting this service. This is a raw command-line that should not contain any shell escaping. If expansion of environmental variables is required then use a shell script or `importas` from `pkgs.execline`. ''; default = [ ]; }; }; }; Loading nixos/modules/system/service/portable/test.nix +31 −18 Original line number Diff line number Diff line Loading @@ -20,8 +20,10 @@ let services = { service1 = { process = { executable = "/usr/bin/echo"; # *giggles* args = [ "hello" ]; argv = [ "/usr/bin/echo" # *giggles* "hello" ]; }; assertions = [ { Loading @@ -37,21 +39,27 @@ let process = { # No meta.mainProgram, because it's supposedly an executable script _file_, # not a directory with a bin directory containing the main program. executable = dummyPkg "cowsay.sh"; args = [ "world" ]; argv = [ (dummyPkg "cowsay.sh") "world" ]; }; }; service3 = { process = { executable = "/bin/false"; args = [ ]; argv = [ "/bin/false" ]; }; services.exclacow = { process = { executable = dummyPkg "cowsay-ng" // { argv = [ (lib.getExe ( dummyPkg "cowsay-ng" // { meta.mainProgram = "cowsay"; }; args = [ "!" ]; } )) "!" ]; }; assertions = [ { Loading Loading @@ -91,8 +99,10 @@ let services = { service1 = { process = { executable = "/usr/bin/echo"; args = [ "hello" ]; argv = [ "/usr/bin/echo" "hello" ]; }; services = { }; assertions = [ Loading @@ -107,8 +117,10 @@ let }; service2 = { process = { executable = "${dummyPkg "cowsay.sh"}"; args = [ "world" ]; argv = [ "${dummyPkg "cowsay.sh"}" "world" ]; }; services = { }; assertions = [ ]; Loading @@ -116,13 +128,14 @@ let }; service3 = { process = { executable = "/bin/false"; args = [ ]; argv = [ "/bin/false" ]; }; services.exclacow = { process = { executable = "${dummyPkg "cowsay-ng"}/bin/cowsay"; args = [ "!" ]; argv = [ "${dummyPkg "cowsay-ng"}/bin/cowsay" "!" ]; }; services = { }; assertions = [ Loading nixos/modules/system/service/systemd/service.nix +1 −3 Original line number Diff line number Diff line Loading @@ -69,9 +69,7 @@ in Restart = lib.mkDefault "always"; RestartSec = lib.mkDefault "5"; ExecStart = [ (systemdPackage.functions.escapeSystemdExecArgs ( [ config.process.executable ] ++ config.process.args )) (systemdPackage.functions.escapeSystemdExecArgs config.process.argv) ]; }; }; Loading nixos/modules/system/service/systemd/test.nix +9 −6 Original line number Diff line number Diff line Loading @@ -11,14 +11,17 @@ let machine = evalSystem ( { lib, ... }: let hello' = lib.getExe hello; in { # Test input system.services.foo = { process = { executable = hello; args = [ argv = [ hello' "--greeting" "hoi" ]; Loading @@ -26,8 +29,8 @@ let }; system.services.bar = { process = { executable = hello; args = [ argv = [ hello' "--greeting" "hoi" ]; Loading @@ -37,8 +40,8 @@ let }; services.db = { process = { executable = hello; args = [ argv = [ hello' "--greeting" "Hi, I'm a database, would you believe it" ]; Loading Loading
nixos/doc/manual/development/modular-services.md +1 −1 Original line number Diff line number Diff line Loading @@ -48,7 +48,7 @@ It is possible to write service modules that are portable. This is done by eithe { config, options, lib, ... }: { _class = "service"; config = { process.executable = "${lib.getExe config.foo.program}"; process.argv = [ (lib.getExe config.foo.program) ]; } // lib.optionalAttrs (options?systemd) { # ... systemd-specific definitions ... }; Loading
nixos/modules/system/service/portable/service.nix +6 −21 Original line number Diff line number Diff line Loading @@ -7,18 +7,6 @@ let inherit (lib) mkOption types; pathOrStr = types.coercedTo types.path (x: "${x}") types.str; program = types.coercedTo ( types.package // { # require mainProgram for this conversion check = v: v.type or null == "derivation" && v ? meta.mainProgram; } ) lib.getExe pathOrStr // { description = "main program, path or command"; descriptionClass = "conjunction"; }; in { # https://nixos.org/manual/nixos/unstable/#modular-services Loading @@ -45,18 +33,15 @@ in visible = "shallow"; }; process = { executable = mkOption { type = program; description = '' The path to the executable that will be run when the service is started. ''; }; args = lib.mkOption { argv = lib.mkOption { type = types.listOf pathOrStr; example = lib.literalExpression ''[ (lib.getExe config.package) "--nobackground" ]''; description = '' Arguments to pass to the `executable`. Command filename and arguments for starting this service. This is a raw command-line that should not contain any shell escaping. If expansion of environmental variables is required then use a shell script or `importas` from `pkgs.execline`. ''; default = [ ]; }; }; }; Loading
nixos/modules/system/service/portable/test.nix +31 −18 Original line number Diff line number Diff line Loading @@ -20,8 +20,10 @@ let services = { service1 = { process = { executable = "/usr/bin/echo"; # *giggles* args = [ "hello" ]; argv = [ "/usr/bin/echo" # *giggles* "hello" ]; }; assertions = [ { Loading @@ -37,21 +39,27 @@ let process = { # No meta.mainProgram, because it's supposedly an executable script _file_, # not a directory with a bin directory containing the main program. executable = dummyPkg "cowsay.sh"; args = [ "world" ]; argv = [ (dummyPkg "cowsay.sh") "world" ]; }; }; service3 = { process = { executable = "/bin/false"; args = [ ]; argv = [ "/bin/false" ]; }; services.exclacow = { process = { executable = dummyPkg "cowsay-ng" // { argv = [ (lib.getExe ( dummyPkg "cowsay-ng" // { meta.mainProgram = "cowsay"; }; args = [ "!" ]; } )) "!" ]; }; assertions = [ { Loading Loading @@ -91,8 +99,10 @@ let services = { service1 = { process = { executable = "/usr/bin/echo"; args = [ "hello" ]; argv = [ "/usr/bin/echo" "hello" ]; }; services = { }; assertions = [ Loading @@ -107,8 +117,10 @@ let }; service2 = { process = { executable = "${dummyPkg "cowsay.sh"}"; args = [ "world" ]; argv = [ "${dummyPkg "cowsay.sh"}" "world" ]; }; services = { }; assertions = [ ]; Loading @@ -116,13 +128,14 @@ let }; service3 = { process = { executable = "/bin/false"; args = [ ]; argv = [ "/bin/false" ]; }; services.exclacow = { process = { executable = "${dummyPkg "cowsay-ng"}/bin/cowsay"; args = [ "!" ]; argv = [ "${dummyPkg "cowsay-ng"}/bin/cowsay" "!" ]; }; services = { }; assertions = [ Loading
nixos/modules/system/service/systemd/service.nix +1 −3 Original line number Diff line number Diff line Loading @@ -69,9 +69,7 @@ in Restart = lib.mkDefault "always"; RestartSec = lib.mkDefault "5"; ExecStart = [ (systemdPackage.functions.escapeSystemdExecArgs ( [ config.process.executable ] ++ config.process.args )) (systemdPackage.functions.escapeSystemdExecArgs config.process.argv) ]; }; }; Loading
nixos/modules/system/service/systemd/test.nix +9 −6 Original line number Diff line number Diff line Loading @@ -11,14 +11,17 @@ let machine = evalSystem ( { lib, ... }: let hello' = lib.getExe hello; in { # Test input system.services.foo = { process = { executable = hello; args = [ argv = [ hello' "--greeting" "hoi" ]; Loading @@ -26,8 +29,8 @@ let }; system.services.bar = { process = { executable = hello; args = [ argv = [ hello' "--greeting" "hoi" ]; Loading @@ -37,8 +40,8 @@ let }; services.db = { process = { executable = hello; args = [ argv = [ hello' "--greeting" "Hi, I'm a database, would you believe it" ]; Loading