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

Linux builder forced to host platform system instead of it's package variant #313784

Closed
loic-roux-404 opened this issue May 22, 2024 · 2 comments
Closed

Comments

@loic-roux-404
Copy link

loic-roux-404 commented May 22, 2024

Describe the bug

A clear and concise description of what the bug is.

Steps To Reproduce

Steps to reproduce the behavior:

  1. On Mac Silicon, Utilizing with nix-darwin, i've the folllowing :
{
    package = pkgs.darwin.linux-builder-x86_64;
}
  1. I always get qemu-system-aarch64 as qemu binary and then an aarch64 linux builder

Expected behavior

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

Add any other context about the problem here.

Notify maintainers

@Enzime

Metadata

 - system: `"aarch64-darwin"`
 - host os: `Darwin 23.5.0, macOS 14.5`
 - multi-user?: `yes`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.21.2`
 - nixpkgs: `/Users/loic/.nix-defexpr/channels/nixpkgs`

Did not find any issues related to this qemu program choice.

nicknovitski added a commit to nicknovitski/nix-darwin that referenced this issue Jun 13, 2024
Before this commit, aarch64 users building the following configuration
would end up with an aarch64-linux builder, while after it, they get the
x86_64-linux builder they expect:
```nix
 nix.linux-builder = {
  enable = true;
  package = pkgs.darwin.linux-builder-x86_64;
};
```

Before, in order to get an x86_64-linux builder, they would have needed
to use this configuration instead:
```nix
 nix.linux-builder = {
  enable = true;
  config.nixpkgs.hostPlatform = "x86_64-linux";
  systems = ["x86_64-linux"];
};
```

The reason for this is that the linux-builder module calls `override` on
the package option, and the `linux-builder-x86_64` package is also
defined using override:
```nix
linux-builder-x86_64 = linux-builder.override {
  modules = [ { nixpkgs.hostPlatform = "x86_64-linux"; } ];
};
```

The module was effectively discarding the `nixpkgs.hostPlatform` option.

Example issue: NixOS/nixpkgs#313784
@nicknovitski
Copy link
Contributor

I think the qemu binary is set correctly in the builders, in this file:

default = if hostPkgs.stdenv.hostPlatform.qemuArch == pkgs.stdenv.hostPlatform.qemuArch then hostPkgs.qemu_kvm else hostPkgs.qemu;

I was also having this problem, and found this issue while looking into it. But I realized the result is being caused by these lines in nix-darwin:

  builderWithOverrides = cfg.package.override {
    modules = [ cfg.config ];
  };

(https://github.com/LnL7/nix-darwin/blob/master/modules/nix/linux-builder.nix#L10-L12)

That looks fine, but the builder package we're trying to use is also created using override!

  linux-builder-x86_64 = self.linux-builder.override {
    modules = [ { nixpkgs.hostPlatform = "x86_64-linux"; } ];
  };

So the override in nix-darwin is overriding the override in nixpkgs, making the resulting package have the default hostPlatform.

You can work around this by setting that value in your nix darwin config, like this:

 nix.linux-builder = {
  enable = true;
  package = pkgs.darwin.linux-builder-x86_64; # This line currently doesn't matter! But see my linked PR.
  systems = ["x86_64-linux"]; # set this to make nix on your laptop send the right kinds of derivations to the builder
  config.nixpkgs.hostPlatform = "x86_64-linux"; # This is what nix-darwin is removing, and what you need to add back 
};

I've opened a pull request to make this work the way we expected it to: LnL7/nix-darwin#974

Thank you for this issue, it confirmed that I wasn't the only person having this problem, and led me to find the cause. 😄

nicknovitski added a commit to nicknovitski/nix-darwin that referenced this issue Jun 14, 2024
Before this commit, aarch64 users building the following configuration
would end up with an aarch64-linux builder, while after it, they get the
x86_64-linux builder they expect:
```nix
 nix.linux-builder = {
  enable = true;
  package = pkgs.darwin.linux-builder-x86_64;
};
```

Before, in order to get an x86_64-linux builder, they would have needed
to use this configuration instead:
```nix
 nix.linux-builder = {
  enable = true;
  config.nixpkgs.hostPlatform = "x86_64-linux";
  systems = ["x86_64-linux"];
};
```

The reason for this is that the linux-builder module calls `override` on
the package option, and the `linux-builder-x86_64` package is also
defined using override:
```nix
linux-builder-x86_64 = linux-builder.override {
  modules = [ { nixpkgs.hostPlatform = "x86_64-linux"; } ];
};
```

The module was effectively discarding the `nixpkgs.hostPlatform` option.

Example issue: NixOS/nixpkgs#313784
nicknovitski added a commit to nicknovitski/nix-darwin that referenced this issue Jun 16, 2024
Before this commit, aarch64 users building the following configuration
would end up with an aarch64-linux builder, while after it, they get the
x86_64-linux builder they expect:
```nix
 nix.linux-builder = {
  enable = true;
  package = pkgs.darwin.linux-builder-x86_64;
};
```

Before, in order to get an x86_64-linux builder, they would have needed
to use this configuration instead:
```nix
 nix.linux-builder = {
  enable = true;
  config.nixpkgs.hostPlatform = "x86_64-linux";
  systems = ["x86_64-linux"];
};
```

The reason for this is that the linux-builder module calls `override` on
the package option, and the `linux-builder-x86_64` package is also
defined using override:
```nix
linux-builder-x86_64 = linux-builder.override {
  modules = [ { nixpkgs.hostPlatform = "x86_64-linux"; } ];
};
```

The module was effectively discarding the `nixpkgs.hostPlatform` option.

Example issue: NixOS/nixpkgs#313784
kamushadenes pushed a commit to kamushadenes/nix-darwin that referenced this issue Jul 8, 2024
Before this commit, aarch64 users building the following configuration
would end up with an aarch64-linux builder, while after it, they get the
x86_64-linux builder they expect:
```nix
 nix.linux-builder = {
  enable = true;
  package = pkgs.darwin.linux-builder-x86_64;
};
```

Before, in order to get an x86_64-linux builder, they would have needed
to use this configuration instead:
```nix
 nix.linux-builder = {
  enable = true;
  config.nixpkgs.hostPlatform = "x86_64-linux";
  systems = ["x86_64-linux"];
};
```

The reason for this is that the linux-builder module calls `override` on
the package option, and the `linux-builder-x86_64` package is also
defined using override:
```nix
linux-builder-x86_64 = linux-builder.override {
  modules = [ { nixpkgs.hostPlatform = "x86_64-linux"; } ];
};
```

The module was effectively discarding the `nixpkgs.hostPlatform` option.

Example issue: NixOS/nixpkgs#313784
@loic-roux-404
Copy link
Author

Thanks a lot !

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

No branches or pull requests

2 participants