NixOS stable - Emacs ImageMagick support

Hello list,
Emacs user here; I see that ImageMagick is specified as dependency in Emacs derivation
however (image-type-available-p 'imagemagick) ⇒ nil. Am I missing something?

Thanks :slight_smile:

– Ingmar

1 Like

The package is called from all-packages.nix with imagemagick = null, so you need to use something like this,

nixpkgs.emacs.override { inherit (nixpkgs) imagemagick; }

for your emacs definition. Unfortunately this does mean that you will be building emacs yourself; fortunately it’s not the slowest build out there.

Hy,
thanks for the quick reply!

The package is called from all-packages.nix with
imagemagick => null so you need to use something like this,

nixpkgs.emacs.override { inherit (nixpkgs) imagemagick; }

Hum, maybe I do not understand (my nix knowledge is rather limited),
using directly this expression in my config result in an error so I
tried to “override” in nixpkgs.config like:

 packageOverrides = pkgs: {
   emacs = pkgs.emacs.override {
     imagemagick = true;
  };
 };

However nixos-rebuild fail with

building '/nix/store/rxzlpnpmicmbwxgxxfp5gk5m0wn1a928-emacs-26.1.drv'...
build input 1 does not exist

Where am I wrong?

Unfortunately this does mean that you will be building emacs yourself;
fortunately it’s not the slowest build out there.
That’s ok, expected and not much a problem since Emacs on stable
does not change too frequently :slight_smile:

– Ingmar

The error is probably related to the fact that the imagemagick argument is expected to be a derivation (sort of like a package) and not a boolean. What was the other error that you got?

What @acowley did above is take imagemagick from the package set and re-inject it back into the argument used to build the emacs package.

inherit (nixpkgs) imagemagick; is a shorter version of imagemagick = pkgs.imagemagick;

1 Like

I think @zimbatm explained it pretty well, but do ask for more assistance if it would help. The snippet I pasted is directly from how I install emacs, which you can take a look at to see a somewhat complicated by very real configuration.

To expand things a bit, the name nixpkgs I used is because my overlay named its second argument nixpkgs, whereas you are using the identifier pkgs for the same purpose in your config.nix.

Hy,

The error is probably related to the fact that the imagemagick
argument is expected to be a derivation (sort of like a package) and
not a boolean. What was the other error that you got?
A paste error, my bad… So I change imagemagick = true; to
imagemagick = pkgs.imagemagick; and finally Emacs got properly
rebuild :slight_smile:

However I still have a problem, I’ve forgotten to mention that I’m
using EXWM… I’ve got two Emacs, one with ImageMagick support, ldd
proof at hand
/nix/store/…cmr-emacs-26.1/bin/.emacs-26.1-wrapped
and another without
/nix/store/…cqy-emacs-26.1/bin/.emacs-26.1-wrapped
the letter is launched bye windowManager.exwm.enable = true;

Did I have to override also exwm in some way ?

Thanks!

– Ingmar

Hy,

I think @zimbatm explained it pretty well, but do ask for more
assistance if it would help. The snippet I pasted is directly from how
I install emacs, which you can take a look at to see a somewhat
complicated by very real configuration.
Thanks! Being a new NixOS user I still have to port my Emacs to Nix,
in the sense that I still keep Emacs config alone in my home handled
by a mix of req-package and few abandoned lips bits, sooner or later
I’ll try to nix-ify it via homeManger and probably steal something
from your config, bookmarked :slight_smile:

To expand things a bit, the name nixpkgs I used is because my
overlay named its second argument nixpkgs, whereas you are using the
identifier pkgs for the same purpose in your config.nix.
Yep, the first error I mention was a paste error on my side… Nix
DSL was a bit hard to metabolize for me :frowning:

– Ingmar

Compiling this did not work for me.

emacs = (super.emacs.override {srcRepo = true;}).overrideAttrs (old: rec {
      name = "emacs-${version}${versionModifier}";
      version = "27.0.50";
      versionModifier = "-git";
      src = pkgs.fetchFromGitHub {
        owner = "emacs-mirror";
        repo = "emacs";
        rev = "0a5212b99666b9ba0543a62cdbb12ee0685820f3";
        sha256 = "038kasdll0332vdpyc29xlkdj801sivz3ssnyz0dqr3gcavpk5yv";
      };
      patches = [];
      imagemagick = pkgs.imagemagick;
    });

(image-type-available-p 'imagemagick) still evaluated to nil.

The same goes for imagemagick = pkgs.imagemagickBig;.

Overriding with imagemagickBig works:

$ nix-build -E 'with import <nixpkgs> {}; emacs.override { imagemagick = imagemagickBig; }'
$ result/bin/emacs --batch --eval "(print (image-type-available-p 'imagemagick))"
t
1 Like

Hi,

Overriding with imagemagickBig works:
My actual NixOS config contains, for Emacs

nixpkgs = {
  config = {
    packageOverrides = pkgs: {
      emacs = pkgs.emacs.override {
        imagemagick = pkgs.imagemagick;
      };

    };
  };
};

As @Anthony Cowley posted above, but the problem in my case is that
solution does not “substitute emacs”, it build another Emacs with
proper ImageMagick support. I mean, today I have

/nix/store/0v04sr1j5c4d66pmxssqgb5brm6yxcgg-emacs-26.1

and

/nix/store/358kviq833wirlc2z6xw3r9jppr6jp01-emacs-26.1

The last one have ImageMagick support, the first, compiled form EXWM
derivation (I suppose) does not. So using EXWM activated with a simple

windowManager.exwm.enable = true;

bring me up an EXWM desktop, without ImageMagick support, however

services.xserver.windowManager.session = lib.singleton {
  name = "exwm";
  start = ''
    ${emacs}/bin/emacs 
  '';
};

Give an Emacs with ImageMagick support. My knowledge of Nix is too
limited (despite around an year of use I still haven’t had enough
time to study it more) to properly understand, In theory I suppose
that having overridden emacs derivation ANY other derivation that
use Emacs get the overridden one, but I see it’s not true… The
main point of using Nix exwm derivation is that it’s simpler and
more intuitive to my eyes.

– Ingmar

@xte It’s not easy to figure this stuff out unfortunately. For this particular case you’ll have to override emacs26 instead of the standard emacs attribute:

  nixpkgs.overlays = [(self: super: {
    emacs26 = super.emacs26.override {
      imagemagick = self.imagemagickBig;
    };
  })];

This will make services.xserver.windowManager.exwm.enable and everything else use the overridden emacs version by default.

Hi,

you’ll have to override emacs26 instead of the standard emacs
attribute
thanks for the suggestion but… No, it does not give me an Emacs
with ImageMagick support active… Just tried.

– Ingmar

What’s your configuration.nix? Did you rebuild and restart? How did you verify that it didn’t work? How did you start emacs? What’s your nixpkgs version (run nix-shell -p nix-info --run nix-info)?

I can’t help much if you don’t give me much information to work with. I’m 99% sure that the given overlay should work for exwm.

Hi,

What’s your configuration.nix?

nixpkgs = {
  config = {
    overlays = [(self: super: {
      emacs26 = super.emacs26.override { imagemagick = self.imagemagickBig; };
    })];

    packageOverrides = pkgs: {
      hplip = pkgs.hplip.override {
        withPlugin = true;
      };
  };

And

services = {
  xserver = {
    exportConfiguration = true;
    enable = true;
    layout = "us,fr,it";
    xkbOptions = "eurosign:e, compose:menu, grp:alt_space_toggle,     altwin:hyper_win";

    displayManager.lightdm = {
      enable = true;
      greeter.enable = false;
      autoLogin.user = "xte";
      autoLogin.enable = true;
    };

    displayManager.sessionCommands = ''
      ${pkgs.xorg.xhost}/bin/xhost +SI:localuser:$USER
      ${pkgs.xlibs.xsetroot}/bin/xsetroot -cursor_name left_ptr
      ${pkgs.numlockx}/bin/numlockx on
      ${pkgs.pnmixer}/bin/pnmixer &
      ${pkgs.networkmanagerapplet}/bin/nm-applet &
      ${pkgs.clipit}/bin/clipit &
      ${pkgs.autocutsel}/bin/autocutsel -selection PRIMARY -fork &
      ${pkgs.xorg.xmodmap}/bin/xmodmap /home/xte/.myenv/xkb/my_kbd_map
    '';

    desktopManager.xterm.enable = false;
    desktopManager.default = "none";

    desktopManager.session = [ {
      manage = "desktop";
      name = "exwm";
      start = ''
        ${pkgs.emacs}/bin/emacs &
        waitPID=$!
      ''; } ];

    windowManager.default = "exwm";

    windowManager.exwm = {
      enable = true;
      extraPackages = epkgs: [ ... ];
    };

    videoDrivers = [ "nouveau" ];
    autorun = true;
    startDbusSession = true;
  }; # xserver

  # compton, redshift, dunst, udiskie, unclutter ... services
}; # services

If you prefer I can paste the entire config on paste2&c, it’s a bit
verbouse, splitted in 8 files. Single file org-mode version is still
ongoing…

Did you rebuild and restart?
nixos-rebuild switch && reboot

How did you verify that it didn’t work?
(image-type-available-p 'imagemagick) => nil
ldd /nix/store/vz7av0209zm5nn87aignvl41p571zn1r-emacs-26.1/bin/.emacs-wrapped | grep -i image

How did you start emacs?
via LightDM, reshaped pstree

systemd-+
        >
        ├─lightdm─┬─X───2*[{X}]
                  ├─lightdm─┬─v6ivw4b7w9dkksp─┬─.emacs-26.1-wra─

ps x | grep emacs

/nix/store/vz7av0209zm5nn87aignvl41p571zn1r-emacs-26.1/bin/.emacs-wrapped -l /nix/store/kd9rwg8wymvbdiqp8b9xy42fxz14prlk-emacs-exwm-load

What’s your nixpkgs version (run nix-shell -p nix-info --run nix-info)?

these paths will be fetched (0.05 MiB download, 0.28 MiB unpacked):
  /nix/store/ial8a56ys2rswfq4j2abm3cl99li5b6p-bash-interactive-4.4-p23-dev
copying path '/nix/store/ial8a56ys2rswfq4j2abm3cl99li5b6p-bash-interactive-4.4-p23-dev' from 'https://cache.nixos.org'...
system: "x86_64-linux", multi-user?: yes, version: nix-env (Nix) 2.1.3, channels(root): "nixos-18.09.2436.395a543f360", nixpkgs: /nix/var/nix/profiles/per-user/root/channels/nixos

I can’t help much if you don’t give me much information to work with.
I’m 99% sure that the given overlay should work for exwm.
Thanks for your time and support :slight_smile: actually I “solved” avoiding exwm
derivation, simply running EMACS as per previous message, only I like
the idea of having exwm derivation with my packages etc, it seems a bit
cleaner to my eye :slight_smile:

– Ingmar

Ah there it is, it should be

nixpkgs = {
  overlays = ...;
  config = ...;
}

Hi,

Ah there it is, it should be

nixpkgs = {
  overlays = ...;
  config = ...;
}

Oh that’s work, thanks! I definitely need to take more time studying Nix.

– Ingmar

Hi,

I finally switch laptop e desktop to your overlay, thanks again :slight_smile:
just for late curiosity is it possible to add Emacs packages to the
same overlay instead of using windowManager.exwm.extraPackages so to
have essentially a “single block” of Emacs system-wide config leaving
exwm to a mere windowManager.exwm.enable = true; like usually done
for gnome/shell or kde?

I’m in a slow (especially since I have little free time to dedicate)
process of creating my “Emacs Computing Environment” in a way that’s
is reproducible and easy enough to modify to became a generic config,
a “custom NixOS” instead of a sole Emacs setup like famous doom,
spacemacs, prelude, …

For now I port in org-mode part of my setup (emacs, of course, mail
with mbsync+afew+notmuch+khard+small scripts and feeds) plus a rude
NixOS setup (preinstall.org to create a personal ISO with Emacs and
NixOS target configs with liveinstall.org to operate semi-automated
local deploy + automatic reporting from the live image) but it’s
still not much modular and generic… The idea is to create a series
of .nix file easy to import in a configuration.nix using noweb ref
to modularize a bit the setup. Ideal target: “here a big single, well
documented, org file with anything needed to create and deploy a
personal desktop with Emacs as UI both for CLI and graphic”. Possible
evolution beside local deploy a LAN-wide one with NixOps…

– Ingmar

Due to the way the Emacs derivation is set up this currently doesn’t work on macOS. I’ve submitted the following PR to fix the issue:

https://github.com/NixOS/nixpkgs/pull/64901