Improve nixos service so it uses a dynamic user
This commit is contained in:
parent
a0bfd2bcca
commit
2a51a33f9b
@ -7,26 +7,19 @@ in
|
|||||||
{
|
{
|
||||||
options.services.picture-frame-server = {
|
options.services.picture-frame-server = {
|
||||||
enable = lib.mkEnableOption "enable picture-frame-server";
|
enable = lib.mkEnableOption "enable picture-frame-server";
|
||||||
user = lib.mkOption {
|
|
||||||
type = lib.types.str;
|
|
||||||
default = "picture-frame-server";
|
|
||||||
description = ''
|
|
||||||
The user the server should run as
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
group = lib.mkOption {
|
|
||||||
type = lib.types.str;
|
|
||||||
default = "picture-frame-server";
|
|
||||||
description = ''
|
|
||||||
The group the server should run as
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
imgDir = lib.mkOption {
|
imgDir = lib.mkOption {
|
||||||
type = lib.types.str;
|
type = lib.types.str;
|
||||||
description = ''
|
description = ''
|
||||||
Directory of images that the server will serve
|
Directory of images that the server will serve
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
imgDirGroup = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
description = ''
|
||||||
|
The group the server will run as a member of.
|
||||||
|
So the server can have read access to `imgDir`.
|
||||||
|
'';
|
||||||
|
};
|
||||||
port = lib.mkOption {
|
port = lib.mkOption {
|
||||||
type = lib.types.int;
|
type = lib.types.int;
|
||||||
default = 18450;
|
default = 18450;
|
||||||
@ -38,18 +31,17 @@ in
|
|||||||
|
|
||||||
config = lib.mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
nixpkgs.overlays = [ overlay ];
|
nixpkgs.overlays = [ overlay ];
|
||||||
users.users.${cfg.user} = {
|
|
||||||
isSystemUser = true;
|
|
||||||
group = cfg.group;
|
|
||||||
};
|
|
||||||
users.groups.${cfg.group} = { };
|
|
||||||
systemd.services.picture-frame-server = {
|
systemd.services.picture-frame-server = {
|
||||||
enable = true;
|
enable = true;
|
||||||
after = [ "network.target" ];
|
after = [ "network.target" ];
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
serviceConfig.ExecStart = "${pkgs.picture-frame.server}/bin/server ${toString cfg.port} ${cfg.imgDir}";
|
serviceConfig = {
|
||||||
serviceConfig.User = cfg.user;
|
ExecStart = "${pkgs.picture-frame.server}/bin/server ${toString cfg.port} ${cfg.imgDir}";
|
||||||
serviceConfig.Group = cfg.group;
|
DynamicUser = true;
|
||||||
|
PrivateTmp = true;
|
||||||
|
User = "picture-frame-server";
|
||||||
|
SupplementaryGroups = [ cfg.imgDirGroup ];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user