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