at 23.11-pre 2.4 kB view raw
1# Felix server 2{ config, lib, pkgs, ... }: 3 4with lib; 5 6let 7 8 cfg = config.services.felix; 9 10in 11 12{ 13 14 ###### interface 15 16 options = { 17 18 services.felix = { 19 20 enable = mkEnableOption (lib.mdDoc "the Apache Felix OSGi service"); 21 22 bundles = mkOption { 23 type = types.listOf types.package; 24 default = [ pkgs.felix_remoteshell ]; 25 defaultText = literalExpression "[ pkgs.felix_remoteshell ]"; 26 description = lib.mdDoc "List of bundles that should be activated on startup"; 27 }; 28 29 user = mkOption { 30 type = types.str; 31 default = "osgi"; 32 description = lib.mdDoc "User account under which Apache Felix runs."; 33 }; 34 35 group = mkOption { 36 type = types.str; 37 default = "osgi"; 38 description = lib.mdDoc "Group account under which Apache Felix runs."; 39 }; 40 41 }; 42 43 }; 44 45 46 ###### implementation 47 48 config = mkIf cfg.enable { 49 users.groups.osgi.gid = config.ids.gids.osgi; 50 51 users.users.osgi = 52 { uid = config.ids.uids.osgi; 53 description = "OSGi user"; 54 home = "/homeless-shelter"; 55 }; 56 57 systemd.services.felix = { 58 description = "Felix server"; 59 wantedBy = [ "multi-user.target" ]; 60 61 preStart = '' 62 # Initialise felix instance on first startup 63 if [ ! -d /var/felix ] 64 then 65 # Symlink system files 66 67 mkdir -p /var/felix 68 chown ${cfg.user}:${cfg.group} /var/felix 69 70 for i in ${pkgs.felix}/* 71 do 72 if [ "$i" != "${pkgs.felix}/bundle" ] 73 then 74 ln -sfn $i /var/felix/$(basename $i) 75 fi 76 done 77 78 # Symlink bundles 79 mkdir -p /var/felix/bundle 80 chown ${cfg.user}:${cfg.group} /var/felix/bundle 81 82 for i in ${pkgs.felix}/bundle/* ${toString cfg.bundles} 83 do 84 if [ -f $i ] 85 then 86 ln -sfn $i /var/felix/bundle/$(basename $i) 87 elif [ -d $i ] 88 then 89 for j in $i/bundle/* 90 do 91 ln -sfn $j /var/felix/bundle/$(basename $j) 92 done 93 fi 94 done 95 fi 96 ''; 97 98 script = '' 99 cd /var/felix 100 ${pkgs.su}/bin/su -s ${pkgs.bash}/bin/sh ${cfg.user} -c '${pkgs.jre}/bin/java -jar bin/felix.jar' 101 ''; 102 }; 103 }; 104}