cleaned up building of webfiles
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -1263,7 +1263,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mize"
|
name = "mize"
|
||||||
version = "0.1.1"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"axum",
|
"axum",
|
||||||
"axum-extra",
|
"axum-extra",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "mize"
|
name = "mize"
|
||||||
version = "0.1.1"
|
version = "0.0.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "GPL-3.0"
|
license = "GPL-3.0"
|
||||||
description = 'A strongly typed "filesystem" for the age of connectivity.'
|
description = 'A strongly typed "filesystem" for the age of connectivity.'
|
||||||
|
|||||||
15
flake.lock
generated
15
flake.lock
generated
@@ -62,17 +62,14 @@
|
|||||||
"mize_modules": {
|
"mize_modules": {
|
||||||
"flake": false,
|
"flake": false,
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1725110866,
|
"lastModified": 1725174598,
|
||||||
"narHash": "sha256-pwbO+IPT6hxQ4orfVftqWnei6k5NvgdgXiLWC7E39zc=",
|
"narHash": "sha256-jB5YUArfAiwYwZ7qLwWMHCAY4DMWmLp7F3hzEG5mezk=",
|
||||||
"owner": "c2vi",
|
"path": "/home/me/work/modules",
|
||||||
"repo": "mize-modules",
|
"type": "path"
|
||||||
"rev": "3fc5c4a1faba733790a22b22dc795238d569d508",
|
|
||||||
"type": "github"
|
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "c2vi",
|
"path": "/home/me/work/modules",
|
||||||
"repo": "mize-modules",
|
"type": "path"
|
||||||
"type": "github"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
|
|||||||
@@ -53,7 +53,10 @@ in {
|
|||||||
|
|
||||||
osCrane = osCrane;
|
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 {
|
default = osCrane.buildPackage {
|
||||||
src = "${self}";
|
src = "${self}";
|
||||||
|
|||||||
96
webfiles.nix
96
webfiles.nix
@@ -4,11 +4,12 @@
|
|||||||
, self
|
, self
|
||||||
, defaultMizeConfig
|
, defaultMizeConfig
|
||||||
, mize_modules
|
, mize_modules
|
||||||
|
, localSystem
|
||||||
, ...
|
, ...
|
||||||
}:
|
}:
|
||||||
let
|
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 {
|
module_list_drv = pkgs.stdenv.mkDerivation {
|
||||||
name = "mize_module_list";
|
name = "mize_module_list";
|
||||||
dontUnpack = true;
|
dontUnpack = true;
|
||||||
@@ -24,26 +25,10 @@ let
|
|||||||
exit 0
|
exit 0
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
module_list_string = builtins.readFile "${module_list_drv}/modules_to_build";
|
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);
|
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 {
|
toolchain_version_drv = pkgs.stdenv.mkDerivation {
|
||||||
name = "toolchain_version_drv";
|
name = "toolchain_version_drv";
|
||||||
@@ -58,25 +43,75 @@ let
|
|||||||
exit 0
|
exit 0
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
toolchain_version_string = pkgs.lib.strings.removeSuffix "\n" (builtins.readFile "${toolchain_version_drv}/rustc-version");
|
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 {
|
MIZE_BUILD_CONFIG = pkgs.writeTextFile {
|
||||||
name = "mize-build-config";
|
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
|
system = crossSystem;
|
||||||
postBuild = ''
|
|
||||||
patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 /build/source/target/release/mize
|
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
|
in
|
||||||
|
|
||||||
stdenv.mkDerivation {
|
stdenv.mkDerivation {
|
||||||
@@ -86,15 +121,14 @@ stdenv.mkDerivation {
|
|||||||
# so that /bin/sh does not get patched to a nix store path in victorinix-s
|
# so that /bin/sh does not get patched to a nix store path in victorinix-s
|
||||||
dontPatchShebangs = true;
|
dontPatchShebangs = true;
|
||||||
|
|
||||||
buildPhase = ''
|
buildPhase = "";
|
||||||
|
|
||||||
|
InstallPhase = ''
|
||||||
mkdir -p $out
|
mkdir -p $out
|
||||||
mkdir -p $out/mize
|
mkdir -p $out/mize
|
||||||
mkdir -p $out/mize/dist
|
mkdir -p $out/mize/dist
|
||||||
|
|
||||||
mkdir -p $out/mize/x86_64-linux-gnu
|
'' + pkgs.lib.concatStringsSep "\n" (map mkInstallPhase list_of_mizes);
|
||||||
cp -r ${main}/bin/mize $out/mize/x86_64-linux-gnu/mize
|
|
||||||
|
|
||||||
'' + pkgs.lib.concatStringsSep "\n" (map webfilesBuildPhase module_drv_list);
|
|
||||||
|
|
||||||
|
|
||||||
nativeBuildInputs = [
|
nativeBuildInputs = [
|
||||||
|
|||||||
Reference in New Issue
Block a user