made mizeLib in lib.nix and cross compiling support
This commit is contained in:
23
flake.lock
generated
23
flake.lock
generated
@@ -94,7 +94,8 @@
|
||||
"fenix": "fenix",
|
||||
"flake-utils": "flake-utils",
|
||||
"mize_modules": "mize_modules",
|
||||
"nixpkgs": "nixpkgs"
|
||||
"nixpkgs": "nixpkgs",
|
||||
"rust-overlay": "rust-overlay"
|
||||
}
|
||||
},
|
||||
"rust-analyzer-src": {
|
||||
@@ -114,6 +115,26 @@
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"rust-overlay": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1725157860,
|
||||
"narHash": "sha256-DhqyM7XJYKj+WAEaYwMtXaYX66tA+lOd31sd5QkxLDM=",
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"rev": "1fd72e343c6890f695243a37b367a1e3b90a49ee",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
|
||||
18
flake.nix
18
flake.nix
@@ -13,6 +13,11 @@
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
rust-overlay = {
|
||||
url = "github:oxalica/rust-overlay";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
mize_modules = {
|
||||
url = "github:c2vi/mize-modules";
|
||||
flake = false;
|
||||
@@ -20,7 +25,7 @@
|
||||
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
};
|
||||
outputs = { self, flake-utils, nixpkgs, fenix, crane, mize_modules, ... }@inputs: flake-utils.lib.eachDefaultSystem (system:
|
||||
outputs = { self, flake-utils, nixpkgs, fenix, crane, mize_modules, rust-overlay, ... }@inputs: flake-utils.lib.eachDefaultSystem (system:
|
||||
|
||||
############################## LET BINDINGS ##############################
|
||||
let
|
||||
@@ -46,6 +51,12 @@ let
|
||||
};
|
||||
};
|
||||
|
||||
mizeLib = import ./lib.nix {
|
||||
inherit inputs nixpkgs self osCrane defaultMizeConfig mize_modules;
|
||||
inherit rust-overlay crane;
|
||||
localSystem = system;
|
||||
};
|
||||
|
||||
in {
|
||||
############################## PACKAGES ##############################
|
||||
|
||||
@@ -53,9 +64,8 @@ in {
|
||||
|
||||
osCrane = osCrane;
|
||||
|
||||
webfiles = pkgs.callPackage ./webfiles.nix {
|
||||
inherit inputs nixpkgs self osCrane defaultMizeConfig mize_modules;
|
||||
localSystem = system;
|
||||
webfiles = pkgs.callPackage ./webfiles.nix {
|
||||
inherit (mizeLib) buildMizeForSystem mkInstallPhase;
|
||||
};
|
||||
|
||||
default = osCrane.buildPackage {
|
||||
|
||||
133
lib.nix
Normal file
133
lib.nix
Normal file
@@ -0,0 +1,133 @@
|
||||
{ stdenv
|
||||
, pkgs
|
||||
, osCrane
|
||||
, self
|
||||
, defaultMizeConfig
|
||||
, mize_modules
|
||||
, localSystem
|
||||
, nixpkgs
|
||||
, rust-overlay
|
||||
, crane
|
||||
, ...
|
||||
}:
|
||||
rec {
|
||||
# get a list of all modules, that have a mize_module.nix in their folder
|
||||
module_list_drv = pkgs.stdenv.mkDerivation {
|
||||
name = "mize_module_list";
|
||||
dontUnpack = true;
|
||||
configurePhase = "";
|
||||
buildPhase = ''
|
||||
mkdir -p $out
|
||||
touch $out/modules_to_build
|
||||
|
||||
for d in ${mize_modules}/modules/*; do
|
||||
[[ -f $d/mize_module.nix ]] && echo "$d/mize_module.nix" >> $out/modules_to_build
|
||||
done
|
||||
|
||||
exit 0
|
||||
'';
|
||||
};
|
||||
module_list_string = builtins.readFile "${module_list_drv}/modules_to_build";
|
||||
module_list = pkgs.lib.lists.remove "" (pkgs.lib.strings.splitString "\n" module_list_string);
|
||||
|
||||
|
||||
|
||||
toolchain_version_drv = pkgs.stdenv.mkDerivation {
|
||||
name = "toolchain_version_drv";
|
||||
dontUnpack = true;
|
||||
configurePhase = "";
|
||||
buildPhase = ''
|
||||
mkdir -p $out
|
||||
touch $out/rustc-version
|
||||
|
||||
${osCrane.rustc}/bin/rustc --version > $out/rustc-version
|
||||
|
||||
exit 0
|
||||
'';
|
||||
};
|
||||
toolchain_version_string = pkgs.lib.strings.removeSuffix "\n" (builtins.readFile "${toolchain_version_drv}/rustc-version");
|
||||
|
||||
|
||||
|
||||
buildMizeForSystem = system: let
|
||||
crossSystem = (if builtins.isString system then pkgs.lib.systems.mkSystemFrommString system else system)
|
||||
// {
|
||||
name = if crossSystem.vendor == "unknown"
|
||||
then "${crossSystem.cpu.name}-${crossSystem.kernel.name}-${crossSystem.abi.name}"
|
||||
else "${crossSystem.cpu.name}-${crossSystem.vendor.name}-${crossSystem.kernel.name}-${crossSystem.abi.name}";
|
||||
nameFull = "${crossSystem.cpu.name}-${crossSystem.vendor.name}-${crossSystem.kernel.name}-${crossSystem.abi.name}";
|
||||
};
|
||||
pkgsCross = import nixpkgs { inherit crossSystem localSystem; overlays = [ rust-overlay ]; };
|
||||
|
||||
craneLib = (crane.mkLib pkgsCross).overrideToolchain (p: p.rust-bin.stable.latest.default);
|
||||
|
||||
mkSelString = attrs: builtins.toJSON (attrs // {
|
||||
toolchain_version = toolchain_version_string;
|
||||
mize_version = main.version;
|
||||
});
|
||||
|
||||
mkMizeModule = attrs: {
|
||||
a = builtins.error "todo!()";
|
||||
};
|
||||
|
||||
mkMizeRustModule = attrs: craneLib.buildPackage attrs // {
|
||||
cargoExtraArgs = "--target ${crossSystem.nameFull} " + attrs.cargoExtraArgs or "";
|
||||
"CARGO_TARGET_${pkgsCross.lib.strings.toUpper crossSystem.nameFull}_LINKER" = "${pkgsCross.stdenv.cc.targetPrefix}cc";
|
||||
HOST_CC = "${pkgsCross.stdenv.cc.nativePrefix}cc";
|
||||
TARGET_CC = "${pkgsCross.stdenv.cc.targetPrefix}cc";
|
||||
};
|
||||
|
||||
buildModule = path: (pkgsCross.callPackage path {
|
||||
inherit mkSelString craneLib;
|
||||
inherit mkMizeModule mkMizeRustModule;
|
||||
toolchain_version = toolchain_version_string;
|
||||
mize_version = main.version;
|
||||
});
|
||||
|
||||
main = craneLib.buildPackage {
|
||||
src = "${self}";
|
||||
cargoExtraArgs = "--bin mize --features os-target";
|
||||
|
||||
MIZE_BUILD_CONFIG = pkgs.writeTextFile {
|
||||
name = "mize-build-config";
|
||||
text = builtins.toJSON (defaultMizeConfig // {
|
||||
toolchain_version = toolchain_version_string;
|
||||
mize_version = main.version;
|
||||
});
|
||||
};
|
||||
# patch the interpreter to run on most linux-gnu distros
|
||||
postBuild = ''
|
||||
patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 /build/source/target/release/mize
|
||||
'';
|
||||
};
|
||||
in rec {
|
||||
inherit main;
|
||||
|
||||
system = crossSystem;
|
||||
|
||||
modules = pkgs.lib.lists.flatten (map buildModule module_list);
|
||||
};
|
||||
|
||||
|
||||
|
||||
mkInstallPhase = mize: ''
|
||||
# install mize
|
||||
mkdir -p $out/mize/${mize.system.name}
|
||||
cp ${mize.main}/bin/mize $out/mize/${mize.system.name}/
|
||||
|
||||
# intall the modules
|
||||
${mkModulesInstallPhase mize.modules}
|
||||
'';
|
||||
|
||||
mkModulesInstallPhase = modules: pkgs.lib.concatStringsSep "\n" (map (module: ''
|
||||
echo got module: ${module.name}
|
||||
hash=$(echo ${module.selector_string} | sha256sum | cut -c -32)
|
||||
mkdir -p $out/mize/dist/$hash
|
||||
cp -r ${module}/* $out/mize/dist/$hash
|
||||
echo '${module.selector_string}' > $out/mize/dist/$hash/selector_string
|
||||
'')) modules;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
115
webfiles.nix
115
webfiles.nix
@@ -1,119 +1,16 @@
|
||||
{ stdenv
|
||||
, pkgs
|
||||
, osCrane
|
||||
, self
|
||||
, defaultMizeConfig
|
||||
, mize_modules
|
||||
, localSystem
|
||||
, mkInstallPhase
|
||||
, buildMizeForSystem
|
||||
, ...
|
||||
}:
|
||||
let
|
||||
}: let
|
||||
|
||||
# get a list of all modules, that have a mize_module.nix in their folder
|
||||
module_list_drv = pkgs.stdenv.mkDerivation {
|
||||
name = "mize_module_list";
|
||||
dontUnpack = true;
|
||||
configurePhase = "";
|
||||
buildPhase = ''
|
||||
mkdir -p $out
|
||||
touch $out/modules_to_build
|
||||
|
||||
for d in ${mize_modules}/modules/*; do
|
||||
[[ -f $d/mize_module.nix ]] && echo "$d/mize_module.nix" >> $out/modules_to_build
|
||||
done
|
||||
|
||||
exit 0
|
||||
'';
|
||||
};
|
||||
module_list_string = builtins.readFile "${module_list_drv}/modules_to_build";
|
||||
module_list = pkgs.lib.lists.remove "" (pkgs.lib.strings.splitString "\n" module_list_string);
|
||||
|
||||
|
||||
|
||||
toolchain_version_drv = pkgs.stdenv.mkDerivation {
|
||||
name = "toolchain_version_drv";
|
||||
dontUnpack = true;
|
||||
configurePhase = "";
|
||||
buildPhase = ''
|
||||
mkdir -p $out
|
||||
touch $out/rustc-version
|
||||
|
||||
${osCrane.rustc}/bin/rustc --version > $out/rustc-version
|
||||
|
||||
exit 0
|
||||
'';
|
||||
};
|
||||
toolchain_version_string = pkgs.lib.strings.removeSuffix "\n" (builtins.readFile "${toolchain_version_drv}/rustc-version");
|
||||
|
||||
|
||||
|
||||
buildMizeForSystem = system: let
|
||||
crossSystem = if builtins.isString system then { config = system; } else system;
|
||||
craneLib = osCrane;
|
||||
|
||||
mkSelString = attrs: builtins.toJSON (attrs // {
|
||||
toolchain_version = toolchain_version_string;
|
||||
mize_version = main.version;
|
||||
});
|
||||
|
||||
buildModule = path: (pkgs.callPackage path {
|
||||
inherit mkSelString;
|
||||
craneLib = osCrane;
|
||||
toolchain_version = toolchain_version_string;
|
||||
});
|
||||
|
||||
main = craneLib.buildPackage {
|
||||
src = "${self}";
|
||||
cargoExtraArgs = "--bin mize --features os-target";
|
||||
|
||||
MIZE_BUILD_CONFIG = pkgs.writeTextFile {
|
||||
name = "mize-build-config";
|
||||
text = builtins.toJSON (defaultMizeConfig // {
|
||||
toolchain_version = toolchain_version_string;
|
||||
mize_version = main.version;
|
||||
});
|
||||
};
|
||||
# patch the interpreter to run on most linux-gnu distros
|
||||
postBuild = ''
|
||||
patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 /build/source/target/release/mize
|
||||
'';
|
||||
};
|
||||
in rec {
|
||||
inherit main;
|
||||
|
||||
system = crossSystem;
|
||||
|
||||
modules = map buildModule module_list;
|
||||
};
|
||||
|
||||
|
||||
|
||||
mkInstallPhase = mize: ''
|
||||
# install mize
|
||||
mkdir -p $out/mize/${mize.system.config}
|
||||
cp ${mize.main}/bin/mize $out/mize/${mize.system.config}/
|
||||
|
||||
# intall the modules
|
||||
${mkModulesInstallPhase mize.modules}
|
||||
'';
|
||||
|
||||
mkModulesInstallPhase = modules: pkgs.lib.concatStringsSep "\n" (map (module: ''
|
||||
echo got module: ${module.name}
|
||||
hash=$(echo ${module.selector_string} | sha256sum | cut -c -32)
|
||||
mkdir -p $out/mize/dist/$hash
|
||||
cp -r ${module}/* $out/mize/dist/$hash
|
||||
echo '${module.selector_string}' > $out/mize/dist/$hash/selector_string
|
||||
'')) modules;
|
||||
|
||||
|
||||
|
||||
# list of systems, we build mize for
|
||||
systems = [ "x86_64-linux-gnu" ];
|
||||
# list of systems, we build mize for for webfiles
|
||||
systems = [ "x86_64-linux" "aarch64-linux" "wasm32" ];
|
||||
|
||||
list_of_mizes = map buildMizeForSystem systems;
|
||||
|
||||
in
|
||||
|
||||
in
|
||||
stdenv.mkDerivation {
|
||||
name = "mize-webfiles";
|
||||
dontUnpack = true;
|
||||
|
||||
Reference in New Issue
Block a user