cleaned up building of webfiles
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -1263,7 +1263,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "mize"
|
||||
version = "0.1.1"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"axum-extra",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "mize"
|
||||
version = "0.1.1"
|
||||
version = "0.0.0"
|
||||
edition = "2021"
|
||||
license = "GPL-3.0"
|
||||
description = 'A strongly typed "filesystem" for the age of connectivity.'
|
||||
|
||||
15
flake.lock
generated
15
flake.lock
generated
@@ -62,17 +62,14 @@
|
||||
"mize_modules": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1725110866,
|
||||
"narHash": "sha256-pwbO+IPT6hxQ4orfVftqWnei6k5NvgdgXiLWC7E39zc=",
|
||||
"owner": "c2vi",
|
||||
"repo": "mize-modules",
|
||||
"rev": "3fc5c4a1faba733790a22b22dc795238d569d508",
|
||||
"type": "github"
|
||||
"lastModified": 1725174598,
|
||||
"narHash": "sha256-jB5YUArfAiwYwZ7qLwWMHCAY4DMWmLp7F3hzEG5mezk=",
|
||||
"path": "/home/me/work/modules",
|
||||
"type": "path"
|
||||
},
|
||||
"original": {
|
||||
"owner": "c2vi",
|
||||
"repo": "mize-modules",
|
||||
"type": "github"
|
||||
"path": "/home/me/work/modules",
|
||||
"type": "path"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
|
||||
@@ -53,7 +53,10 @@ in {
|
||||
|
||||
osCrane = osCrane;
|
||||
|
||||
webfiles = pkgs.callPackage ./webfiles.nix { inherit inputs nixpkgs self osCrane defaultMizeConfig mize_modules; };
|
||||
webfiles = pkgs.callPackage ./webfiles.nix {
|
||||
inherit inputs nixpkgs self osCrane defaultMizeConfig mize_modules;
|
||||
localSystem = system;
|
||||
};
|
||||
|
||||
default = osCrane.buildPackage {
|
||||
src = "${self}";
|
||||
|
||||
96
webfiles.nix
96
webfiles.nix
@@ -4,11 +4,12 @@
|
||||
, self
|
||||
, defaultMizeConfig
|
||||
, mize_modules
|
||||
, localSystem
|
||||
, ...
|
||||
}:
|
||||
let
|
||||
|
||||
# build all modules
|
||||
# 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;
|
||||
@@ -24,26 +25,10 @@ let
|
||||
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);
|
||||
|
||||
buildModule = path: (pkgs.callPackage path {
|
||||
craneLib = osCrane;
|
||||
toolchain_version = toolchain_version_string;
|
||||
});
|
||||
module_drv_list = map buildModule module_list;
|
||||
|
||||
test2 = builtins.trace "list: ${module_drv_list}" "hi";
|
||||
test = builtins.trace "last: ${pkgs.lib.lists.last module_drv_list}" test2;
|
||||
|
||||
webfilesBuildPhase = module_drv: ''
|
||||
echo got module: ${module_drv.name}
|
||||
hash=$(echo ${module_drv.selector_string} | sha256sum | cut -c -32)
|
||||
mkdir -p $out/mize/dist/$hash
|
||||
cp -r ${module_drv}/* $out/mize/dist/$hash
|
||||
echo '${module_drv.selector_string}' > $out/mize/dist/$hash/selector_string
|
||||
'';
|
||||
|
||||
toolchain_version_drv = pkgs.stdenv.mkDerivation {
|
||||
name = "toolchain_version_drv";
|
||||
@@ -58,25 +43,75 @@ let
|
||||
exit 0
|
||||
'';
|
||||
};
|
||||
|
||||
toolchain_version_string = pkgs.lib.strings.removeSuffix "\n" (builtins.readFile "${toolchain_version_drv}/rustc-version");
|
||||
|
||||
main = osCrane.buildPackage {
|
||||
src = "${self}";
|
||||
cargoExtraArgs = "--bin mize --features os-target";
|
||||
|
||||
|
||||
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; });
|
||||
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;
|
||||
|
||||
# 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
|
||||
'';
|
||||
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_mizes = map buildMizeForSystem systems;
|
||||
|
||||
in
|
||||
|
||||
stdenv.mkDerivation {
|
||||
@@ -86,15 +121,14 @@ stdenv.mkDerivation {
|
||||
# so that /bin/sh does not get patched to a nix store path in victorinix-s
|
||||
dontPatchShebangs = true;
|
||||
|
||||
buildPhase = ''
|
||||
buildPhase = "";
|
||||
|
||||
InstallPhase = ''
|
||||
mkdir -p $out
|
||||
mkdir -p $out/mize
|
||||
mkdir -p $out/mize/dist
|
||||
|
||||
mkdir -p $out/mize/x86_64-linux-gnu
|
||||
cp -r ${main}/bin/mize $out/mize/x86_64-linux-gnu/mize
|
||||
|
||||
'' + pkgs.lib.concatStringsSep "\n" (map webfilesBuildPhase module_drv_list);
|
||||
'' + pkgs.lib.concatStringsSep "\n" (map mkInstallPhase list_of_mizes);
|
||||
|
||||
|
||||
nativeBuildInputs = [
|
||||
|
||||
Reference in New Issue
Block a user