diff --git a/deploy b/deploy old mode 100644 new mode 100755 index bdcb6d3..a0d0e22 --- a/deploy +++ b/deploy @@ -8,14 +8,16 @@ then echo doneeeeeeeeeeeeeee echo path: $path - scp -r acern:$path/* ocih:host/webserver/webfiles + #scp -r acern:$path/* ocih:host/webserver/webfiles + rsync -rv $path/* ocih:host/webserver/webfiles --rsync-path="sudo rsync" else path=$(nix build .#webfiles -L -v --print-out-paths $@) echo doneeeeeeeeeeeeeee echo path: $path - scp -r $path/* ocih:host/webserver/webfiles + #scp -r $path/* ocih:host/webserver/webfiles + rsync -rv $path/* ocih:host/webserver/webfiles --rsync-path="sudo rsync" fi diff --git a/flake.lock b/flake.lock index 814a2f3..876023c 100644 --- a/flake.lock +++ b/flake.lock @@ -59,6 +59,22 @@ "type": "github" } }, + "mize_modules": { + "flake": false, + "locked": { + "lastModified": 1725110866, + "narHash": "sha256-pwbO+IPT6hxQ4orfVftqWnei6k5NvgdgXiLWC7E39zc=", + "owner": "c2vi", + "repo": "mize-modules", + "rev": "3fc5c4a1faba733790a22b22dc795238d569d508", + "type": "github" + }, + "original": { + "owner": "c2vi", + "repo": "mize-modules", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1703637592, @@ -80,6 +96,7 @@ "crane": "crane", "fenix": "fenix", "flake-utils": "flake-utils", + "mize_modules": "mize_modules", "nixpkgs": "nixpkgs" } }, diff --git a/flake.nix b/flake.nix index 2698565..003bb79 100644 --- a/flake.nix +++ b/flake.nix @@ -13,9 +13,14 @@ inputs.nixpkgs.follows = "nixpkgs"; }; + mize_modules = { + url = "github:c2vi/mize-modules"; + flake = false; + }; + flake-utils.url = "github:numtide/flake-utils"; }; - outputs = { self, flake-utils, nixpkgs, fenix, crane, ... }@inputs: flake-utils.lib.eachDefaultSystem (system: + outputs = { self, flake-utils, nixpkgs, fenix, crane, mize_modules, ... }@inputs: flake-utils.lib.eachDefaultSystem (system: ############################## LET BINDINGS ############################## let @@ -34,17 +39,27 @@ let CARGO_BUILD_TARGET = "wasm32-unknown-unknown"; }); + defaultMizeConfig = { + config = { + namespace = "mize.buildtime.ns"; + module_url = "c2vi.dev"; + }; + }; + in { ############################## PACKAGES ############################## - webfiles = pkgs.callPackage ./webfiles.nix { inherit inputs nixpkgs self; }; + packages = { - packages.default = osCrane.buildPackage { - src = "${self}"; - cargoExtraArgs = "--bin mize --features os-binary"; - }; + osCrane = osCrane; + + webfiles = pkgs.callPackage ./webfiles.nix { inherit inputs nixpkgs self osCrane defaultMizeConfig mize_modules; }; + + default = osCrane.buildPackage { + src = "${self}"; + cargoExtraArgs = "--bin mize --features os-target"; + }; - packages = rec { wasm = wasmCrane.buildPackage { src = "${self}"; CARGO_BUILD_TARGET = "wasm32-unknown-unknown"; @@ -94,6 +109,11 @@ in { lldb gdb ]; + MIZE_BUILD_CONFIG = pkgs.writeTextFile { + name = "vic-build-config"; + text = builtins.toJSON defaultMizeConfig; + }; + shellHook = '' export MIZE_CONFIG_FILE=${self}/test-config.toml ''; diff --git a/src/core/instance/mod.rs b/src/core/instance/mod.rs index eb02d9f..55ed609 100644 --- a/src/core/instance/mod.rs +++ b/src/core/instance/mod.rs @@ -43,6 +43,8 @@ pub mod module; static MSG_CHANNEL_SIZE: usize = 200; +static BUILD_TIME_CONFIG: &str = include_str!(std::env!("MIZE_BUILD_CONFIG")); + /// The Instance type is the heart of the mize system #[derive(Clone)] pub struct Instance { @@ -141,6 +143,10 @@ impl Instance { fn init(&mut self) -> MizeResult<()> { + // load the config from build time + let config = ItemData::from_toml(BUILD_TIME_CONFIG)?; + self.set_blocking("0", config); + // platform specific init code crate::platform::any::instance_init(self); @@ -166,7 +172,7 @@ impl Instance { let mut instance = Instance::empty()?; - instance.set_blocking("0", config.clone()); + instance.set_blocking("0", config); instance.init()?; diff --git a/src/core/item.rs b/src/core/item.rs index 879b2c1..9e948d2 100644 --- a/src/core/item.rs +++ b/src/core/item.rs @@ -1,4 +1,5 @@ use tracing::{debug, error, info, instrument, trace, warn, Instrument}; +use serde::Deserialize; use serde::Serialize; use core::fmt; use std::fmt::Debug; @@ -148,6 +149,16 @@ impl ItemData { ItemData(CborValue::Null) } + pub fn from_toml(toml_string: &str) -> MizeResult { + + let toml_deserializer = toml::Deserializer::new(&toml_string); + + let value = CborValue::deserialize(toml_deserializer) + .mize_result_msg(format!("Could not deserialize the toml string: {}", &toml_string))?; + + return Ok(value.into_item_data()); + } + pub fn from_string>(into_string: S) -> ItemData { let string = into_string.into(); let data = CborValue::Text(string); diff --git a/src/platform/os/mod.rs b/src/platform/os/mod.rs index 13dea17..02866aa 100644 --- a/src/platform/os/mod.rs +++ b/src/platform/os/mod.rs @@ -188,12 +188,9 @@ pub fn config_from_file(file_path: String) -> MizeResult { let toml_string = fs::read_to_string(&file_path) .mize_result_msg(format!("Could not read file {} as mize config", &file_path))?; - let toml_deserializer = toml::Deserializer::new(&toml_string.as_str()); + let item_data = ItemData::from_toml(toml_string.as_str())?; - let config = CborValue::deserialize(toml_deserializer) - .mize_result_msg(format!("Could not deserialize the content of MIZE_CONFIG_FILE at {}", &file_path))?; - - return Ok(config.into_item_data()); + return Ok(item_data); } fn config_from_string(config_string: String) -> MizeResult { diff --git a/webfiles.nix b/webfiles.nix index 5b075dc..26b44ce 100644 --- a/webfiles.nix +++ b/webfiles.nix @@ -1,9 +1,83 @@ { stdenv , pkgs -, ... }: +, osCrane +, self +, defaultMizeConfig +, mize_modules +, ... +}: let -in + # build all modules + 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); + + 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"; + 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"); + + main = osCrane.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; }); + }; + + # 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 stdenv.mkDerivation { name = "mize-webfiles"; @@ -14,7 +88,14 @@ stdenv.mkDerivation { buildPhase = '' 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); + nativeBuildInputs = [ ];