GithubHelp home page GithubHelp logo

Comments (2)

roberth avatar roberth commented on June 9, 2024

Implementation note:

This could be generalized to arbitrary variants of the flake configuration.

  1. move this to flake-parts https://github.com/hercules-ci/hercules-ci-agent/blob/master/variants.nix
  2. add cross compilation option for setting Nixpkgs buildPlatform (setting crossSystem is wrong imo)
  3. add renaming functions and options to control the copying of attributes from the otherwise invisible variants.<x>.packages.<y> to packages."${x}/${y}"

An alternative solution for adding cross support could be NixOS/nixpkgs#160061.

I am not aware of any documentation regarding cross compilation with flakes. Are you?
I would expect packages in packages.<system> to be runnable on system, as suggested by the nix run behavior. Ultimately Nix is all about outputs, as those are the usable end product. Where the derivation runs is secondary and is abstracted away by the remote builder concept.

That is the nature of cross compilation, but the Nix CLI behavior seems to steer towards a solution that repeats the mistakes of nixos/modules/misc/nixpkgs.nix.

from flake-parts.

ldesgoui avatar ldesgoui commented on June 9, 2024

Hey,

Thanks a lot for the pointers, it did allow me to figure it out, here's how that looks like for now

{ config, inputs, ... }:
let
  rootConfig = config;
in
{
  perSystem = { config, lib, system, moduleType, ... }: {
    options =
      let
        inherit (lib) mkOption types;
      in
      {
        crossSystems = mkOption {
          type = types.listOf types.str;

          default = builtins.filter (c: system != c && config.selectCrossSystem c) rootConfig.systems;
        };

        selectCrossSystem = mkOption {
          type = types.functionTo types.bool;

          default = crossSystem:
            let
              local = lib.systems.elaborate system;
              cross = lib.systems.elaborate crossSystem;
            in
            # Can only build MacOS stuff from MacOS
            (cross.isMacOS -> local.isMacOS)
            # https://github.com/NixOS/nixpkgs/issues/137877
            && (local.isMacOS && local.isAarch64 -> !cross.isLinux)
          ;
        };

        x = mkOption {
          type = types.lazyAttrsOf moduleType;
          default = { };
        };
      };

    config = {
      _module.args.pkgs = lib.mkIf (config ? _module.args.crossSystem)
        (import inputs.nixpkgs {
          inherit system;
          inherit (config._module.args) crossSystem;
        });

      x = lib.mkIf (!(config ? _module.args.crossSystem))
        (lib.genAttrs config.crossSystems (c: { _module.args.crossSystem = c; }));
    };
  };
}

add cross compilation option for setting Nixpkgs buildPlatform (setting crossSystem is wrong imo)

I looked far and wide, that seems to only be a NixOS thing

I am not aware of any documentation regarding cross compilation with flakes [..]

Yeah, this is a philosophical question to which I chose not to find an answer :P
Feels like packages.<system> should be buildable on <system> and apps.<system> should be runnable on <system>, and all package shouldn't implicitly be apps?

As the solution is opinionated and somewhat niche, I'll just close. Feel free to re-open if you'd like

from flake-parts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.