Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(syschdemd): exit code #140

Merged
merged 4 commits into from
Nov 13, 2022
Merged

fix(syschdemd): exit code #140

merged 4 commits into from
Nov 13, 2022

Conversation

nzbr
Copy link
Member

@nzbr nzbr commented Oct 8, 2022

This fixes #138, by using systemd-run instead of machinectl, but breaks systemd user sessions and dbus

@K900: If we can get those to work with systemd-run, it will probably work with native systemd as well (because I think this is what MS is using as well)

@nzbr nzbr added the bug Something isn't working label Oct 8, 2022
@K900
Copy link
Contributor

K900 commented Oct 8, 2022

No, they're spawning a shell as a child of /init, so it's not even in the right slice.

@nzbr
Copy link
Member Author

nzbr commented Oct 12, 2022

I wanted to find out, how distrod gets around that, and the answer seems to be that they didn't:

PS C:\Users\nzbr> wsl -d Distrod systemctl --user
Failed to connect to bus: No such file or directory

@nzbr
Copy link
Member Author

nzbr commented Oct 12, 2022

genie seems to use machinectl

@nzbr
Copy link
Member Author

nzbr commented Oct 12, 2022

A possible solution would be to use machinectl when launching the default shell and systemd-run when a command is specified. I'd rather find a way to always use systemd-run though

@nzbr nzbr added the hacktoberfest-accepted This labes is used to supply people with free t-shirts label Oct 18, 2022
@nzbr nzbr mentioned this pull request Oct 27, 2022
2 tasks
@nzbr
Copy link
Member Author

nzbr commented Oct 30, 2022

image
I got it to work!

@K900 We might be able to use the same approach (using runuser) for native systemd. That would mean having a wrapper script as the root shell again, but it'd be much simpler because we don't need the namespace

@SuperSandro2000
Copy link
Member

@nzbr what do you think about adding me as a collaborator to this repo?

@nzbr
Copy link
Member Author

nzbr commented Nov 10, 2022

@nzbr what do you think about adding me as a collaborator to this repo?

Given that you're pretty active on here, that's probably a good idea - same goes for @K900
Unfortunately, I don't have the necessary permission to do that though

@SuperSandro2000
Copy link
Member

SuperSandro2000 commented Nov 11, 2022

Starts now without crashing.

ssh-agent is still broken because of SSH_AUTH_SOCK=/mnt/wslg/runtime-dir/ssh-agent but NixOS placing the socket in the default location.

systemctl status diff between before and after this PR:

I think TERMINFO_DIRS is set wrong by wezterm.

Otherwise things seem to work.

--- before	2022-11-11 18:06:50.116889800 +0100
+++ after	2022-11-11 18:07:26.142133500 +0100
@@ -2,28 +2,47 @@
     State: running
      Jobs: 0 queued
    Failed: 0 units
-    Since: Fri 2022-11-11 18:06:28 CET; 22s ago
+    Since: Fri 2022-11-11 18:07:19 CET; 6s ago
    CGroup: /
            ├─user.slice 
            │ └─user-1000.slice 
            │   ├─[email protected] 
            │   │ ├─app.slice 
            │   │ │ ├─ssh-agent.service 
-           │   │ │ │ └─ 70 /nix/store/hfmwjjkz0c2p9ggcqw22rgnhx0jjm84z-openssh-9.1p1/bin/ssh-agent -a /run/user/1000/ssh-agent
+           │   │ │ │ └─ 69 /nix/store/hfmwjjkz0c2p9ggcqw22rgnhx0jjm84z-openssh-9.1p1/bin/ssh-agent -a /run/user/1000/ssh-agent
            │   │ │ └─auto-fix-vscode-server.service 
            │   │ │   ├─  63 /nix/store/y0g1mvsr6vygr61f9znljik9kl0x0inc-bash-5.1-p16/bin/bash /nix/store/ngx73rfq5mx9s4zkgjjnypciizq4n7aa-auto-fix-vscode-server.sh
-           │   │ │   ├─ 116 /nix/store/y0g1mvsr6vygr61f9znljik9kl0x0inc-bash-5.1-p16/bin/bash /nix/store/ngx73rfq5mx9s4zkgjjnypciizq4n7aa-auto-fix-vscode-server.sh
-           │   │ │   └─ 117 inotifywait -q -m -e CREATE,ISDIR -e DELETE_SELF --format %w%f:%e /home/sandro/.vscode-server/bin
+           │   │ │   ├─ 118 /nix/store/y0g1mvsr6vygr61f9znljik9kl0x0inc-bash-5.1-p16/bin/bash /nix/store/ngx73rfq5mx9s4zkgjjnypciizq4n7aa-auto-fix-vscode-server.sh
+           │   │ │   └─ 119 inotifywait -q -m -e CREATE,ISDIR -e DELETE_SELF --format %w%f:%e /home/sandro/.vscode-server/bin
            │   │ └─init.scope 
            │   │   ├─ 56 /nix/store/isg9b516rmlf6ri8c29jm9ibl1kg0sa7-systemd-249.12/lib/systemd/systemd --user
            │   │   └─ 57 (sd-pam)
            │   └─session-c1.scope 
-           │     ├─  54 /run/current-system/sw/bin/bash
-           │     ├─  68 (sd-pam)
-           │     ├─  93 /nix/store/4wnc0503iawwc2166jfwkf0zmd7wr0ps-cod-0.1.0/bin/cod api forked-daemon 87
+           │     ├─  54 /nix/store/15y79343wxnalk8629v9vg63a31pbwk7-util-linux-2.38.1-bin/bin/runuser -u sandro -- /bin/sh -c declare -x COLORTERM="truecolor"
+declare -x DISPLAY=":0"
+declare -x HOSTTYPE="x86_64"
+declare -x LANG="en_US.UTF-8"
+declare -x NAME="francium"
+declare -x OLDPWD
+declare -x PATH="/run/wrappers/bin:/nix/store/xq4g38m5ppg78z7bzfxyy2s8ii693k74-coreutils-9.1/bin:/nix/store/vdmbj6w77pg29fn77ndn659ngbxjsq4w-daemonize-1.7.8/bin:/nix/store/4xynblhic6sq4paq2ra4ql535yyvracs-glibc-2.35-163-bin/bin:/nix/store/sqypvzmrsl8hil564xfk8n5w51gq47h0-gnugrep-3.7/bin:/nix/store/z5qg6m93yv2wsij772rsljah3ahw1m8b-systemd-251.5/bin:/nix/store/15y79343wxnalk8629v9vg63a31pbwk7-util-linux-2.38.1-bin/bin:/nix/store/ldaflixlmv5dills5dq960i6m1s9pzq0-which-2.21/bin:/nix/store/53ssjlp0w2dsbifdg9jbykypq05205c2-nixos-wsl-systemd-wrapper/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib"
+declare -x PULSE_SERVER="/mnt/wslg/PulseServer"
+declare -x PWD="/mnt/c/Users/user"
+declare -x SHLVL="1"
+declare -x TERM="wezterm"
+declare -x TERMINFO_DIRS="/home/user/.nix-profile/share/terminfo"
+declare -x TERM_PROGRAM="WezTerm"
+declare -x TERM_PROGRAM_VERSION="20220905-102802-7d4b8249"
+declare -x WAYLAND_DISPLAY="wayland-0"
+declare -x WSL2_GUI_APPS_ENABLED="1"
+declare -x WSLENV="TERMINFO_DIRS:TERM:COLORTERM:TERM_PROGRAM:TERM_PROGRAM_VERSION"
+declare -x WSL_DISTRO_NAME="NixOS"
+declare -x WSL_INTEROP="/run/WSL/6_interop"
+declare -x XDG_RUNTIME_DIR="/mnt/wslg/runtime-dir"; source /etc/set-environment; exec /run/current-system/sw/bin/bash
+           │     ├─  67 /run/current-system/sw/bin/bash
+           │     ├─  93 /nix/store/4wnc0503iawwc2166jfwkf0zmd7wr0ps-cod-0.1.0/bin/cod api forked-daemon 86
            │     ├─ 131 /run/current-system/sw/bin/bash
-           │     ├─ 134 /nix/store/5ysxr04vk1v2arpyl6brd0xzlig5sds8-gitstatus-1.5.4/bin/gitstatusd -G v1.5.4 --parent-pid=54 --num-threads=8 --max-num-staged=1 --max-num-unstaged=1 --max-num-conflicted=1 --max-num-untracked=1 --dirty-max-index-size=-1 --repo-ttl-seconds=3600
-           │     └─ 348 systemctl status
+           │     ├─ 134 /nix/store/5ysxr04vk1v2arpyl6brd0xzlig5sds8-gitstatus-1.5.4/bin/gitstatusd -G v1.5.4 --parent-pid=67 --num-threads=8 --max-num-staged=1 --max-num-unstaged=1 --max-num-conflicted=1 --max-num-untracked=1 --dirty-max-index-size=-1 --repo-ttl-seconds=3600
+           │     └─ 237 systemctl status
            ├─init.scope 
            │ └─ 1 systemd
            └─system.slice 

@SuperSandro2000
Copy link
Member

SuperSandro2000 commented Nov 11, 2022

git gpg signing is broken with those changes. Not sure why and I am not looking forward to debugging it.

@nzbr
Copy link
Member Author

nzbr commented Nov 12, 2022

I don't have SSH_AUTH_SOCK set, because I don't use the SSH agent. Was it working before the patch?

@SuperSandro2000
Copy link
Member

No, but I hoped it would work now. Let me debug that this later.

@nzbr nzbr mentioned this pull request Nov 13, 2022
@nzbr nzbr merged commit e9e8d01 into nix-community:main Nov 13, 2022
@nzbr nzbr deleted the exit-code branch November 13, 2022 23:47
psvo added a commit to psvo/NixOS-WSL that referenced this pull request Nov 21, 2022
* upstream/main:
  Fix syschdemd exit code (nix-community#140)
  update remaining references to wsl.automountPath (nix-community#158)
  Update flakes (nix-community#124)
  wsl.conf: proper option types (nix-community#153)
  Fix eval by disabling module completely when wsl.enable = false (nix-community#151)
  NixOS users.users.<user> attribute name and .name can differ (nix-community#147)
  switch nixpkgs.overlays to inline overlay (nix-community#150)
  feat: native systemd support (nix-community#134)
  remove boot.isContainer (nix-community#145)
  Do not import minimal profile by default (nix-community#144)
@nzbr nzbr changed the title Fix syschdemd exit code fix(syschdemd): exit code Jul 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working hacktoberfest-accepted This labes is used to supply people with free t-shirts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

wsl.exe always returns 0 exit code
3 participants