2010-04-22 17:13:50 +02:00
|
|
|
# Felix server
|
2014-04-14 16:26:48 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2010-04-22 17:13:50 +02:00
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
with lib;
|
2010-04-22 17:13:50 +02:00
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.felix;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2010-04-22 17:13:50 +02:00
|
|
|
options = {
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2010-04-22 17:13:50 +02:00
|
|
|
services.felix = {
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2020-04-20 20:05:26 +02:00
|
|
|
enable = mkEnableOption "the Apache Felix OSGi service";
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2010-04-22 17:13:50 +02:00
|
|
|
bundles = mkOption {
|
2016-01-17 19:34:55 +01:00
|
|
|
type = types.listOf types.package;
|
2010-04-22 17:13:50 +02:00
|
|
|
default = [ pkgs.felix_remoteshell ];
|
2016-01-17 19:34:55 +01:00
|
|
|
defaultText = "[ pkgs.felix_remoteshell ]";
|
2010-04-22 17:13:50 +02:00
|
|
|
description = "List of bundles that should be activated on startup";
|
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
2021-01-26 20:56:21 +01:00
|
|
|
type = types.str;
|
2010-04-22 17:13:50 +02:00
|
|
|
default = "osgi";
|
|
|
|
description = "User account under which Apache Felix runs.";
|
2011-09-14 20:20:50 +02:00
|
|
|
};
|
2010-04-22 17:13:50 +02:00
|
|
|
|
|
|
|
group = mkOption {
|
2021-01-26 20:56:21 +01:00
|
|
|
type = types.str;
|
2010-04-22 17:13:50 +02:00
|
|
|
default = "osgi";
|
|
|
|
description = "Group account under which Apache Felix runs.";
|
2011-09-14 20:20:50 +02:00
|
|
|
};
|
|
|
|
|
2010-04-22 17:13:50 +02:00
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2010-04-22 17:13:50 +02:00
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2010-04-22 17:13:50 +02:00
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2019-09-14 19:51:29 +02:00
|
|
|
users.groups.osgi.gid = config.ids.gids.osgi;
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2019-09-14 19:51:29 +02:00
|
|
|
users.users.osgi =
|
|
|
|
{ uid = config.ids.uids.osgi;
|
2010-04-22 17:13:50 +02:00
|
|
|
description = "OSGi user";
|
|
|
|
home = "/homeless-shelter";
|
|
|
|
};
|
|
|
|
|
2016-01-06 07:50:18 +01: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 17:13:50 +02:00
|
|
|
};
|
|
|
|
}
|