2010-04-22 15:13:50 +00:00
|
|
|
# Felix server
|
2014-04-14 14:26:48 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2010-04-22 15:13:50 +00:00
|
|
|
|
2014-04-14 14:26:48 +00:00
|
|
|
with lib;
|
2010-04-22 15:13:50 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.felix;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2010-04-22 15:13:50 +00:00
|
|
|
options = {
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2010-04-22 15:13:50 +00:00
|
|
|
services.felix = {
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2024-04-13 12:54:15 +00:00
|
|
|
enable = mkEnableOption "the Apache Felix OSGi service";
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2010-04-22 15:13:50 +00:00
|
|
|
bundles = mkOption {
|
2016-01-17 18:34:55 +00:00
|
|
|
type = types.listOf types.package;
|
2010-04-22 15:13:50 +00:00
|
|
|
default = [ pkgs.felix_remoteshell ];
|
2021-10-03 16:06:03 +00:00
|
|
|
defaultText = literalExpression "[ pkgs.felix_remoteshell ]";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "List of bundles that should be activated on startup";
|
2010-04-22 15:13:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
2021-01-26 19:56:21 +00:00
|
|
|
type = types.str;
|
2010-04-22 15:13:50 +00:00
|
|
|
default = "osgi";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "User account under which Apache Felix runs.";
|
2011-09-14 18:20:50 +00:00
|
|
|
};
|
2010-04-22 15:13:50 +00:00
|
|
|
|
|
|
|
group = mkOption {
|
2021-01-26 19:56:21 +00:00
|
|
|
type = types.str;
|
2010-04-22 15:13:50 +00:00
|
|
|
default = "osgi";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Group account under which Apache Felix runs.";
|
2011-09-14 18:20:50 +00:00
|
|
|
};
|
|
|
|
|
2010-04-22 15:13:50 +00:00
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2010-04-22 15:13:50 +00:00
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2010-04-22 15:13:50 +00:00
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2019-09-14 17:51:29 +00:00
|
|
|
users.groups.osgi.gid = config.ids.gids.osgi;
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2019-09-14 17:51:29 +00:00
|
|
|
users.users.osgi =
|
|
|
|
{ uid = config.ids.uids.osgi;
|
2010-04-22 15:13:50 +00:00
|
|
|
description = "OSGi user";
|
|
|
|
home = "/homeless-shelter";
|
|
|
|
};
|
|
|
|
|
2016-01-06 06:50:18 +00:00
|
|
|
systemd.services.felix = {
|
|
|
|
description = "Felix server";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
preStart = ''
|
|
|
|
# Initialise felix instance on first startup
|
|
|
|
if [ ! -d /var/felix ]
|
|
|
|
then
|
|
|
|
# Symlink system files
|
|
|
|
|
|
|
|
mkdir -p /var/felix
|
|
|
|
chown ${cfg.user}:${cfg.group} /var/felix
|
|
|
|
|
|
|
|
for i in ${pkgs.felix}/*
|
|
|
|
do
|
|
|
|
if [ "$i" != "${pkgs.felix}/bundle" ]
|
|
|
|
then
|
|
|
|
ln -sfn $i /var/felix/$(basename $i)
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# Symlink bundles
|
|
|
|
mkdir -p /var/felix/bundle
|
|
|
|
chown ${cfg.user}:${cfg.group} /var/felix/bundle
|
|
|
|
|
|
|
|
for i in ${pkgs.felix}/bundle/* ${toString cfg.bundles}
|
|
|
|
do
|
|
|
|
if [ -f $i ]
|
|
|
|
then
|
|
|
|
ln -sfn $i /var/felix/bundle/$(basename $i)
|
|
|
|
elif [ -d $i ]
|
|
|
|
then
|
|
|
|
for j in $i/bundle/*
|
|
|
|
do
|
|
|
|
ln -sfn $j /var/felix/bundle/$(basename $j)
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
|
|
|
script = ''
|
|
|
|
cd /var/felix
|
|
|
|
${pkgs.su}/bin/su -s ${pkgs.bash}/bin/sh ${cfg.user} -c '${pkgs.jre}/bin/java -jar bin/felix.jar'
|
|
|
|
'';
|
|
|
|
};
|
2010-04-22 15:13:50 +00:00
|
|
|
};
|
|
|
|
}
|