Search code examples
macosnanonix

Nix on OSX fails to build nano?


I'm trying to use nix and I've run into a problem which I think is related to nix failing to build nano, but I'm not certain. I'm on OSX 10.11.4 (I'm very new to Macs as well) and am getting the following error:

clang -DHAVE_CONFIG_H -I. -I..  -DLOCALEDIR=\"/nix/store/h1afxzyfxh7xc8b0scvq831s1yapczgm-nano-2.6.3/share/locale\" -DSYSCONFDIR=\"/etc\" -I/nix/store/gmb9mxkm5mqfnhlav16rx5x7wf070qqf-ncurses-5.9-dev/include/ncursesw -I/nix/store/gmb9mxkm5mqfnhlav16rx5x7wf070qqf-ncurses-5.9-dev/include   -g -O2 -Wall -c -o winio.o winio.c
winio.c:513:15: error: use of undeclared identifier 'TIOCLINUX'
        if (ioctl(0, TIOCLINUX, &modifiers) >= 0 && (modifiers & 0x04)) {
                     ^
1 error generated.

Is there something that I have set up incorrectly here? All that I did was setup nix via the curl ... | sh and then source ~/.nix-profile/etc/profile.d/nix.sh.

I'm trying to build from this shell.nix:

{ nixpkgs ? import <nixpkgs> {}, compiler ? "default" }:

let

  inherit (nixpkgs) pkgs;

  # Build a default.nix file from our .cabal file:
  here = ./.;
  project = pkgs.stdenv.mkDerivation ({
    name = "default.nix";

    buildCommand = ''
    ${pkgs.cabal2nix}/bin/cabal2nix file://${here} > $out
    '';
  });

  # Use the package set for our compiler:
  haskellPackages = if compiler == "default"
                       then pkgs.haskellPackages
                       else pkgs.haskell.packages.${compiler};

  # Helper function that gets Nix-packaged dependencies off GitHub.
  # GitHub project needs a default.nix file for this to work.
  fetchHaskell = { url, rev, sha256 }:
    haskellPackages.callPackage (pkgs.fetchgit { inherit url rev sha256; }) {};

  drv = haskellPackages.callPackage project {
    # Specify GitHub dependencies here.
    # You can get url, rev and sha256 by running 'nix-prefetch-git git@...'
    ...snip....
  };

in

  if pkgs.lib.inNixShell then drv.env else drv

Any pointers would be greatly appreciated.


Solution

  • I don't know anything about nix, but I get the same error building nano from source code. The problem is that a section of code checking for ctrl-arrow keys on the Linux console is included unconditionally, causing the build to fail on any system other than Linux.

    Find the entire section of winio.c where it is doing this (line 507-523 on my manually downloaded nano version 2.6.3), and remove it (I put #ifdef TIOCLINUX before it and #endif after, but just deleting it, using #if 0, or commenting it out will work just as well) If you can't control the source code being built by nix you may need to install nano by some other means (manual source compilation, or macports, or fink, or homebrew)

    The MacPorts version of nano contains a patch which resolves this issue: https://trac.macports.org/browser/trunk/dports/editors/nano/files/patch-src-winio.c.diff