~radicle-link/dev

lil gitd fixes v2 PROPOSED

Changes from v1

* Moved example config files to bins/example-systemd-config

Published-At: rad:git:hnrkxafojjsz4m55qxbwigh1z8sdt7mai81gy on 
    seed: hydtac74mgo8xeh34cy7tmzzfejcybmxgfyawhnb4zj8wxxo4qckgh@seed.lnk.network:8799
    peer ID: hydjhd8q9nkoxzkpddhcuue9xzpfr4bn6d44fo1f4q1japwm4brhh6
Published-At: https://github.com/alexjg/radicle-link/tree/patches/lil-gitd-fixes/v2

Alex Good (3):
  Make lnk home argument for gitd optional
  Add logging to `lnk-exe`
  Add examples of systemd config

 bins/Cargo.lock                              |  1 +
 bins/example-systemd-config/README.md        | 68 ++++++++++++++++++++
 bins/example-systemd-config/lnk-gitd.service |  6 ++
 bins/example-systemd-config/lnk-gitd.socket  |  6 ++
 cli/gitd-lib/src/args.rs                     |  6 +-
 cli/lnk-exe/Cargo.toml                       |  6 +-
 cli/lnk-exe/src/cli/main.rs                  |  2 +
 7 files changed, 91 insertions(+), 4 deletions(-)
 create mode 100644 bins/example-systemd-config/README.md
 create mode 100644 bins/example-systemd-config/lnk-gitd.service
 create mode 100644 bins/example-systemd-config/lnk-gitd.socket

-- 
2.36.1
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~radicle-link/dev/patches/33207/mbox | git am -3
Learn more about email & git

[PATCH v2 1/3] Make lnk home argument for gitd optional Export this patch

Make the lnk-home argument optional so that by default lnk-gitd uses
the `LnkHome::ProjectDirs`.

Signed-off-by: Alex Good <alex@memoryandthought.me>
---
 cli/gitd-lib/src/args.rs | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/cli/gitd-lib/src/args.rs b/cli/gitd-lib/src/args.rs
index 705debb0..2ec4d966 100644
--- a/cli/gitd-lib/src/args.rs
+++ b/cli/gitd-lib/src/args.rs
@@ -19,8 +19,8 @@ use crate::{

#[derive(Debug, Parser)]
pub struct Args {
    /// The path to use `LNK_HOME`.
    pub lnk_home: PathBuf,
    /// The path to use as `LNK_HOME`, if not set defaults to ProjectDirs.
    pub lnk_home: Option<PathBuf>,
    #[clap(short)]
    /// The socket address to start the gitd server on.
    pub addr: Option<SocketAddr>,
@@ -61,7 +61,7 @@ impl Args {
        self,
        spawner: Arc<link_async::Spawner>,
    ) -> Result<Config<BoxedSigner>, Error> {
        let home = LnkHome::Root(self.lnk_home);
        let home = self.lnk_home.map(LnkHome::Root).unwrap_or(LnkHome::ProjectDirs);
        let profile = Profile::from_home(&home, None)?;
        let signer = spawner
            .blocking({
-- 
2.36.1

[PATCH v2 2/3] Add logging to `lnk-exe` Export this patch

Signed-off-by: Alex Good <alex@memoryandthought.me>
---
 bins/Cargo.lock             | 1 +
 cli/lnk-exe/Cargo.toml      | 6 +++++-
 cli/lnk-exe/src/cli/main.rs | 2 ++
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/bins/Cargo.lock b/bins/Cargo.lock
index 97d715ef..6ab3de18 100644
--- a/bins/Cargo.lock
@@ -2302,6 +2302,7 @@ dependencies = [
 "lnk-sync",
 "lnk-thrussh-agent",
 "tokio",
 "tracing-subscriber",
]

[[package]]
diff --git a/cli/lnk-exe/Cargo.toml b/cli/lnk-exe/Cargo.toml
index c974c895..76849293 100644
--- a/cli/lnk-exe/Cargo.toml
+++ b/cli/lnk-exe/Cargo.toml
@@ -37,4 +37,8 @@ default-features = false

[dependencies.tokio]
version = "1.17"
features = ["rt"]
\ No newline at end of file
features = ["rt"]

[dependencies.tracing-subscriber]
version = "0.3.0"
features = ["std", "env-filter", "fmt"]
diff --git a/cli/lnk-exe/src/cli/main.rs b/cli/lnk-exe/src/cli/main.rs
index 05c8e95b..c64580ab 100644
--- a/cli/lnk-exe/src/cli/main.rs
+++ b/cli/lnk-exe/src/cli/main.rs
@@ -10,6 +10,8 @@ use super::args::{self, Args};
pub fn main() -> anyhow::Result<()> {
    let Args { global, command } = Args::parse();

    tracing_subscriber::fmt::init();

    // TODO: provide Runtime trait in lnk-clib to allow different runtimes
    let runtime = tokio::runtime::Builder::new_current_thread()
        .thread_name("lnk")
-- 
2.36.1

[PATCH v2 3/3] Add examples of systemd config Export this patch

Add some very simple example unit files and a README explaining how to
use them.

Signed-off-by: Alex Good <alex@memoryandthought.me>
---
 bins/example-systemd-config/README.md        | 68 ++++++++++++++++++++
 bins/example-systemd-config/lnk-gitd.service |  6 ++
 bins/example-systemd-config/lnk-gitd.socket  |  6 ++
 3 files changed, 80 insertions(+)
 create mode 100644 bins/example-systemd-config/README.md
 create mode 100644 bins/example-systemd-config/lnk-gitd.service
 create mode 100644 bins/example-systemd-config/lnk-gitd.socket

diff --git a/bins/example-systemd-config/README.md b/bins/example-systemd-config/README.md
new file mode 100644
index 00000000..e16f34a6
--- /dev/null
@@ -0,0 +1,68 @@
Here's how to get a simple lnk setup up and running on linux using systemd.

## Build and install the CLI tools

```
cd bins
cargo install --path lnk-gitd
cargo install --path lnk
```

## Setup your local identity

```
# create a profile
lnk profile create
# create your person identity, record the `urn` field of the resulting JSON
lnk identities person create --payload '{"name": "<your display name>"}'
lnk identities local set --urn <the urn from above>
```

## Add your seeds

Modify `$XDG_CONFIG_DIR/.radicle-link/<profile ID>/seeds`, add the following
line:

```
<your seed peer ID>@<address>:<port>
```

Note that the active profile can be found with `lnk profile get`


## Create the unit files

Copy `example-systemd-config/lnk-gitd.service` to `$XDG_CONFIG_DIR/user`. Modify
it so that the `<your lnk-gitd>` points at the location of the `lnk-gitd` you
installed above (probably `$HOME/.cargo/bin/lnk-gitd`).

Copy `example-systemd-config/lnk-gitd.socket` to `$XDG_CONFIG_DIR/user`, modify
the port in `ListenStream` to be wherever you want the git server to run.

Finally, enable the socket with `systemctl --user enable lnk-gitd.socket`


## Clone a project and mess around and add remote config

```
lnk clone --urn <some project>
cd <project name>
```

You'll need to update the project config to point `rad://` urls at `lnk-gitd`.
Put the following lines in `.git/config`

```
[url "ssh://127.0.0.1:9987/rad:git:"]
    insteadOf = "rad://"
```

Note that you can't currently put this in `~/.gitconfig` as it messes up `lnk
clone`.


## Off you go

Now you can push and pull from your monorepo via `git push rad`. Currently you
will need to add remotes for each other peer you want to work, this will be
fixed once we have updated `lnk sync` to update include files.
diff --git a/bins/example-systemd-config/lnk-gitd.service b/bins/example-systemd-config/lnk-gitd.service
new file mode 100644
index 00000000..eb9999ec
--- /dev/null
@@ -0,0 +1,6 @@
[Unit]
Description=lnk git daemon

[Service]
ExecStart=<your lnk-gitd> --linger-timeout 10000 --push-seeds --fetch-seeds
Environment=RUST_LOG=info
diff --git a/bins/example-systemd-config/lnk-gitd.socket b/bins/example-systemd-config/lnk-gitd.socket
new file mode 100644
index 00000000..dca23f54
--- /dev/null
@@ -0,0 +1,6 @@
[Socket]
ListenStream=127.0.0.1:9987
FileDescriptorName=ssh

[Install]
WantedBy=sockets.target
-- 
2.36.1