1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let cfg = config.programs.cdemu;
6in {
7
8 options = {
9 programs.cdemu = {
10 enable = mkOption {
11 type = types.bool;
12 default = false;
13 description = lib.mdDoc ''
14 {command}`cdemu` for members of
15 {option}`programs.cdemu.group`.
16 '';
17 };
18 group = mkOption {
19 type = types.str;
20 default = "cdrom";
21 description = lib.mdDoc ''
22 Group that users must be in to use {command}`cdemu`.
23 '';
24 };
25 gui = mkOption {
26 type = types.bool;
27 default = true;
28 description = lib.mdDoc ''
29 Whether to install the {command}`cdemu` GUI (gCDEmu).
30 '';
31 };
32 image-analyzer = mkOption {
33 type = types.bool;
34 default = true;
35 description = lib.mdDoc ''
36 Whether to install the image analyzer.
37 '';
38 };
39 };
40 };
41
42 config = mkIf cfg.enable {
43
44 boot = {
45 extraModulePackages = [ config.boot.kernelPackages.vhba ];
46 kernelModules = [ "vhba" ];
47 };
48
49 services = {
50 udev.extraRules = ''
51 KERNEL=="vhba_ctl", MODE="0660", OWNER="root", GROUP="${cfg.group}"
52 '';
53 dbus.packages = [ pkgs.cdemu-daemon ];
54 };
55
56 users.groups.${config.programs.cdemu.group} = {};
57
58 # Systemd User service
59 # manually adapted from example in source package:
60 # https://sourceforge.net/p/cdemu/code/ci/master/tree/cdemu-daemon/service-example/cdemu-daemon.service
61 systemd.user.services.cdemu-daemon.description = "CDEmu daemon";
62 systemd.user.services.cdemu-daemon.serviceConfig = {
63 Type = "dbus";
64 BusName = "net.sf.cdemu.CDEmuDaemon";
65 ExecStart = "${pkgs.cdemu-daemon}/bin/cdemu-daemon --config-file \"%h/.config/cdemu-daemon\"";
66 Restart = "no";
67 };
68
69 environment.systemPackages =
70 [ pkgs.cdemu-daemon pkgs.cdemu-client ]
71 ++ optional cfg.gui pkgs.gcdemu
72 ++ optional cfg.image-analyzer pkgs.image-analyzer;
73 };
74
75}