Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HylaFAX+: init at 5.5.8 #19392

Closed
wants to merge 1 commit into from
Closed

HylaFAX+: init at 5.5.8 #19392

wants to merge 1 commit into from

Conversation

RamKromberg
Copy link
Contributor

@RamKromberg RamKromberg commented Oct 9, 2016

Motivation for this change

trees?

Things done

Receiving and sending faxes works.
Email redirection works.
Optional hfaxd client-server service works (mostly for LAN clients) and some local GUIs.

Configuration is somewhat manual\interactive due to the nature of the hardware:

    1. In configuration.nix: services.hylafaxp.enable = true;
    1. As root: faxsetup.
    1. Copy /var/spool/hylafax/etc/config and /var/spool/hylafax/etc/config.tty* to configuration.nix. e.g.
  services.hylafaxp = {
    enable = true;
    config = ''
      LogFacility:                daemon
      CountryCode:                011
      AreaCode:           01
      LongDistancePrefix: 1
      InternationalPrefix:        011
      DialStringRules:    etc/dialrules
      ServerTracing:              1
    '';
    devs = {
      ttyACM0 = ''
        CountryCode:        011
        AreaCode:       01
        FAXNumber:      12345678
        LongDistancePrefix: 1
        InternationalPrefix:    011
        DialStringRules:    etc/dialrules
        ServerTracing:      1
        SessionTracing:     0xFFF
        RecvFileMode:       0600
        LogFileMode:        0600
        DeviceMode:     0600
        RingsBeforeAnswer:  5
        SpeakerVolume:      off
        GettyArgs:      "-h %l dx_%s"
        LocalIdentifier:    companyOrHome
        TagLineFont:        etc/LiberationSans-25.pcf
        TagLineFormat:      "From %%l|%c|Page %%P of %%T"
        MaxRecvPages:       25
        #
        #
        # Modem-related stuff: should reflect modem command interface
        # and hardware connection/cabling (e.g. flow control).
        #
        ModemType:      Class1      # use this to supply a hint
        ModemRate:      19200       # rate for DCE-DTE communication
        ModemFlowControl:   rtscts      # default
        #
        ModemNoFlowCmd:     AT&K0       # setup no flow control
        ModemHardFlowCmd:   AT&K3       # setup hardware flow control
        ModemSoftFlowCmd:   AT&K4       # setup software flow control
        ModemSetupDTRCmd:   AT&D2       # setup so DTR drop resets modem
        ModemSetupDCDCmd:   AT&C1       # setup so DCD reflects carrier (or not)
        #
        ModemMfrQueryCmd:   !Rockwell
        ModemModelQueryCmd: !RC288DPi
        ModemRevQueryCmd:   ATI3        # product information
        #
        ModemDialCmd:       ATDT%s      # T for tone dialing
      '';
    };
  };
    1. nixos-rebuild switch.

This will produce persistent results between reboot & updates.

    1. (Optional) For email dispatching, it's enough to add:
    faxDispatch = ''
      SENDTO=myemail@mydomain.com;
      FILETYPE=pdf;
    '';

to services.hylafaxp and

  services.postfix = {
    enable = true;
    setSendmail = true;
  };
    1. (Optional) For the client-server protocol service, adding
    hfaxd = {
      enable = true;
      hosts = ''
        localhost
        127.0.0.1
      '';
    };

to services.hylafaxp should be sufficient for local access. See faxadduser for LAN clients and passwords.

I've only tested one soft-modem, but I wrote the module to support multiple modems.

Built and tested with nixos-rebuild switch -I nixpkgs=/home/user/nixpkgs.

  • Tested using sandboxing
    (nix.useSandbox on NixOS,
    or option build-use-sandbox in nix.conf
    on non-NixOS)
  • Built on platform(s)
    • NixOS
    • OS X
    • Linux
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

Note: HylaFAX vs. HylaFAX+ is 2012 vs. 2016.

@mention-bot
Copy link

@RamKromberg, thanks for your PR! By analyzing the history of the files in this pull request, we identified @joachifm, @edolstra and @offlinehacker to be potential reviewers.

${pkgs.ghostscript}/bin/gs -q -sDEVICE=tiffg3 -sFONTPATH="${pkgs.ghostscript}/share/ghostscript/fonts ${pkgs.ghostscript}/share/ghostscript/${pkgs.ghostscript.version}/Resource/Init ${pkgs.ghostscript}/share/ghostscript/${pkgs.ghostscript.version}/lib ${pkgs.ghostscript}/share/ghostscript/${pkgs.ghostscript.version}/Resource/Font ${pkgs.ghostscript}/share/ghostscript/fonts ${pkgs.ghostscript}/share/fonts/default/ghostscript ${pkgs.ghostscript}/share/fonts/default/Type1 ${pkgs.ghostscript}/share/fonts/default/TrueType" /var/spool/hylafax/bin/genfontmap.ps > /var/spool/hylafax/etc/Fontmap.HylaFAX 2>/dev/null
${concatStringsSep ";" (zipListsWith (a: b: "cp " + a + " /var/spool/hylafax/etc/config." + b) etcConfigDevs etcDevs)};
chmod 0755 /var/spool/hylafax
ls -A /var/spool/hylafax/ | grep -v -E 'recvq|log' | ${pkgs.gawk}/bin/awk '{print "/var/spool/hylafax/"$1}' | xargs chmod -R 0755
Copy link
Member

@Mic92 Mic92 Oct 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something with find would be cleaner:

find /var/spool/hylafax -type d \( -path recvq -o -path log \) -prune -o -print0 | xargs -0 chmod -R 0755

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shopt -s extglob nullglob
chmod 0755 /var/spool/hylafax/!(recvq|log)/**/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mic92 It's also good but I prefer it my way since it's easier to understand and maintain.

@joachifm I've considered this previously and decided I'd like to avoid bash-only features when possible.

Unless you guys can produce a solution that doesn't depend on regex matching (compute) or that walks only the one time (disk io), I'm sticking with the choice I find easiest to maintain.

{
${coreutils}/bin/echo -n "$* "
}
ttyPort()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mic92 it's the indentation faxsetup outputs. Same goes for hyla.conf, setup.cache and setup.modem.

I'd rather not touch them for diffing purposes if a future update changes them.

@RamKromberg
Copy link
Contributor Author

RamKromberg commented Oct 10, 2016

WIP: Taking a look at the email redirection.
email redirection works now. See first post for updated how-to.

@RamKromberg RamKromberg changed the title HylaFAX+: init at 5.5.8 [WIP] HylaFAX+: init at 5.5.8 Oct 10, 2016
@RamKromberg RamKromberg changed the title [WIP] HylaFAX+: init at 5.5.8 HylaFAX+: init at 5.5.8 Oct 10, 2016
services.hylafaxp.pagesizes = mkOption {
type = types.lines;
default = ''
# $Id: pagesizes.in 2 2005-11-11 21:32:03Z faxguy $
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file did not change since 2005. Do you think it is necessary to provide an option to change it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it's the paper size you send.
HylaFAX usually distributes with Letter as a default but I've taken the liberty to use ISO A4 instead since that's what I, and presumably, most of the NixOS user base, uses.

Anyhow, Americans\Japanese will want to change this.

@@ -6081,6 +6081,11 @@ in

hyenae = callPackage ../tools/networking/hyenae { };

hylafaxp = callPackage ../servers/hylafaxp {
pam = null;
openldap = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, if those dependencies are never used in hylafax, could we not drop them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since ldap and pam aren't useful to me I nulled them out.

But, a more enterprise-centric person might want to look at the module for hfaxd's inetd support that's likely to go with pam. Similarly, ldap...

${if (config.services.hylafaxp.config != "") then "cat ${_config} - > /var/spool/hylafax/etc/config" else ""}
${if (config.services.hylafaxp.hfaxd.hosts != "") then "cat ${_hosts_hfaxd} - > /var/spool/hylafax/etc/hosts.hfaxd" else ""}
${if (config.services.hylafaxp.faxDispatch != "") then "cat ${_FaxDispatch} - > /var/spool/hylafax/etc/FaxDispatch" else ""}
${pkgs.ghostscript}/bin/gs -q -sDEVICE=tiffg3 -sFONTPATH="${pkgs.ghostscript}/share/ghostscript/fonts ${pkgs.ghostscript}/share/ghostscript/${pkgs.ghostscript.version}/Resource/Init ${pkgs.ghostscript}/share/ghostscript/${pkgs.ghostscript.version}/lib ${pkgs.ghostscript}/share/ghostscript/${pkgs.ghostscript.version}/Resource/Font ${pkgs.ghostscript}/share/ghostscript/fonts ${pkgs.ghostscript}/share/fonts/default/ghostscript ${pkgs.ghostscript}/share/fonts/default/Type1 ${pkgs.ghostscript}/share/fonts/default/TrueType" /var/spool/hylafax/bin/genfontmap.ps > /var/spool/hylafax/etc/Fontmap.HylaFAX 2>/dev/null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can those files above replaced by writeText and symlinks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need ghostscript to produce font names and paths depending on what's available on the system and the specific ghostscript package version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mic92 maybe replacing FONTPATH with a nix variable will help a little?

assert dev != "";
nameValuePair "hylafaxp-faxgetty-${dev}" {
description = "faxgetty ${dev}: HylaFAX+ front-door process";
after = optionals (dev!="dummy") [ "hylafaxp-setup.service" "hylafaxp-faxq.service" "${dev}.device" ];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mic92 This one sucks but I'm not sure how to clean it up.

I'd like to condition this entire let..in.. construct by config.services.hylafaxp.devs and move the error message** to the setupscript.

It's quite ugly and convoluted in an already complex structure but I don't know how to do the condition so I ended up recycling the unit to display the error so the unit won't be a total waste.

Similarly, there are also a few setupScript config.services.hylafaxp.devs if statements I'm not particularly happy about.

** letting the user know they should run faxsetup and update config.services.hylafaxp.devs accordingly

@RamKromberg
Copy link
Contributor Author

@Mic92 I've cleaned up a few problem spots including the FONTPATH you've requested. It's still being produced by ghostscript since we still need to account for different fonts and changes between ghostscript versions... But it's nicer looking :)

@lethalman Thanks for explaining how to condition the let...in... statement.

@Mic92
Copy link
Member

Mic92 commented Oct 24, 2016

@RamKromberg
I have refactored the module:
Mic92@babb767

@7c6f434c
Copy link
Member

7c6f434c commented Nov 4, 2017

@Mic92 Have you ever pushed the refactored version to mainline Nixpkgs?

@Mic92
Copy link
Member

Mic92 commented Nov 8, 2017

@7c6f434c no

@7c6f434c
Copy link
Member

7c6f434c commented Nov 8, 2017

@Mic92 any reason not to push it (and close this PR afterwards)?

@RamKromberg
Copy link
Contributor Author

@7c6f434c If memory serves, it was suggested the package should probably be rewritten (and updated*) to run in a container since it handles its own ring0->ring3 de-escalation. I think I tried doing it myself but run into some issues... Well, I was pretty satisfied with the C code security-wise and was running it for a few months without any major problems so I just never got around to doing it.

Eventually, it stalled as I became "distracted" with unrelated low-level work and generally gone inactive with NixOS development.

Seeing how I moved my fax-modem to a RasPi and been running Debian there... Well, it would be a shame to see so much work going to waste but I'll understand if you'd want to close the pull request. Though I wish it could be archived or something in case someone ends up wanting to work on it or something.

@7c6f434c
Copy link
Member

@RamKromberg I think the refactored version by @Mic92 addresses some of the discussion. I asked about closing the PR after merging whatever further work on top of this PR has been done.

In general, closed PRs are visible in a separate tab and are displayed in search; availability of the branch actually depends on whether you keep it in your fork.

@Yarny0 Yarny0 mentioned this pull request Aug 5, 2018
9 tasks
@c0bw3b
Copy link
Contributor

c0bw3b commented Oct 8, 2018

Closing this since #44496 was merged and now provides fax-sending from NixOS.

Thanks @RamKromberg for laying the groundwork on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants