simonmichael / hledger

Robust, fast, intuitive plain text accounting tool with CLI, TUI and web interfaces.
https://hledger.org
GNU General Public License v3.0
3.01k stars 321 forks source link

hledger-ui: hfsevent broken on MacOS/Nix/Stack #613

Closed kalhauge closed 7 years ago

kalhauge commented 7 years ago

On MacOS, running Nix and Stack, hledger-ui does not work:

$ stack build hledger-ui
hledger-1.3.99: build (lib + exe)
hfsevents-0.1.6: configure
hfsevents-0.1.6: build
vty-5.16: configure
vty-5.16: build
vty-5.16: copy/register
Progress: 3/6
--  While building package hfsevents-0.1.6 using:
     $HOME/.stack/setup-exe-cache/x86_64-osx-nix/Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 --builddir=.stack-work/dist/x86_64-osx-nix/Cabal-1.24.2.0 build --ghc-options " -ddump-hi -ddump-to-file"
    Process exited with code: ExitFailure 1
    Logs have been written to: hledger/.stack-work/logs/hfsevents-0.1.6.log

    Configuring hfsevents-0.1.6...
    Building hfsevents-0.1.6...
    Preprocessing library hfsevents-0.1.6...
    [1 of 1] Compiling System.OSX.FSEvents ( System/OSX/FSEvents.hs, .stack-work/dist/x86_64-osx-nix/Cabal-1.24.2.0/build/System/OSX/FSEvents.o )

    /private/var/folders/gh/j563xb_s475dmjn_5n60bwnw0000gn/T/stack73141/hfsevents-0.1.6/cbits/c_fsevents.m:1:10: error:
         fatal error: 'CoreServices/CoreServices.h' file not found
    #include <CoreServices/CoreServices.h>
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    1 error generated.
    `cc' failed in phase `C Compiler'. (Exit code: 1)

Some efforts have been done on the internet to fix this:

https://github.com/commercialhaskell/stack/issues/1698

But neither adding darwin.apple_sdk.frameworks.CoreServices and darwin.apple_sdk.frameworks.Cocoa or adding darwin.xcode to nix.packages in ~/.stack/config.yaml, works.

I know that this is a problem with hfsevent, Nix and Stack, and not with hledger-ui, but I thought I would add it here regardless.

Versions:

$ nix-env --version
nix-env (Nix) 1.11.15

$ stack --version
Version 1.5.1, Git revision 600c1f01435a10d127938709556c1682ecfd694e (4861 commits) x86_64 hpack-0.17.1

MacOS Sierra: 10.12.6
simonmichael commented 7 years ago

@kalhauge, I don't see this problem on macos 10.12.5. stack is 1.5.1 and config.yaml is default. hfsevents-0.1.6 is installed. I don't use Nix. In the past I have probably run the "install xcode command line tools" step sometimes recommended. Also I may have installed things with homebrew.

simonmichael commented 7 years ago

Also:

~$ locate CoreServices.h
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreServices.framework/Versions/A/Headers/CoreServices.h
/System/Library/Frameworks/CoreServices.framework/Versions/A/Headers/CoreServices.h
kalhauge commented 7 years ago

@simonmichael, nix is a different beast. It tries to keep its build paths pure to the point where it's almost running small virtual machines for each build. This gives some complications with libraries that use OS features. It is especially bad with use of MacOS core libraries.

simonmichael commented 7 years ago

Ah I see, a nix-on-mac problem. I've noted it by the nix instructions on the download page.

You said "Maybe splitting hledger-lib and the others into self-contained repositories might reduce building overhead." - you know you can build specific packages, right ? Eg stack build hledger hledger-ui, or make ghcid.

kalhauge commented 7 years ago

It's mostly for developing reasons having different libraries in different repositories makes them easier to develop on using Spacemacs and other tools as they will just run stack build or cabal build.

simonmichael commented 7 years ago

hledger-ui depends on fsnotify for the --watch feature, and that depends on hfsevents.

I don't want to complicate packaging and testing by making this a conditional build feature. I noted this issue next to the Nix instructions on the download page, hopefully that is enough on our side and the nixies will get it worked out.

sbrow commented 2 years ago

For anyone else that has this problem, I was able to get the build running with Nix on MacOS Monterey using the following default.nix file.

{ pkgs ? import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/9cc577aa46b0ae2c2b369354bb27055d35c89efd.tar.gz") {}
}:

pkgs.mkShell {
  buildInputs = [
    # pkgs.haskellPackages.hfsevents
    # pkgs.ghc
    pkgs.libffi
    pkgs.libiconv
    pkgs.ncurses
    pkgs.stack
    pkgs.zlib
    pkgs.darwin.apple_sdk.frameworks.CoreServices
    pkgs.darwin.apple_sdk.frameworks.Cocoa
    pkgs.darwin.objc4.all
  ];
}

Unfortunately, this still uses a user-level GHC install. Perhaps someone with more time on their hands could figure out a "proper" nix config with the help of the haskell4nix documentation.