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

Snippet: how to mix two nixpkgs #178

Open
domenkozar opened this issue Sep 7, 2021 · 10 comments
Open

Snippet: how to mix two nixpkgs #178

domenkozar opened this issue Sep 7, 2021 · 10 comments

Comments

@domenkozar
Copy link
Member

A good example is mixing aarch64-darwin and x86_64-darwin. Another one is using unstable and stable to get different versions of software.

@pecigonzalo
Copy link

FWIW, I use the following:

❯ cat ~/.config/nixpkgs/overlays/m1.nix
self: super:
let
  pkgs_x86_64 = import <nixpkgs> { localSystem = "x86_64-darwin"; overlays = []; };
in
{
  neovim-unwrapped = pkgs_x86_64.neovim-unwrapped;
  dhall = pkgs_x86_64.dhall;
  elmPackages.elm = pkgs_x86_64.elmPackages.elm;
  packer = pkgs_x86_64.packer;
  ansible = pkgs_x86_64.ansible;
  ansible-lint = pkgs_x86_64.ansible-lint;
}

@evanrelf
Copy link

@pecigonzalo Did you need to configure anything else in /etc/nix/nix.conf or elsewhere to get x86_64-darwin builds working?

I'm getting this error when trying to build x86-64 packages:

error: a 'x86_64-darwin' with features {} is required to build '/nix/store/...', but I am a 'aarch64-darwin' with features {benchmark, big-parallel, nixos-test}

I tried adding extra-platforms = x86_64-darwin to /etc/nix/nix.conf but it doesn't seem to have any effect. Do I need to add ssh://localhost as a builder or something?

@pecigonzalo
Copy link

My nix.conf has this

system = aarch64-darwin
extra-platforms = aarch64-darwin x86_64-darwin

I did not add any special builders or anything

@evanrelf
Copy link

I figured it out: you have to specify --system x86_64-darwin at the command-line and then it builds fine.

Also I added aarch64-darwin to extra-platforms like you mentioned, for whatever it's worth.

@pecigonzalo
Copy link

@evanrelf to what command line? Im not passing such argument. Maybe you hav a different workflow?

@evanrelf
Copy link

Yeah sorry, I wasn't clear. I have a different workflow. I'm nix-building a pkgs.buildEnv derivation, and it was failing on the x86-64 builds until I re-ran the build with the new system.

@kubukoz
Copy link
Member

kubukoz commented Dec 1, 2021

Does anyone have this as an overlay using only its inputs? I guess it might be impossible, but I'd like to do something roughly like

final : prev : {
  elm = prev.x64_64-darwin.prev;
}

if possible.

@evanrelf
Copy link

evanrelf commented Dec 1, 2021

@kubukoz You can technically do this:

pkgsFinal: pkgsPrev: {
  x86_64-darwin = import pkgsFinal.path {
    system = "x86_64-darwin";
    inherit (pkgsFinal) config overlays;
  };
}

But it gets tricky very quickly. Using pkgsFinal.overlays in particular is dangerous because it causes stuff like this to infinitely recurse:

pkgsFinal: pkgsPrev: {
  # This is bad!
  hello = pkgsFinal.x86_64-darwin.hello;
}

hello in this overlay is referring to itself because the x86_64-darwin package set is using this overlay!

If you pick a different name, it's okay:

pkgsFinal: pkgsPrev: {
  hello-x86_64 = pkgsFinal.x86_64-darwin.hello;
}

Or if you just use the package in the definition of another:

pkgsFinal: pkgsPrev: {
  env = pkgsPrev.buildEnv {
    name = "my-env";
    paths = with pkgsFinal; [ hello ];
  };
}

@evanrelf
Copy link

evanrelf commented Dec 1, 2021

@kubukoz For a more concrete/practical example, I do something similar to this in my dotfiles.

  • Here I define the overlay to provide packages for other systems.
  • Here I swap out broken aarch64-darwin packages with x86_64-darwin packages in my Apple silicon laptop config.

@kubukoz
Copy link
Member

kubukoz commented Dec 1, 2021

That's exactly what I was looking for, I think :) thank you very much. Getting mine in the morning so I'll play around then 😂

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

4 participants