Skip to content

Commit

Permalink
WSL: Codchi tray autostart
Browse files Browse the repository at this point in the history
WSL: windows terminal fragments (solves #14)
Updated Logo in MSIX
  • Loading branch information
htngr committed Nov 19, 2024
1 parent 04a183e commit b6145f0
Show file tree
Hide file tree
Showing 17 changed files with 142 additions and 30 deletions.
3 changes: 3 additions & 0 deletions build/msix/AppxManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
<uap5:ExecutionAlias Alias="codchi.exe" />
</uap5:AppExecutionAlias>
</uap5:Extension>
<desktop:Extension Category="windows.startupTask" Executable="codchi.exe" EntryPoint="Windows.FullTrustApplication">
<desktop:StartupTask TaskId="codchi-tray" Enabled="true" DisplayName="Codchi Tray Icon" />
</desktop:Extension>
</Extensions>
</Application>
</Applications>
Expand Down
Binary file modified build/msix/Assets/StoreLogo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added build/msix/Assets/favicon.ico
Binary file not shown.
Binary file modified build/msix/Assets/favicon150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified build/msix/Assets/favicon44.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified build/msix/Assets/favicon44.targetsize-44_altform-unplated.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 10 additions & 2 deletions codchi/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions codchi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ windows = { version = "0.58", features = [
] }
wslapi = "0.1.3"
clap_complete_command = { version = "0.6.1", default-features = false }
uuid = { version = "1.11.0", features = ["v5"] }

[build-dependencies]
clap = { version = "4", features = ["derive", "cargo", "string"] }
Expand Down
2 changes: 1 addition & 1 deletion codchi/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ let
'';

CODCHI_WSL_VERSION_MIN = "2.0.14";
CODCHI_WSL_VERSION_MAX = "2.3.24";
CODCHI_WSL_VERSION_MAX = "2.3.26";

};
linux = rec {
Expand Down
11 changes: 10 additions & 1 deletion codchi/src/platform/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ pub trait Host: Sized {
});
}

Self::write_shortcuts(&machine.config.name, desktop_entries.iter())
Self::write_shortcuts(&machine.config.name, desktop_entries.iter())?;
Ok(())
}

fn open_terminal(&self, cmd: &[&str]) -> Result<()>;
Expand Down Expand Up @@ -137,6 +138,14 @@ pub trait Host: Sized {

#[cfg(target_os = "windows")]
fn start_vcxsrv(&self, kill_running: bool) -> Result<()>;

fn post_install(_machine_name: &str) -> Result<()> {
Ok(())
}

fn post_delete(_machine_name: &str) -> Result<()> {
Ok(())
}
}

#[derive(Clone, Debug)]
Expand Down
2 changes: 2 additions & 0 deletions codchi/src/platform/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ git add flake.*

set_progress_status("Updating start menu shortcuts...");
HostImpl::write_machine_shortcuts(self)?;
HostImpl::post_install(&self.config.name)?;

hide_progress();

Expand Down Expand Up @@ -391,6 +392,7 @@ git add flake.*

set_progress_status("Deleting start menu shortcuts...");
HostImpl::delete_shortcuts(&self.config.name)?;
HostImpl::post_delete(&self.config.name)?;

println!("Successfully deleted {}. You might also want to run a garbage collection (`codchi gc`).", self.config.name);

Expand Down
74 changes: 72 additions & 2 deletions codchi/src/platform/windows/host.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
cli::DEBUG,
config::CodchiConfig,
consts,
consts::{self, APP_NAME},
platform::{DesktopEntry, Host},
util::PathExt,
};
Expand Down Expand Up @@ -40,7 +40,7 @@ impl Host for HostImpl {
is_terminal,
} in apps
{
let mut lnk = ShellLink::new(&codchi_exe)?;
let mut lnk = ShellLink::new(codchi_exe.clone())?;
if let Some(ico_path) = icon {
let target = ico_folder.join(format!("{app_name}.ico"));
fs::copy(ico_path, &target)?;
Expand Down Expand Up @@ -166,4 +166,74 @@ impl Host for HostImpl {
terms.iter().map(|(term, _)| term).join(", ")
)
}

fn post_install(machine_name: &str) -> Result<()> {
// write json fragments for windows terminal
{
// from https://learn.microsoft.com/en-us/windows/terminal/json-fragment-extensions#calculating-a-guid-for-a-built-in-profile
let guid = {
use uuid::Uuid;
// Windows Terminal namespace GUID for auto-generated profiles
let terminal_namespace_guid =
Uuid::parse_str("2bde4a90-d05f-401c-9492-e40884ead1d8")?;
let profile_name = consts::machine::machine_name(machine_name);

let utf16le_bytes: Vec<u8> = profile_name
.encode_utf16()
.flat_map(|unit| unit.to_le_bytes()) // little-endian (BOM-less)
.collect();

Uuid::new_v5(&terminal_namespace_guid, &utf16le_bytes)
};
let fragment_dir = get_known_folder_path(KnownFolder::LocalAppData)
.expect("FOLDERID_LocalAppData missing")
.join("Microsoft")
.join("Windows Terminal")
.join("Fragments")
.join(APP_NAME);
fragment_dir.get_or_create()?;

let fragment_path = fragment_dir.join(format!("{machine_name}.json"));

// omit icon for now because if its missing, the fragment doesn't work. Also, after
// each codchi update the icon path changes until the machine is rebuilt
// let codchi_icon = env::current_exe()?
// .parent()
// .context("Failed to access codchi.exe install dir.")?
// .join("Assets")
// .join("favicon150.png");
// let codchi_icon = codchi_icon.display();
// "icon": "{codchi_icon}",

fs::write(
fragment_path,
format!(
r#"{{
"profiles": [
{{
"updates": "{{{guid}}}",
"commandline": "codchi.exe exec {machine_name}",
"name": "Codchi - {machine_name}",
}}
]
}}"#
),
)?;
}

Ok(())
}

fn post_delete(machine_name: &str) -> Result<()> {
get_known_folder_path(KnownFolder::LocalAppData)
.expect("FOLDERID_LocalAppData missing")
.join("Microsoft")
.join("Windows Terminal")
.join("Fragments")
.join(APP_NAME)
.join(format!("{machine_name}.json"))
.remove();

Ok(())
}
}
14 changes: 14 additions & 0 deletions docs/src/docs/config/misc.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,17 @@ By default the time zone is UTC inside a code machine. You can change this via
time.timeZone = "Europe/Berlin";
}
```

## Windows Networking

By default WSL configures the `/etc/hosts` and `/etc/resolv.conf` to match the networking settings of the host. Therefore they can't be generated by NixOS / Codchi. While Windows' DNS settings (through `/etc/resolv.conf`) are often neccessary for a working WSL instance, `/etc/hosts` is overridden by Codchi to enable reproducible IP / Domain configuration.

To override this change these options:
```nix
{
environment.etc = {
hosts.enable = true; # /etc/hosts set by Codchi
"resolv.conf".enable = false; # /etc/hosts set by WSL
};
}
```
42 changes: 21 additions & 21 deletions docs/src/docs/contrib/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,36 @@

- Docs
- [ ] Demo Video
- NixOS options
- [ ] hosts / resolv.conf
- auto update
- update available notification / working auto update

- [ ] Architecture
- [ ] Landing Page

- MVP Features
- [ ] Codchi doctor (periodical check)

- [ ] License
- Bugs
- [ ] shortcuts / terminal fragments win
- update path on every update => autostart codchi tray => run "migration"

- Future
- Custom certs auto adding
- => how to handle inside code machines?
- Announcement Post (Discourse, HN?, Product Hunt?)
- [/] GPU
- WSL:
Terminal integration (#14)
- Docs
- [ ] Internal Docs / Contrib
- [ ] Uninstalling Codchi, Migrating away

- Bugs
- update required with local repos => invalidate nix cache flag?
- (testing: dont prompt)
- Features
- [ ] codchi status on windows is slow
=> move wsl status checking / store container starting to scheduled / time based task
- [ ] `codchi recover` => fs tar export
- [ ] `codchi debug` => machine / store debug shell
- [ ] `codchi export {vmware,virtualbox,qemu,hyperv}`
=> export machine to VM image
=> backup / migrating away
- [ ] (`codchi state export`) => creating a base fs for files like IJ / eclipse config
- [ ] (codchi daemon inside each code machine)
- current bash solution too fragile
=> Does init (secret / config fetching, log reporting)
- [ ] (Custom certs auto adding)
- => how to handle inside code machines?
- [ ] (Linux Wayland support)


- open questions:
- WSL
- what happens if store stops and machines runs?
- how to handle network reset (VcXsrv)?
=> wslg as default?
- LXD
- Wayland support / xwayland?
6 changes: 4 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@
inherit lib;

nixosModules.default = import ./nix/nixos;
nixosModules.codchi = {
nixosModules.codchi = { pkgs, ... }: {
nixpkgs.config.allowUnfree = true;
environment.systemPackages = self.devShells.${system}.default.nativeBuildInputs;
environment.systemPackages = self.devShells.${system}.default.nativeBuildInputs ++ [
pkgs.vscodium
];
# programs.neovim = {
# enable = true;
# package = pkgs.nixvim.makeNixvim (import ./editor.nix);
Expand Down
5 changes: 4 additions & 1 deletion nix/nixos/driver/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ in
environment.variables.NIX_REMOTE = "daemon";
# Setup nix flakes
nix = {
package = pkgs.nixFlakes;
package =
if lib.versionAtLeast config.system.stateVersion "24.11"
then pkgs.nix
else pkgs.nixFlakes;
extraOptions = ''
experimental-features = nix-command flakes
'';
Expand Down

0 comments on commit b6145f0

Please sign in to comment.