-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enter command for integrated user setup + typing + compose refa…
…ctoring + version command for nuspawn meta info + reusing initialization code in envire repo
- Loading branch information
1 parent
25f2ae7
commit 2f91959
Showing
12 changed files
with
242 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
[Network] | ||
VirtualEthernet=no | ||
|
||
[Exec] | ||
Boot=yes | ||
Environment=DISPLAY=:0 | ||
Environment=TERM=xterm-256color | ||
Environment=WAYLAND_DISPLAY=wayland-1 | ||
Environment=XDG_RUNTIME_DIR=/run/user/1000 | ||
SystemCallFilter=add_key keyctl bpf | ||
|
||
[Files] | ||
BindUser=your_user_here | ||
Bind=/home:/home | ||
TemporaryFileSystem=/tmp | ||
Environment=DISPLAY=:0 | ||
Boot=yes | ||
PrivateUsers=yes | ||
Bind=/dev/fuse:/dev/fuse | ||
BindReadOnly=/run/user:/run/user | ||
Bind=/dev/dri:/dev/dri | ||
BindUser=tulili |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use std assert | ||
use machine_manager.nu [machinectl run_container] | ||
|
||
# Enter and setup an nspawn container with your current user | ||
# Requires your container to have a recent version of systemd-userdb if you are binding your current user to the machine | ||
export def --env "main enter" [ | ||
--machinectl (-m) # Use machinectl for operations instead of machinectl | ||
--shadow = true # Copy your user hashed password from /etc/shadow and put it inside the container | ||
--root-user: string = "root" # User with root privileges in the container | ||
--environment (-e): list<string> # Test | ||
--setup-no-bind = false # Sets up the container for usage without binding user | ||
--no-bind = false # Use this if you are having issue with user binding | ||
--bind-dirs = "/home:/home" # Comma separated list of directories bound to the container (e.g.: /home/developer:/opt/dev./home/tulili:/tmp/hosthome) | ||
--user: string # User that will be binded to the container | ||
machine: string # Name of the machine to be logged into | ||
...args: list<string> # Extra arguments to pass to the backend | ||
] { | ||
let user = (if $user != null { $user } else { ($env.USER? | default root) }) | ||
|
||
if not $machinectl { | ||
try { | ||
machinectl stop $machine | ignore | ||
} | ||
(systemd-run | ||
--uid=0 | ||
--gid=0 | ||
-t | ||
-q | ||
-- | ||
'systemd-nspawn' | ||
'-b' | ||
'-M' | ||
$'($machine)' | ||
'--bind=/home:/home' | ||
'--bind=/run/user:/run/user' | ||
'--set-credential=firstboot.locale:C.UTF-8' | ||
'--bind=/dev/dri' | ||
'--bind=/dev/shm' | ||
$'--setenv=DISPLAY=($env.DISPLAY? | default ":0")' | ||
$"--setenv=WAYLAND_DISPLAY=($env.WAYLAND_DISPLAY? | default "wayland-1")" | ||
(if not $no_bind { $"--bind-user=($user)" }) | ||
(if not $no_bind {"-U"}) | ||
) | ||
return | ||
} | ||
machinectl shell $"($user)@($machine)" # Should be pre-configured by init or compose | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
export extern machinectl [ | ||
--verify: string = "no" | ||
...args: string | ||
] | ||
|
||
export extern systemd-nspawn [ | ||
--machine (-M): string | ||
...args: string | ||
] | ||
|
||
export extern systemd-run [ | ||
--uid: number | ||
--gid: number | ||
--pty (-t) | ||
--quiet (-q) | ||
...args: string | ||
] | ||
|
||
export extern "machinectl pull-tar" [url: string, name?: string] | ||
export extern "machinectl pull-raw" [url: string, name?: string] | ||
export extern "machinectl remove" [machine: string] | ||
export extern "machinectl shell" [user_connection: string, ...args: string] | ||
export extern "machinectl read-only" [machine: string, enabled: string] | ||
export extern "machinectl show-image" [machine: string] | ||
export extern "machinectl stop" [machine: string] | ||
|
||
export const CONFIG_EXTENSION = "nspawn" | ||
|
||
# Meant to be used as a way to run a single command at a time in a container using machinectl. | ||
export def run_container [ | ||
--user: string = "root", | ||
--nspawn (-n), | ||
--environment (-e): string = "PATH=/usr/bin:/usr/local/bin:/bin" # Spaced environment variables for /usr/bin/env | ||
--env-binary: path = /usr/bin/env | ||
--shell-binary: path = /bin/sh | ||
machine: string, | ||
...args: string | ||
] { | ||
if not $nspawn { | ||
machinectl start $machine | ||
sleep 1sec | ||
machinectl shell $"($user)@($machine)" $env_binary $environment $shell_binary '-c' ($args | str join " ; ") | ||
} else { | ||
(systemd-run | ||
--uid=0 | ||
--gid=0 | ||
-t | ||
-q | ||
"--" | ||
"systemd-nspawn" | ||
"-M" $machine | ||
$env_binary | ||
$environment | ||
$shell_binary | ||
'-c' ($args | str join " ; ") | ||
) | ||
} | ||
try { machinectl stop $machine | ignore } | ||
} | ||
|
||
# Meant to be used as a way to run a single command at a time in a container using nspawn. | ||
export def nspawn_run_container [ | ||
--user: string = "root", | ||
--environment (-e): string = "PATH=/usr/bin:/usr/local/bin:/bin" # Spaced environment variables for /usr/bin/env | ||
--env-binary: path = /usr/bin/env | ||
--shell-binary: path = /bin/sh | ||
machine: string, | ||
...args: string | ||
] { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
export const NAME = "nuspawn" | ||
export const VERSION = "%VERSION%" | ||
export const GIT_COMMIT = "%GIT_COMMIT%" | ||
export const NSPAWNHUB_KEY_LOCATION = "https://hub.nspawn.org/storage/masterkey.pgp" | ||
export const NSPAWNHUB_STORAGE_ROOT = "https://hub.nspawn.org/storage" | ||
export const NSPAWNHUB_KEY_LOCATION = "https://hub.nspawn.org/storage/masterkey.pgp" | ||
export const MACHINE_STORAGE_PATH = "/var/lib/machines" | ||
export const MACHINE_CONFIG_PATH = "/etc/systemd/nspawn" | ||
export const NUSPAWN_PROFILES_PATH = "/etc/nuspawn/profiles" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.