Skip to content

Commit 01b0a5d

Browse files
committed
better mkService
1 parent 3aca9a5 commit 01b0a5d

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

nix/misc.nix

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ let
22
repo = builtins.toString ./..;
33
in
44
with (import ./project.nix {}); rec {
5+
inherit pkgs;
56
pkgBin = pkg: "${pkgs.${pkg}}/bin/${pkg}";
67
nix-bundle = pkgs.nix-bundle.overrideAttrs (attrs: {
78
buildInputs =
@@ -62,7 +63,7 @@ in
6263
};
6364
mkService = {
6465
srv,
65-
usr ? null,
66+
opts ? {},
6667
mkExe,
6768
}: {
6869
lib,
@@ -75,12 +76,17 @@ in
7576
];
7677

7778
options = {
78-
services."${srv}" = {
79-
enable = mkOption {
80-
default = false;
81-
type = types.bool;
82-
};
83-
};
79+
services."${srv}" =
80+
{
81+
enable = mkOption {
82+
default = false;
83+
type = types.bool;
84+
};
85+
runAsUser = mkOption {
86+
type = types.nullOr types.str;
87+
};
88+
}
89+
// opts;
8490
};
8591

8692
config = mkIf config.services."${srv}".enable {
@@ -89,7 +95,9 @@ in
8995
wantedBy = ["default.target"];
9096
script = "PATH=$PATH:${pkgs.busybox}/bin ${mkExe config}";
9197
serviceConfig = {
92-
User =
98+
User = let
99+
usr = config.services."${srv}".runAsUser;
100+
in
93101
if usr == null
94102
then config.services.functora.userName
95103
else usr;

0 commit comments

Comments
 (0)