Skip to content

Instantly share code, notes, and snippets.

@mjlbach
Last active Nov 30, 2022
Embed
What would you like to do?
Installing gccEmacs (native-comp) with Nix

Nix

Adding the overlay and configuring cachix

Option 1: Adding the overlay to configuration.nix or home.nix

Add the nix-community overlay to your nixpkgs. You can add the following to your configuration.nix (NixOS, non-user specific) or to your home-manager's home.nix. Note in the case of the latter, this will not be available for installation via nix-env.

{
  nixpkgs.overlays = [
    (import (builtins.fetchTarball {
      url = https://github.com/nix-community/emacs-overlay/archive/master.tar.gz;
    }))
  ];
}

See nixos or home-manager options for more information on adding overlays.

Option 2: Add to the overlays directory

echo "import (builtins.fetchTarball {
      url = https://github.com/nix-community/emacs-overlay/archive/master.tar.gz;
    })" >> $HOME/.config/nixpkgs/overlays/emacs.nix

Optional: Add cachix support to avoid compilation

As this package is installed via an overlay, it is not built by the Hydra CI/CD pipeline that underlies nixpkgs. Instead, the binary is built by the nix-community hydra and pushed to Cachix. Follow the instructions here to add the nix-community cachix.

nix-env -iA cachix -f https://cachix.org/api/v1/install
cachix use nix-community

You will need to ensure that you are are installing the emacs overlay from the nixos-unstable unstable channel, not the nixpkgs-unstable channel. If you are using home-manager, you will need to set your default channel to nixos-unstable (you can do this on non-NixOS systems, the difference is that nixos-unstable lags behind nixpkgs-unstable due to requiring more comprehensive tests before deployment). Alternatively, you can separately import nixos-unstable import <nixos-unstable> { overlays = [ overlay1 overlay2 ]; } separately, and use a separate channel specifically for emacs.

Installing emacs

If you followed option 2, the following will work.

nix-env -iA nixpkgs.emacsGcc

More likely, you will want to declaratively install in your configuration.nix or home.nix.

Home-manager provides a handy module, you can also add extra packages such as vterm.

{
  programs.emacs = {
    enable = true;
    package = pkgs.emacsGcc;
    extraPackages = (epkgs: [ epkgs.vterm ] );
  };
}

Alternatively you can add something like the following to you configuration.nix system packages

{
emacsWithPackages = (pkgs.emacsPackagesGen pkgs.emacsGcc).emacsWithPackages (epkgs: ([epkgs.vterm]));
}

Notes

As of 2020-08-03 the above works on fedora/ubuntu/debian and under NixOS. If you get an immediate segfault upon starting emacs, please ensure that your font is appropriately configured.

@mjlbach
Copy link
Author

mjlbach commented Nov 9, 2020

If you look at the notes, the above only works on Linux. If you want to use on mac, I would recommend my custom overlay in which I've patched the error and provide a cachix cache.

Edit: This overlay is deprecated. Most of the fixes are now in the nix-community emacs-overlay.

@webframp
Copy link

webframp commented Nov 10, 2020

Thanks for the pointer @mjlbach I'll try that out!

@webframp
Copy link

webframp commented Nov 11, 2020

Can confirm that works quite well @mjlbach, thanks!

@arjunv27
Copy link

arjunv27 commented Dec 8, 2020

Do binaries from cachix make sense for a program which is intended for native compilation? Do we get the same benefits from the binaries?

@mjlbach
Copy link
Author

mjlbach commented Dec 8, 2020

Yes, the build fetched from cachix will only substitute if it matches what nix would build locally . I don’t use nix to manage my emacs packages, but I believe the community overlay provides pre-native compiled emacs packages as well.

@panaak
Copy link

panaak commented Dec 28, 2020

Trying to run emacs daemon i get strange error:

Assertion failed: (mach_vm_map(mach_task_self(), &address, size, 0, VM_FLAGS_ANYWHERE | VM_MAKE_TAG(VM_MEMORY_COREGRAPHICS_BACKINGSTORES), port, 0, false, prot, prot, VM_INHERIT_SHARE) == KERN_SUCCESS), function backing_map, file /AppleInternal/BuildRoot/Library/Caches/com.apple.xbs/Sources/SkyLight/SkyLight-569.6/SkyLight/Services/Windows/CGSBackingStore.c, line 192. Fatal error 6: Aborted [1] 2319 abort emacs --fg-daemon

more info here: nix-community/emacs-overlay#98

@mjlbach
Copy link
Author

mjlbach commented Dec 28, 2020

I agree with the assessment in nix-community/emacs-overlay#98. Did you file an upstream issue?

@panaak
Copy link

panaak commented Dec 28, 2020

i'm not sure where would be the best place to file it.. what would you recommend?

@mjlbach
Copy link
Author

mjlbach commented Dec 28, 2020

@panaak
Copy link

panaak commented Dec 28, 2020

ok, thanks.. bug report sent..

@thomasheartman
Copy link

thomasheartman commented Feb 9, 2021

@mjlbach Thanks for this! I have a question on using Cachix, though. The gist says:

You will need to ensure that you are are installing the emacs overlay from the nixos-unstable unstable channel, not the nixpkgs-unstable channel. If you are using home-manager, you will need to set your default channel to nixos-unstable.

I'm not entirely sure I get what this means. Does that mean running nix-channel --add https://nixos.org/channels/nixos-unstable nixos or is there some configuration you can do in home-manager? I tried looking through the readme for home-manager, but couldn't find anything obvious there.

The gist also mentions you can import <nixos-unstable> and use overlays there, but I'm afraid I don't know how I'd do that either. Could you elaborate on how to do that?

Aside from Cachix, everything works great. But having to unexpectedly rebuild Emacs when just wanting to change some configuration settings can be an annoyance 🤷

@mjlbach
Copy link
Author

mjlbach commented Feb 10, 2021

If you add a channel via nix-channel, you can import it within home-manager, and use that channel to install emacs-overlay. The mechanism isn't unique to home-manager, but is part of the nix expression language, so it's not in that readme. Something like.

  1. nix-channel --add https://nixos.org/channels/nixos-unstable nixos-unstable
let
pkgs-unstable = import <nixos-unstable> {overlays = [(builtins.fetchTarball {
      url = https://github.com/nix-community/emacs-overlay/archive/master.tar.gz;
    })];};
in
{
home.packages = with pkgs-unstable; [
    emacsGit
];
}

@thomasheartman
Copy link

thomasheartman commented Feb 11, 2021

Thanks! Unfortunately, I still can't make it work. I've tried adding and unpacking the unstable channel as you've demonstrated, and tried with code like this:

let

  unstable = import <nixos-unstable>  {overlays = [(builtins.fetchTarball {
      url = https://github.com/nix-community/emacs-overlay/archive/master.tar.gz;
    })];};

  my-emacs = unstable.emacsWithPackagesFromUsePackage {
    package = unstable.emacsGcc;
  };

in
{
  # ...
}

But it won't build. I get an error saying 'attempt to call something which is not a function but a string with context'.

The full error message looks like this:

Full trace
error: while evaluating the attribute 'buildCommand' of the derivation 'home-manager-generation' at /nix/store/acizvsxjirdh4zmhfcwa0gdsv3zcv3jn-nixos-20.09.3072.d4c29df154d/nixos/pkgs/build-support/trivial-builders.nix:7:7:
while evaluating the attribute 'text' of the derivation 'activation-script' at /nix/store/acizvsxjirdh4zmhfcwa0gdsv3zcv3jn-nixos-20.09.3072.d4c29df154d/nixos/pkgs/build-support/trivial-builders.nix:7:7:
while evaluating 'mkCmd' at /nix/store/lc4np3b1gi4fh8wr98h1xshwqcn8mipl-source/modules/home-environment.nix:502:17, called from undefined position:                                                                         
while evaluating the attribute 'data' at /nix/store/lc4np3b1gi4fh8wr98h1xshwqcn8mipl-source/modules/lib/dag.nix:91:37:                                                                                                          
while evaluating the attribute 'data' at /nix/store/lc4np3b1gi4fh8wr98h1xshwqcn8mipl-source/modules/lib/dag.nix:85:9:                                                                                                           
while evaluating the attribute 'data' at undefined position:
while evaluating 'g' at /nix/store/acizvsxjirdh4zmhfcwa0gdsv3zcv3jn-nixos-20.09.3072.d4c29df154d/nixos/lib/attrsets.nix:276:19, called from undefined position:
while evaluating anonymous function at /nix/store/acizvsxjirdh4zmhfcwa0gdsv3zcv3jn-nixos-20.09.3072.d4c29df154d/nixos/lib/modules.nix:98:72, called from /nix/store/acizvsxjirdh4zmhfcwa0gdsv3zcv3jn-nixos-20.09.3072.d4c29df154d/nixos/lib/attrsets.nix:279:20:          
while evaluating the attribute 'value' at /nix/store/acizvsxjirdh4zmhfcwa0gdsv3zcv3jn-nixos-20.09.3072.d4c29df154d/nixos/lib/modules.nix:465:9:            
while evaluating the option `home.activation.installPackages.data':
while evaluating the attribute 'mergedValue' at /nix/store/acizvsxjirdh4zmhfcwa0gdsv3zcv3jn-nixos-20.09.3072.d4c29df154d/nixos/lib/modules.nix:497:5:            
while evaluating the attribute 'values' at /nix/store/acizvsxjirdh4zmhfcwa0gdsv3zcv3jn-nixos-20.09.3072.d4c29df154d/nixos/lib/modules.nix:491:9:            
while evaluating the attribute 'values' at /nix/store/acizvsxjirdh4zmhfcwa0gdsv3zcv3jn-nixos-20.09.3072.d4c29df154d/nixos/lib/modules.nix:590:7:            
while evaluating anonymous function at /nix/store/acizvsxjirdh4zmhfcwa0gdsv3zcv3jn-nixos-20.09.3072.d4c29df154d/nixos/lib/modules.nix:477:28, called from /nix/store/acizvsxjirdh4zmhfcwa0gdsv3zcv3jn-nixos-20.09.3072.d4c29df154d/nixos/lib/modules.nix:477:17:           
while evaluating definitions from `/nix/store/lc4np3b1gi4fh8wr98h1xshwqcn8mipl-source/modules/home-environment.nix':
while evaluating 'dischargeProperties' at /nix/store/acizvsxjirdh4zmhfcwa0gdsv3zcv3jn-nixos-20.09.3072.d4c29df154d/nixos/lib/modules.nix:549:25, called from /nix/store/acizvsxjirdh4zmhfcwa0gdsv3zcv3jn-nixos-20.09.3072.d4c29df154d/nixos/lib/modules.nix:478:137:          
while evaluating the attribute 'value' at /nix/store/acizvsxjirdh4zmhfcwa0gdsv3zcv3jn-nixos-20.09.3072.d4c29df154d/nixos/lib/modules.nix:338:44:           
while evaluating the attribute 'passAsFile' of the derivation 'home-manager-path' at /nix/store/acizvsxjirdh4zmhfcwa0gdsv3zcv3jn-nixos-20.09.3072.d4c29df154d/nixos/pkgs/build-support/trivial-builders.nix:7:7:
while evaluating the attribute 'packages' at undefined position:
while evaluating 'g' at /nix/store/acizvsxjirdh4zmhfcwa0gdsv3zcv3jn-nixos-20.09.3072.d4c29df154d/nixos/lib/attrsets.nix:276:19, called from undefined position:
while evaluating anonymous function at /nix/store/acizvsxjirdh4zmhfcwa0gdsv3zcv3jn-nixos-20.09.3072.d4c29df154d/nixos/lib/modules.nix:98:72, called from /nix/store/acizvsxjirdh4zmhfcwa0gdsv3zcv3jn-nixos-20.09.3072.d4c29df154d/nixos/lib/attrsets.nix:279:20:          
while evaluating the attribute 'value' at /nix/store/acizvsxjirdh4zmhfcwa0gdsv3zcv3jn-nixos-20.09.3072.d4c29df154d/nixos/lib/modules.nix:465:9:            
while evaluating the option `home.packages':
while evaluating the attribute 'mergedValue' at /nix/store/acizvsxjirdh4zmhfcwa0gdsv3zcv3jn-nixos-20.09.3072.d4c29df154d/nixos/lib/modules.nix:497:5:            
while evaluating 'merge' at /nix/store/acizvsxjirdh4zmhfcwa0gdsv3zcv3jn-nixos-20.09.3072.d4c29df154d/nixos/lib/types.nix:264:20, called from /nix/store/acizvsxjirdh4zmhfcwa0gdsv3zcv3jn-nixos-20.09.3072.d4c29df154d/nixos/lib/modules.nix:499:59:           
while evaluating anonymous function at /nix/store/acizvsxjirdh4zmhfcwa0gdsv3zcv3jn-nixos-20.09.3072.d4c29df154d/nixos/lib/types.nix:265:35, called from undefined position:
while evaluating anonymous function at /nix/store/acizvsxjirdh4zmhfcwa0gdsv3zcv3jn-nixos-20.09.3072.d4c29df154d/nixos/lib/lists.nix:116:29, called from undefined position:
while evaluating anonymous function at /nix/store/acizvsxjirdh4zmhfcwa0gdsv3zcv3jn-nixos-20.09.3072.d4c29df154d/nixos/lib/types.nix:267:23, called from /nix/store/acizvsxjirdh4zmhfcwa0gdsv3zcv3jn-nixos-20.09.3072.d4c29df154d/nixos/lib/lists.nix:116:32:             
while evaluating the attribute 'optionalValue' at /nix/store/acizvsxjirdh4zmhfcwa0gdsv3zcv3jn-nixos-20.09.3072.d4c29df154d/nixos/lib/modules.nix:509:5:            
while evaluating the attribute 'values' at /nix/store/acizvsxjirdh4zmhfcwa0gdsv3zcv3jn-nixos-20.09.3072.d4c29df154d/nixos/lib/modules.nix:491:9:            
while evaluating the attribute 'values' at /nix/store/acizvsxjirdh4zmhfcwa0gdsv3zcv3jn-nixos-20.09.3072.d4c29df154d/nixos/lib/modules.nix:590:7:            
while evaluating anonymous function at /nix/store/acizvsxjirdh4zmhfcwa0gdsv3zcv3jn-nixos-20.09.3072.d4c29df154d/nixos/lib/modules.nix:477:28, called from /nix/store/acizvsxjirdh4zmhfcwa0gdsv3zcv3jn-nixos-20.09.3072.d4c29df154d/nixos/lib/modules.nix:477:17:           
while evaluating definitions from `/home/thomas/dotfiles/.config/nixpkgs/home.nix':
while evaluating 'dischargeProperties' at /nix/store/acizvsxjirdh4zmhfcwa0gdsv3zcv3jn-nixos-20.09.3072.d4c29df154d/nixos/lib/modules.nix:549:25, called from /nix/store/acizvsxjirdh4zmhfcwa0gdsv3zcv3jn-nixos-20.09.3072.d4c29df154d/nixos/lib/modules.nix:478:137:          
while evaluating the attribute 'value' at /nix/store/acizvsxjirdh4zmhfcwa0gdsv3zcv3jn-nixos-20.09.3072.d4c29df154d/nixos/lib/types.nix:271:40:             
while evaluating anonymous function at /nix/store/q1lhzvzy7sapxi9b5838zvqlnk9vhxf3-nixos-unstable-21.03pre269174.29a15e2c1f5/nixos-unstable/pkgs/top-level/impure.nix:15:1, called from /home/thomas/dotfiles/.config/nixpkgs/home.nix:5:14:                                                             
while evaluating anonymous function at /nix/store/q1lhzvzy7sapxi9b5838zvqlnk9vhxf3-nixos-unstable-21.03pre269174.29a15e2c1f5/nixos-unstable/pkgs/top-level/default.nix:19:1, called from /nix/store/q1lhzvzy7sapxi9b5838zvqlnk9vhxf3-nixos-unstable-21.03pre269174.29a15e2c1f5/nixos-unstable/pkgs/top-level/impure.nix:83:1:
while evaluating anonymous function at /nix/store/q1lhzvzy7sapxi9b5838zvqlnk9vhxf3-nixos-unstable-21.03pre269174.29a15e2c1f5/nixos-unstable/pkgs/stdenv/booter.nix:42:1, called from /nix/store/q1lhzvzy7sapxi9b5838zvqlnk9vhxf3-nixos-unstable-21.03pre269174.29a15e2c1f5/nixos-unstable/pkgs/top-level/default.nix:122:10:
while evaluating 'dfold' at /nix/store/q1lhzvzy7sapxi9b5838zvqlnk9vhxf3-nixos-unstable-21.03pre269174.29a15e2c1f5/nixos-unstable/pkgs/stdenv/booter.nix:60:27, called from /nix/store/q1lhzvzy7sapxi9b5838zvqlnk9vhxf3-nixos-unstable-21.03pre269174.29a15e2c1f5/nixos-unstable/pkgs/stdenv/booter.nix:136:4:
while evaluating 'go' at /nix/store/q1lhzvzy7sapxi9b5838zvqlnk9vhxf3-nixos-unstable-21.03pre269174.29a15e2c1f5/nixos-unstable/pkgs/stdenv/booter.nix:63:18, called from /nix/store/q1lhzvzy7sapxi9b5838zvqlnk9vhxf3-nixos-unstable-21.03pre269174.29a15e2c1f5/nixos-unstable/pkgs/stdenv/booter.nix:72:13:
while evaluating 'folder' at /nix/store/q1lhzvzy7sapxi9b5838zvqlnk9vhxf3-nixos-unstable-21.03pre269174.29a15e2c1f5/nixos-unstable/pkgs/stdenv/booter.nix:89:33, called from /nix/store/q1lhzvzy7sapxi9b5838zvqlnk9vhxf3-nixos-unstable-21.03pre269174.29a15e2c1f5/nixos-unstable/pkgs/stdenv/booter.nix:68:18:
while evaluating 'allPackages' at /nix/store/q1lhzvzy7sapxi9b5838zvqlnk9vhxf3-nixos-unstable-21.03pre269174.29a15e2c1f5/nixos-unstable/pkgs/top-level/default.nix:112:17, called from /nix/store/q1lhzvzy7sapxi9b5838zvqlnk9vhxf3-nixos-unstable-21.03pre269174.29a15e2c1f5/nixos-unstable/pkgs/stdenv/booter.nix:101:12:
while evaluating anonymous function at /nix/store/q1lhzvzy7sapxi9b5838zvqlnk9vhxf3-nixos-unstable-21.03pre269174.29a15e2c1f5/nixos-unstable/pkgs/top-level/stage.nix:12:1, called from /nix/store/q1lhzvzy7sapxi9b5838zvqlnk9vhxf3-nixos-unstable-21.03pre269174.29a15e2c1f5/nixos-unstable/pkgs/top-level/default.nix:112:26:
while evaluating 'fix' at /nix/store/q1lhzvzy7sapxi9b5838zvqlnk9vhxf3-nixos-unstable-21.03pre269174.29a15e2c1f5/nixos-unstable/lib/fixed-points.nix:19:9, called from /nix/store/q1lhzvzy7sapxi9b5838zvqlnk9vhxf3-nixos-unstable-21.03pre269174.29a15e2c1f5/nixos-unstable/pkgs/top-level/stage.nix:252:3:
while evaluating 'extends' at /nix/store/q1lhzvzy7sapxi9b5838zvqlnk9vhxf3-nixos-unstable-21.03pre269174.29a15e2c1f5/nixos-unstable/lib/fixed-points.nix:69:24, called from /nix/store/q1lhzvzy7sapxi9b5838zvqlnk9vhxf3-nixos-unstable-21.03pre269174.29a15e2c1f5/nixos-unstable/lib/fixed-points.nix:19:20:
while evaluating 'extends' at /nix/store/q1lhzvzy7sapxi9b5838zvqlnk9vhxf3-nixos-unstable-21.03pre269174.29a15e2c1f5/nixos-unstable/lib/fixed-points.nix:69:24, called from /nix/store/q1lhzvzy7sapxi9b5838zvqlnk9vhxf3-nixos-unstable-21.03pre269174.29a15e2c1f5/nixos-unstable/lib/fixed-points.nix:69:42:
attempt to call something which is not a function but a string with context, at /nix/store/q1lhzvzy7sapxi9b5838zvqlnk9vhxf3-nixos-unstable-21.03pre269174.29a15e2c1f5/nixos-unstable/lib/fixed-points.nix:69:67

Do you know what that means? Am I doing something wrong? Obviously, you have no obligation to assist me, so there's no pressure, but I would appreciate it if you had a tip or two. It seems you know your way around this a lot better than I do. Cheers!

@collares
Copy link

collares commented Feb 24, 2021

@thomasheartman Try something like this:

let
  unstable = import <nixos-unstable> { overlays = [(import (builtins.fetchTarball {
    url = https://github.com/nix-community/emacs-overlay/archive/master.tar.gz;
  }))];};

  my-emacs = unstable.emacsWithPackagesFromUsePackage {
    config = /home/USERNAME/.emacs.d/init.el;
    package = unstable.emacsGcc;
  };
in
{
  home.packages = [
    my-emacs
  ];
}

@thomasheartman
Copy link

thomasheartman commented Feb 24, 2021

@collares Thanks! I tried that, but got an error message saying that

error: file 'nixos-unstable' was not found in the Nix search path (add it using $NIX_PATH or -I)

From what I gather, that's because user channels aren't included in the nix search path by default (according to this issue). I'm trying to see if I can figure out how to add them, but in the meantime:

Instead, I tried doing importing the unstable channel instead via a url (inspired by this post on functor.tokyo:

let

  unstable = import (fetchTarball
    https://github.com/NixOS/nixpkgs-channels/archive/nixos-unstable.tar.gz) {
    overlays = [
      (import (builtins.fetchTarball {
        url =
          "https://github.com/nix-community/emacs-overlay/archive/master.tar.gz";
      }))
    ];
};

  my-emacs = unstable.emacsWithPackagesFromUsePackage {
    config = ~/.emacs.d/init.el;
    package = unstable.emacsGcc;
    alwaysTangle = true;
    extraEmacsPackages = epkgs: [
      epkgs.exwm
      epkgs.emacsql-sqlite
      epkgs.vterm
      epkgs.pdf-tools
    ];
  };

in
{
 # ...
}

Now it builds, but it still has compiles Emacs from the ground up. Should this work? I wonder whether there's something wrong with my Cachix setup. There's nothing else that needs to be done than install it and run the cachix use nix-community command, right?

Update

Wait, I managed to figure something out: I had to add the unstable channel as the root user and then run sudo nix-channel --update nixos-unstable. Is that the right approach?

At this point the caching looks like it works. I still have to manually compile EXWM it seems, but at least that's only about a minute as opposed to fifteen, so that's better.

Still, if it's possible to use the cache and the unstable channel without needing to have a stable channel set up (such as by using fetchTarball to get the channel, for instance), I'd be very interested in hearing about that. And if it isn't, why isn't it?

@collares
Copy link

collares commented Feb 24, 2021

@thomasheartman The nixpkgs-channels repo is deprecated. Try using https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz instead.

@thomasheartman
Copy link

thomasheartman commented Feb 25, 2021

@collares Oh, yes; there we go! Thank you! That seems to have done the job.

For anyone else wondering, this is what I ended up doing:

let

  unstable = import (fetchTarball
    "https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz") {
      overlays = [
        (import (builtins.fetchTarball {
          url =
            "https://github.com/nix-community/emacs-overlay/archive/master.tar.gz";
        }))
      ];
    };

  my-emacs = (pkgs.emacsPackagesGen unstable.emacsGcc).emacsWithPackages
    (epkgs: [ epkgs.exwm epkgs.emacsql-sqlite epkgs.vterm epkgs.pdf-tools ]);

in {

}

Just switching the URL was enough to make it work. Moving away from emacsWithPackagesFromUsePackage is mosty because I use Straight, and I have the impression that those two don't play well together, if at all.

@jacksonludwig
Copy link

jacksonludwig commented Mar 14, 2021

In my home manager I have the following:

{ config, pkgs, ... }:

let

  unstable = import (fetchTarball
    "https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz") {
      overlays = [
        (import (builtins.fetchTarball {
          url = https://github.com/nix-community/emacs-overlay/archive/master.tar.gz;
        }))
      ];
    };

in {
# <other config above>
    programs.emacs = {
      enable = true;
      package = unstable.emacsGcc;
      extraPackages = epkgs: with epkgs; [
          vterm
      ];
  };
# <other config after>
}

I have my channels updated (not that I think it would matter since I'm importing it directly) and have my cachix set to nix-community and your's/mjlbach.

Still, though, nix refuses to pull from the cache and tries to build emacs itself. Is there anything I'm missing here?

@mjlbach
Copy link
Author

mjlbach commented Mar 14, 2021

I don't provide a cache for emacsGcc on linux, only on macOS. I provide a cache for emacsPgtkGcc on Linux, for issues with the nix-community cache you should report there.

@jacksonludwig
Copy link

jacksonludwig commented Mar 14, 2021

Ah my mistake about that. However, I just switched it and nix is still trying to build emacs when using emacsPgtkGcc instead of emacsGcc in my above config.

@mjlbach
Copy link
Author

mjlbach commented Mar 14, 2021

Well, you're using the nix-community overlay in that snippet, so like I said you can file an issue with the nix-community repo, or switch to using my overlay

@jacksonludwig
Copy link

jacksonludwig commented Mar 14, 2021

Sorry, I am a bit confused, I thought I had it the way your readme shows:
image
Would you be able to tell me what I have to change in my config to have it use your's?

@thomasheartman
Copy link

thomasheartman commented Mar 15, 2021

@jacksonludwig This may be unrelated, but could also be what you're seeing. I'm using the same approach (with the imported unstable channel). For a while this worked as expected and pulled the latest build from the cache. However, at some point last week (I think), this stopped working for me and I'm now back to having to build Emacs manually again.

Of course, it could be that I messed something else up somehow, but I don't think so, and seeing you experience something similar makes me think that there could be something wrong with the overlay/cache. However, I can't say for certain that I didn't mess it up myself without taking a closer look at my git history, so I may very well be in the wrong here (Occam's razor and all).

Just thought I'd chime in. If you manage to solve it, I'd love to hear about it. 😄

@jacksonludwig
Copy link

jacksonludwig commented Mar 15, 2021

@thomasheartman yea, thanks for chiming in. I think you may be correct, as I also use the neovim-nightly community overlay that mjlbach maintains which has been pulled from the cache correctly every time I run home-manager switch. I feel like there is an issue somewhere in the emacs community overlay at the moment.

FWIW I made an issue on the community-overlay repo.

@anthonyclarka2
Copy link

anthonyclarka2 commented Sep 10, 2021

I just wanted to be 100% clear about how to configure this. My ~/.nixpkgs/darwin-configuration.nix was created by following the installation instructions at https://wickedchicken.github.io/post/macos-nix-setup/

I then added the cachix binary cache via:

nix-env -iA cachix -f https://cachix.org/api/v1/install
cachix use nix-community

Here's my darwin-configuration.nix:

{ config, pkgs, ... }:

let

  unstable = import (fetchTarball
    "https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz") {
      overlays = [
        (import (builtins.fetchTarball {
          url =
            "https://github.com/nix-community/emacs-overlay/archive/master.tar.gz";
        }))
      ];
    };

  my-emacs = (pkgs.emacsPackagesGen unstable.emacsGcc).emacsWithPackages
    (epkgs: [ epkgs.exwm epkgs.emacsql-sqlite epkgs.vterm epkgs.pdf-tools ]);

in {
  # List packages installed in system profile. To search by name, run:
  # $ nix-env -qaP | grep wget
  environment.systemPackages = with pkgs; [
    vim
    curl
    wget
    my-emacs
    ];

  # Use a custom configuration.nix location.
  # $ darwin-rebuild switch -I darwin-config=$HOME/.config/nixpkgs/darwin/configuration.nix
  # environment.darwinConfig = "$HOME/.config/nixpkgs/darwin/configuration.nix";

  # Auto upgrade nix package and the daemon service.
  # services.nix-daemon.enable = true;
  # nix.package = pkgs.nix;

  # Create /etc/bashrc that loads the nix-darwin environment.
  programs.zsh.enable = true;  # default shell on catalina
  # programs.fish.enable = true;

  # Used for backwards compatibility, please read the changelog before changing.
  # $ darwin-rebuild changelog
  system.stateVersion = 4;
}

Right now, my emacs 28 is being built manually. I think I'm referring to the wrong emacs in the my-emacs = block. Does anyone know the correct package to refer to so I can grab the binary rather than rebuild?

@thomasheartman
Copy link

thomasheartman commented Sep 10, 2021

Hey, @anthonyclarka2!

It may just be that you've been unlucky with when you've tried to pull the package (as mentioned in this issue on the emacs-overlay repo). If you want to pin it to a specific version, you could follow the advice in this thread.

At least from what I can tell, it looks right. However, I'm definitely not the expert, and may very well be wrong, so let's see what the other folks say.


Edit: fixed the link to the advice on pinning the overlay version. It previously pointed back to this thread, but should now point to a thread on the emacs-overlay repo instead.

@anthonyclarka2
Copy link

anthonyclarka2 commented Sep 10, 2021

I ended up using the instructions from this page: https://github.com/twlz0ne/nix-gccemacs-darwin

nix-env -iA cachix -f https://cachix.org/api/v1/install
cachix use gccemacs-darwin
nix-env -iA emacsGccDarwin -f https://github.com/twlz0ne/nix-gccemacs-darwin/archive/master.zip

@intractable
Copy link

intractable commented Sep 12, 2021

It may just be that you've been unlucky with when you've tried to pull the package (as mentioned in this issue on the emacs-overlay repo). If you want to pin it to a specific version, you could follow the advice in this thread.

@thomasheartman Is that link to advice on specific-version pinning actually in this thread, or elsewhere? The suggestions here have been very helpful, and I can get an emacs that I like, but I'm moderately annoyed by frequent rebuilds under configuration.nix changes (caching doesn't seem to work for me and/or I'm just switching my config frequently enough that I'm hitting a window prior to cache population) and would like to be able to pin and bump manually.

Other than that outstanding question, this thread has been very useful, so thanks!

@thomasheartman
Copy link

thomasheartman commented Sep 12, 2021

@intractable Oh, sorry; I must have pasted the wrong link. I meant to link to this issue on the emacs-overlay repo and not to this thread. I'll update my original comment too.

In short, though, the way you do it is by changing the URL to use a specific commit instead of the latest master commit (by swapping master for the desired commit hash) and by adding a sha256 field to the fetchTarball function. If you don't know the hash for the version you're downloading (which is likely), add 0000000000000000000000000000000000000000000000000000 or some other dummy value and change it to what nix reports.

As an example, my config looks like this now and it seems to work.

        import (
          builtins.fetchTarball {
            url =
              "https://github.com/nix-community/emacs-overlay/archive/8320c615b706f0d459544d7d37a59c5a5ff5e7e0.tar.gz";
            sha256 = "1pajyn4n0yzi8qxlqjlh20zhdifxfvxqdcjmphqmb8b5p2grk2rx";
          }
        )

@intractable
Copy link

intractable commented Sep 13, 2021

@thomasheartman I had totally forgotten that one can put the gitrev directly into the URL like that. Thanks so much!

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