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

Nix install instructions are outdated/wrong/confusing. #21

Open
thomastjeffery opened this issue Sep 26, 2017 · 9 comments
Open

Nix install instructions are outdated/wrong/confusing. #21

thomastjeffery opened this issue Sep 26, 2017 · 9 comments

Comments

@thomastjeffery
Copy link

thomastjeffery commented Sep 26, 2017

The information here is confusing, convoluted, and doesn't seem to work.

The real way to build yi with Nix

To build yi in Nix, here is what you currently can do:

  1. Set up package overrides in Nix, so yi will build at all
    Put the following in your ~/.config/nixpkgs/config.nix:
{
  packageOverrides = pkgs: {
    haskellPackages = pkgs.haskellPackages.override {
      overrides = self: super: {
        yi-core            = super.yi-core_0_16_0;
        yi-frontend-vty    = super.yi-frontend-vty_0_16_0;
        yi-fuzzy-open      = super.yi-fuzzy-open_0_16_0;
        yi-ireader         = super.yi-ireader_0_16_0;
        yi-keymap-cua      = super.yi-keymap-cua_0_16_0;
        yi-keymap-emacs    = super.yi-keymap-emacs_0_16_0;
        yi-keymap-vim      = super.yi-keymap-vim_0_16_0;
        yi-language        = super.yi-language_0_16_0;
        yi-misc-modes      = super.yi-misc-modes_0_16_0;
        yi-mode-haskell    = super.yi-mode-haskell_0_16_0;
        yi-mode-javascript = super.yi-mode-javascript_0_16_0;
        yi-snippet         = super.yi-snippet_0_16_0;
        yi-rope            = super.yi-rope_0_10;
      };
    };
  };
}

If you don't do this, nix will complain that it has missing dependencies.

  1. Copy an example config to the right place
$ cp yi-editor/yi/example-configs/yi-config-that-you-want/* ~/.config/yi/
  1. Go to ~/.config/yi/, and build yi.
    You can leave out the -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/master.tar.gz if you are already using the master channel. This will not work on another channel like NixOS-17.09.
$ cd ~/.config/yi/
$ nix-shell -p cabal2nix -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/master.tar.gz
[nix-shell]$ cabal2nix . > default.nix
[nix-shell]$ cabal2nix --shell . > shell.nix
[nix-shell]$ exit
$ nix-build shell.nix -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/master.tar.gz
  1. Run yi
    You need to use nix-shell, so yi can rebuild the configuration you made.
$ nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/master.tar.gz
[nix-shell]$ ./result/bin/yi
@noughtmare
Copy link
Member

Copy an example config to the right place
~$ cp yi-editor/yi/example-configs/yi-config-that-you-want/* ~/.config/yi/

This is not needed by the static configs (which are recommended). They can be placed anywhere you want.

I think the overrides wouldn't have to be added if we would specify version bounds in the cabal files of the example-configs (which is probably a good idea anyway). What errors do you get when you don't specify these overrides in your ~/.config/nixpkgs/config.nix?

Finally, I have seen somewhere that stack is also capable of using nix, so you should be able to run stack --nix build instead of nix-shell -p cabal2nix to build yi.

@thomastjeffery
Copy link
Author

This is not needed by the static configs (which are recommended).

This is true, but it works for both. I wanted to be succinct. That is explained in the yi-editor/yi/README.md.

What errors do you get when you don't specify these overrides in your ~/.config/nixpkgs/config.nix?

Nix will try to build the package, and ghc will complain that it can't find the dependencies.

This is explained in more detail here

Finally, I have seen somewhere that stack is also capable of using nix

This is explicitly what I do not want to do.

I don't know what files stack is going to put where. The advantage of Nix is that I am guaranteed a clean functional system. If I want to use Nix, I want to use Nix. Stack is a perfectly fine option, just not the one I am choosing. I don't even have stack installed. I also want to rely on the prebuilt packages that Nix provides.

@noughtmare
Copy link
Member

I've changed my own config so that it now build with nix:

$ git clone https://github.com/noughtmare/yi-config.git
$ cabal2nix . --shell > shell.nix
$ nix-build shell.nix

This should work without any overrides.

@thomastjeffery
Copy link
Author

That works for me, even using 17.09 instead of master.

@noughtmare
Copy link
Member

I think the explicit bounds on the versions of the dependencies helped in this case, so I will also try to fix the example-configs when I have the time.

@noughtmare
Copy link
Member

I found another terrible problem, yi-dynamic-configuration is version 0.16.0 on nixpkgs, and the rest of the yi related packages are still on 0.14 so that causes major breakage, because yi-dynamic-configuration-0.16.0 requires yi-core-0.16.0 which is not included in the nixpkgs. So every dynamic configuration is broken on nix.

@noughtmare
Copy link
Member

Using the example configs from yi-editor/yi#1043 should also work now (except for the dynamic configs).

@thomastjeffery
Copy link
Author

thomastjeffery commented Sep 29, 2017

My first comment was just how to get an example config to build using Nix. Here is how to start hacking on yi with Nix.

Hacking Yi with Nix

Here are the steps to set up a build environment using Nix for hacking Yi:

  1. Get yi source
mkdir yi-source
cd yi-source
git clone https://github.com/yi-editor/yi
git clone https://github.com/yi-rope
  1. Make a default.nix for every yi library
cd yi

for f in yi-*
do
    cd $f
    nix-shell -p cabal2nix --command "cabal2nix . > default.nix"
    cd ..
done

cd ../yi-rope

nix-shell -p cabal2nix --command "cabal2nix . > default.nix"
  1. Override Nix packages
    There are a few ways to do this. I like to put the following in my `~/.config/nixpkgs/config.nix

Note that I have both yi-editor/yi and yi-editor/yi-rope checked out to ~/yi-source/. Change those two paths accordingly:

let yi-source-root = ~/yi-source/yi;
    yi-rope-source = ~/yi-source/yi-rope;
in
    {
      packageOverrides = pkgs: {
        haskellPackages = pkgs.haskellPackages.override {
          overrides = self: super: {
            yi-core            = self.callPackage (yi-source-root + /yi-core/default.nix) {};
            yi-frontend-vty    = self.callPackage (yi-source-root + /yi-frontend-vty/default.nix) {};
            yi-frontend-pango  = self.callPackage (yi-source-root + /yi-frontend-pango/default.nix) {};
            yi-fuzzy-open      = self.callPackage (yi-source-root + /yi-fuzzy-open/default.nix) {};
            yi-ireader         = self.callPackage (yi-source-root + /yi-ireader/default.nix) {};
            yi-keymap-cua      = self.callPackage (yi-source-root + /yi-keymap-cua/default.nix) {};
            yi-keymap-emacs    = self.callPackage (yi-source-root + /yi-keymap-emacs/default.nix) {};
            yi-keymap-vim      = self.callPackage (yi-source-root + /yi-keymap-vim/default.nix) {};
            yi-language        = self.callPackage (yi-source-root + /yi-language/default.nix) {};
            yi-misc-modes      = self.callPackage (yi-source-root + /yi-misc-modes/default.nix) {};
            yi-mode-haskell    = self.callPackage (yi-source-root + /yi-mode-haskell/default.nix) {};
            yi-mode-javascript = self.callPackage (yi-source-root + /yi-mode-javascript/default.nix) {};
            yi-snippet         = self.callPackage (yi-source-root + /yi-snippet/default.nix) {};
            yi-rope            = self.callPackage (yi-rope-source + /default.nix) {};
          };
        };
      };
    }

Now you should be able to build yi like usual.

To test this, you can type

nix-shell -p yi

and Nix will build the default configuration from your newly overridden packages, resulting in a shell with your new yi in its path.

You can also build your config just like before, but now Nix will use your overridden packages.

@noughtmare
Copy link
Member

It should probably also be mentioned that the *.cabal files need to be generated with hpack.

Also you could probably override the packages in the .nix file of your own config instead of in the global config.nix file.

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

No branches or pull requests

2 participants