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