I have a simple flake like
{
description = "Simple Flake";
nixConfig = {
extra-substituters = [
# Nix community's cache server
"https://nix-community.cachix.org"
];
extra-trusted-public-keys = [
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
];
};
inputs = {
# Nixpkgs (stuff for the system.)
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11";
# Nixpkgs (unstable stuff for certain packages.)
# Also see the 'unstable-packages' overlay at 'overlays/default.nix'.
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
};
outputs =
{
self,
nixpkgs,
...
}@inputs:
let
inherit (self) outputs;
# Supported systems for your flake packages, shell, etc.
systems = [ "aarch64-linux" "x86_64-linux" "aarch64-darwin" ];
# This is a function that generates an attribute by calling a function you
# pass to it, with each system as an argument
forAllSystems = nixpkgs.lib.genAttrs systems;
packages = forAllSystems (
system:
let
pkgs = (import inputs.nixpkgs-unstable) {
system = system;
crossSystem = "x86_64-unknown-linux-musl"; // This build with musl but is incorrect here.
};
in
{
mypackage = pkgs.xz;
}
);
in
{
inherit
packages
;
};
}
I am trying to figure out a solution to basically set libc to musl
on a certain condition:
- In CI I want to run
nix build ".#mypackage
but withmusl
instead ofglibc
.
Questions:
-
Is there a global way to influence
nix
to build withmusl
. From outside,nix.conf
, or env variables? -
How would I instantiate a separate
pkgsMusl
for thesystem
argument inforAllSystems
such that I can `nix build “.#musl.mypackage”:in { mypackage = pkgs.xz; musl.mypackge = pkgsMusl.xz; }
With this I however always need
musl.
infront of everything. With such a solution I also need that to launchnix develop ".#musl.default"
etc, which is cumbersome. Is there a better way?