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

nixos: fix cross-compiling by using buildPackages for build-time lndir #142273

Merged
merged 2 commits into from
Oct 23, 2021

Conversation

ju1m
Copy link
Contributor

@ju1m ju1m commented Oct 20, 2021

Motivation for this change

Cross-compiling.

Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • 21.11 Release Notes (or backporting 21.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Oct 20, 2021
@ju1m ju1m added the 6.topic: cross-compilation Building packages on a different platform than they will be used on label Oct 20, 2021
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux labels Oct 20, 2021
@Artturin
Copy link
Member

how to test?

@ju1m
Copy link
Contributor Author

ju1m commented Oct 21, 2021

how to test?

@Artturin, if ${host} is the name of a cross-compiled flake configuration enabling services.xserver, then:

nix -L build .#nixosConfigurations.${host}.config.services.xserver.displayManager.sessionData.desktops

@ju1m
Copy link
Contributor Author

ju1m commented Oct 21, 2021

  • Added another commit for systemd-lib to also use pkgs.buildPackages.xorg.lndir instead of pkgs.xorg.lndir in a runCommand.

Testing looks like:

nix -L build .#nixosConfigurations.${host}.config.environment.etc.'"systemd/system"'.source

@Artturin
Copy link
Member

Could you send a cross compile flake, I haven't used cross compilation with flakes yet

@ju1m ju1m changed the title nixos/display-managers: fix cross-compiling nixos: fix cross-compiling by using buildPackages for build-time lndir Oct 21, 2021
@ju1m
Copy link
Contributor Author

ju1m commented Oct 21, 2021

@Artturin, here's a minimal flake.nix:

{
inputs.nixpkgs.url = "github:NixOS/nixpkgs/4be96dbda035972f60f9e0f386aaec2abd6f1cdb";
outputs = inputs: let
  remoteNixpkgsPatches = [
    {
      meta.description = "nixos: fix cross-compiling by using buildPackages for build-time lndir";
      url = "https://github.com/NixOS/nixpkgs/pull/142273.diff";
      sha256 = "sha256-ZCDQ7SpGhH8JvAwWzdcyrc68RFEWHxxAj0M2+AvEzIg=";
    }
  ];
  originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
  nixpkgs = originPkgs.applyPatches {
    name = "nixpkgs-patched";
    src = inputs.nixpkgs;
    patches = map originPkgs.fetchpatch remoteNixpkgsPatches;
  };
  nixosSystem = import (nixpkgs + "/nixos/lib/eval-config.nix");
  # Uncomment to use a Nixpkgs without remoteNixpkgsPatches
  #nixosSystem = inputs.nixpkgs.lib.nixosSystem;
  in
  {
    nixosConfigurations.nixos = nixosSystem {
      system = "x86_64-linux";
      modules = [
        ({ pkgs, lib, config, ... }: {
          nixpkgs.crossSystem = lib.systems.examples.armv7l-hf-multiplatform;
          services.xserver = {
            enable = true;
            desktopManager.session = [
              { name = "home-manager";
                start = ''
                  ${pkgs.runtimeShell} $HOME/.hm-xsession &
                  waitPID=$!
                '';
                bgSupport = true;
              }
            ];
          };
        })
      ];
    };
  };
}

Test with:

nix -L build .#nixosConfigurations.nixos.config.services.xserver.displayManager.sessionData.desktops

Change nixosSystem if you want to test without the patch.

Note that testing the systemd-lib commit will need you to hack through other stuffs not cross-compiling (like mesa) wanted by:

nix -L build .#nixosConfigurations.nixos.config.environment.etc.'"systemd/system"'.source

Meaning having to disable stuffs or using an overlay to set failing packages to the dummy hello package.

@ju1m ju1m requested a review from suhr October 22, 2021 00:43
@ju1m ju1m mentioned this pull request Oct 22, 2021
12 tasks
@Artturin
Copy link
Member

i added a modified version of your example to https://nixos.wiki/wiki/Nixpkgs/Reviewing_changes#Testing_the_cross-compilation_of_modules

@Artturin Artturin merged commit dfad31d into NixOS:master Oct 23, 2021
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/how-to-try-a-pr/15410/12

@ju1m ju1m deleted the display-managers branch January 4, 2022 01:58
@Artturin Artturin mentioned this pull request May 17, 2022
10 tasks
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/best-pattern-to-include-multiples-patches-prs-to-nixpgs-in-flake-nix/40917/2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: cross-compilation Building packages on a different platform than they will be used on 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants