Skip to content

Commit

Permalink
Merge pull request #567 from kachick/podman-mount
Browse files Browse the repository at this point in the history
Mount Ubuntu volumes to a container on podman-remote which connects to a podman-machine in another WSL2 instance


Resolves #564
Resolves #563
Updates #499

Initially, I tried to resolve the problem with SSH and rclone mount.
Next, I switched to applying the `/mnt/wsl/instances/` path for that.
The second method looks good to me, but I am keeping rclone era for now. That is useful for non-WSL environments and cloud sync.
  • Loading branch information
kachick authored Apr 12, 2024
2 parents 53c9c8d + 243e889 commit fbe653e
Show file tree
Hide file tree
Showing 9 changed files with 314 additions and 177 deletions.
2 changes: 1 addition & 1 deletion Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ args = [
'-b',
'backup',
'--flake',
'.#kachick',
'.#${@}',
]

[tasks.ci-dev]
Expand Down
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
Personal dotfiles that can be placed in the public repository\
Also known as [盆栽(bonsai)](https://en.wikipedia.org/wiki/Bonsai) 🌳

## For visitors

If you are using the [podman](https://podman.io/), You can test the pre-built [container-image](containers) as follows.

```bash
bash <(curl -fsSL https://raw.githubusercontent.com/kachick/dotfiles/main/containers/sandbox-with-ghcr.bash) latest
```

For local use, replace `s/PRESONA/user/` in following sections may fit.

## Installation - Linux(Ubuntu), Darwin

1. Install [Nix](https://nixos.org/) package manager with [DeterminateSystems/nix-installer](https://github.com/DeterminateSystems/nix-installer).
Expand All @@ -24,9 +34,9 @@ Also known as [盆栽(bonsai)](https://en.wikipedia.org/wiki/Bonsai) 🌳
```bash
bash
```
1. Install [home-manager](https://github.com/nix-community/home-manager) and dotfiles
1. Apply dotfiles for each use
```bash
nix run 'github:kachick/dotfiles#home-manager' -- switch -b backup --flake 'github:kachick/dotfiles#kachick'
nix run 'github:kachick/dotfiles#home-manager' -- switch -b backup --flake 'github:kachick/dotfiles#PERSONA'
```

## Installation - Windows
Expand All @@ -38,13 +48,7 @@ Read [the tips](config/windows/README.md) and CI
If you are developing this repository, the simple reactivation is as follows.

```bash
makers apply
```

If you are using the [podman](https://podman.io/), You can test the pre-built [container-image](containers) as follows.

```bash
bash <(curl -fsSL https://raw.githubusercontent.com/kachick/dotfiles/main/containers/sandbox-with-ghcr.bash) latest
makers apply PERSONA
```

Using podmain may require to install some dependencies without Nix
Expand Down
4 changes: 2 additions & 2 deletions cmd/wsl-init/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

// Exists for remember https://github.com/kachick/dotfiles/pull/264#discussion_r1289600371
func mustActivateSystemDOnWSL() {
func mustActivateSystemdOnWSL() {
path := filepath.Join("etc", "wsl.conf")

const systemdEnablingEntry = `[boot]
Expand Down Expand Up @@ -72,5 +72,5 @@ func main() {
log.Fatalf("Looks executed on non WSL systems: %s", unameStr)
}

mustActivateSystemDOnWSL()
mustActivateSystemdOnWSL()
}
81 changes: 81 additions & 0 deletions config/windows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,87 @@ winget install --exact --id RedHat.Podman-Desktop

And create the new podman-machine-default

## How mount project volumes in podman-remote

Track the [official discussion](https://github.com/containers/podman/discussions/13537), but there are no simple solutions for now.\
This repository provides a mount based solution, mount from another instance as /mnt/wsl/..., then podman-machine also can access there.

1. Ubuntu: Activate the home-manager with `--flake .#wsl`.
2. Look the [definitions](../../home-manager/wsl.nix), it includes how to mount with systemd.
3. podman-machine: Make sure podman-machine can read there `ls /mnt/wsl/instances/ubuntu22/home`
4. Ubuntu: `cdg project_path`
5. Ubuntu: `podman run -v /mnt/wsl/instances/ubuntu22/"$(pwd)":/workdir -it ghcr.io/ruby/ruby:master-dev-76732b3e7b42d23290cd96cd695b2373172c8a43-jammy`

## How SSH login to podman-machine from another WSL instance like default Ubuntu?

### WSL - Ubuntu

Get pubkey

```bash
cat ~/.ssh/id_ed25519.pub | clip.exe
```

### WSL - podman-machine

Register the Ubuntu pubkey

```bash
vi ~/.ssh/authorized_keys
```

### Host - Windows

Get podman-machine port number

```pwsh
podman system connection list | Select-String 'ssh://\w+@[^:]+:(\d+)' | % { $_.Matches.Groups[1].Value }
```

### WSL - Ubuntu

You can login with the port number, for example 53061

```bash
ssh user@localhost -p 53061
```

## How mount client volume with podman-remote

After SSH setup as above steps

In WSL - Ubuntu

```bash
rclone config create podman-machine sftp host=localhost port=53061 publickey=~/.ssh/id_ed25519.pub user=user
# Make sure the connection
rclone lsd podman-machine:/home/user

z project_path
rclone mount --daemon "podman-machine:repos/$(basename "$(pwd)")" .

# If you want to unmount, use specific command instead of kill the background job
#
# Linux
fusermount -u /path/to/local/mount
# OS X
# umount /path/to/local/mount
```

## How oneshot sync source code for podman-remote

This is just a note, prefer `rclone mount` for easier

After SSH setup as above steps

In WSL - Ubuntu

```bash
z project_path

rclone sync --progress . "podman-machine:repos/$(basename "$(pwd)")"
```

## Why aren't these packages in winget list?

- [micro](https://github.com/zyedidia/micro/issues/2339)
16 changes: 12 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@
};
};

wsl = home-manager.lib.homeManagerConfiguration {
inherit pkgs;
modules = [
./home-manager/kachick.nix
./home-manager/wsl.nix
];
extraSpecialArgs = {
inherit edge-pkgs;
};
};

github-actions = home-manager.lib.homeManagerConfiguration {
inherit pkgs;
modules = [
Expand All @@ -87,10 +98,7 @@
inherit pkgs;
modules = [
./home-manager/common.nix
{
# "user" is default in podman-machine-default
home.username = "user";
}
{ home.username = "user"; }
];
extraSpecialArgs = {
inherit edge-pkgs;
Expand Down
9 changes: 7 additions & 2 deletions home-manager/common.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
config,
pkgs,
edge-pkgs,
lib,
...
}:

{
imports = [
./packages.nix
./bash.nix
./zsh.nix
./fish.nix
./gpg.nix
./ssh.nix
./git.nix
./darwin.nix # Omit needless parts for Linux in the file
./darwin.nix
];

# home.username = "<UPDATE_ME_IN_FLAKE>";
Expand Down Expand Up @@ -62,6 +62,11 @@
# Put executable for temporary use
"${config.xdg.dataHome}/tmpbin"
];

packages = import ./packages.nix {
inherit pkgs;
inherit edge-pkgs;
};
};

# https://github.com/nix-community/home-manager/issues/605
Expand Down
Loading

0 comments on commit fbe653e

Please sign in to comment.