Comments (2)
Implementation note:
This could be generalized to arbitrary variants of the flake configuration.
- move this to flake-parts https://github.com/hercules-ci/hercules-ci-agent/blob/master/variants.nix
- add cross compilation option for setting Nixpkgs
buildPlatform
(settingcrossSystem
is wrong imo) - add renaming functions and options to control the copying of attributes from the otherwise invisible
variants.<x>.packages.<y>
topackages."${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.
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
(settingcrossSystem
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)
- Provide a way to easily run doc tests HOT 1
- Explicitly pass default nixpkgs to mkFlake
- Document, how to declare packages only for concrete system
- perSystem.packages cannot be used with recursive packages HOT 1
- NixOS options not 1:1 available HOT 2
- nixosConfigurations example does not invoke nixosConfigurations HOT 2
- infinite recursion when `self` assigned to option HOT 6
- Add `templates` to `flake` HOT 2
- Infinite recursion error when unknown option is set HOT 3
- nix flake show broken HOT 2
- Set `_file` and `_class` for modules defined under `flake.modules.${className}.${moduleName}` HOT 1
- How to define a custom flake attribute for a reusable module HOT 2
- Attribute set is expected to be unique HOT 2
- Generate nixosConfigurations HOT 1
- Per system option with a different name? HOT 4
- Flakestry releases HOT 2
- Q: How to correctly implement a home-manager? HOT 1
- Do we really need nixpkgs in inputs instead of the lightweight nix-community/nixpkgs.lib? HOT 2
- `flake-parts` doesn't evaluate. HOT 3
- Declaring per-system functions as flake outputs HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flake-parts.