Add create command

This commit is contained in:
Louis Bettens 2021-08-04 17:56:49 +02:00
parent fbc8b279a6
commit 4aaef75fa7
5 changed files with 51 additions and 5 deletions

36
miniguest/create.bash Normal file
View File

@ -0,0 +1,36 @@
source create_arg.bash
name="$_arg_guest_name"
set_color_red=$'\e[1m\e[31m'
reset_color=$'\e(B\e[m'
case "${_arg_hypervisor:?}" in
libvirt)
cat <<EOF
# Create $name using:
virt-install \\
--connect qemu:///system \\
-n $name --os-variant nixos-unstable \\
--memory 1536 \\
--disk none \\
--import \\
--boot kernel=/etc/miniguests/$name/kernel,initrd=$guests_dir/$name/initrd \\
--filesystem /nix/store,nix-store,readonly=yes,accessmode=squash \\
--filesystem /etc/miniguests/$name/boot,boot,readonly=yes,accessmode=squash \\
EOF
;;
lxc)
cat <<EOF
#$set_color_red WARNING: make sure root is uid-mapped, otherwise you might experience store corruption in the host!$reset_color
# Create $name using:
lxc-create $name \\
-f extra-config \\
-t local -- \\
-m @lxc_template@/meta.tar.xz \\
-f @lxc_template@/rootfs.tar.xz \\
EOF
;;
esac

View File

@ -0,0 +1,5 @@
# ARG_POSITIONAL_SINGLE(guest-name, name of guest to create)
# ARG_HELP(assist in creatig the guest by configuring the hypervisor)
# ARG_OPTIONAL_SINGLE(hypervisor, t, hypervisor to configure, libvirt)
# ARG_TYPE_GROUP_SET(hypervisors, HYPERVISOR, hypervisor, [libvirt,lxc])
# ARGBASH_GO

View File

@ -25,14 +25,18 @@ nix="$_arg_nix"
source functions.bash
set -- "${_arg_leftovers[@]}" # reset parameters to subcommand arguments
case "${_arg_command:?}" in
install)
source install.bash "${_arg_leftovers[@]}"
source install.bash
;;
upgrade)
source upgrade.bash "${_arg_leftovers[@]}"
source upgrade.bash
;;
remove)
source remove.bash "${_arg_leftovers[@]}"
source remove.bash
;;
create)
source create.bash
;;
esac

View File

@ -16,7 +16,7 @@
# along with Miniguest. If not, see <https://www.gnu.org/licenses/>.
# ARG_POSITIONAL_SINGLE(command, subcommand to run)
# ARG_TYPE_GROUP_SET(commands, COMMAND, command, [install,upgrade,remove,help])
# ARG_TYPE_GROUP_SET(commands, COMMAND, command, [install,upgrade,remove,create,help])
# ARG_OPTIONAL_SINGLE(guests-dir, , directory containing guests profiles, /etc/miniguests)
# ARG_OPTIONAL_SINGLE(nix, , path to the nix binary, @nixFlakes@/bin/nix)
# ARG_LEFTOVERS(subcommand arguments)

View File

@ -17,7 +17,8 @@
stdenvNoCC.mkDerivation {
name = "miniguest";
src = ./.;
inherit bash miniguest-lxc-template nixFlakes;
inherit bash nixFlakes;
lxc_template = miniguest-lxc-template;
nativeBuildInputs = [ argbash makeWrapper ];