ldsalkjdsalkjdsalkj
This commit is contained in:
32
pkgs/mk-nspawn-setup/default.nix
Normal file
32
pkgs/mk-nspawn-setup/default.nix
Normal file
@@ -0,0 +1,32 @@
|
||||
{ lib
|
||||
, pkgs
|
||||
}:
|
||||
|
||||
# this assumes github:tfc/nspawn-nixos nspawn-tarball.nix is mixed into it
|
||||
nixosConfiguration:
|
||||
|
||||
let
|
||||
|
||||
hostname = nixosConfiguration.config.networking.hostName;
|
||||
inherit (nixosConfiguration.config.nixpkgs) system;
|
||||
|
||||
setup = pkgs.substituteAll {
|
||||
src = ./setup-nspawn.sh;
|
||||
isExecutable = true;
|
||||
inherit hostname;
|
||||
};
|
||||
|
||||
inherit (nixosConfiguration.config.system.build) tarball;
|
||||
|
||||
in
|
||||
|
||||
pkgs.runCommandNoCC "nspawn-setup-${hostname}.sh" {
|
||||
nativeBuildInputs = with pkgs; [ makeself ];
|
||||
} ''
|
||||
mkdir -p archive/
|
||||
ln -s ${setup} archive/setup.sh
|
||||
ln -s ${tarball}/tarball/nixos-system-${system}.tar.xz archive/nixos-${hostname}.tar.xz
|
||||
|
||||
echo tarball: ${tarball}
|
||||
makeself --nocomp --follow archive/ $out "setup-nixos-nspawn-${hostname}" ./setup.sh
|
||||
''
|
||||
45
pkgs/mk-nspawn-setup/setup-nspawn.sh
Normal file
45
pkgs/mk-nspawn-setup/setup-nspawn.sh
Normal file
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# TODO: assert correct system
|
||||
|
||||
NSPAWN_NAME=nixos-@hostname@
|
||||
TARBALL=./nixos-@hostname@.tar.xz
|
||||
|
||||
test $(id -u) -eq 0 || {
|
||||
>&2 echo you must run this as root
|
||||
exit 1
|
||||
}
|
||||
|
||||
if ! >/dev/null command -v systemd-nspawn; then
|
||||
>&2 echo "systemd-nspawn" not found in PATH
|
||||
>&2 echo consider installing 'systemd-container'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! >/dev/null command -v machinectl; then
|
||||
>&2 echo "machinectl" not found in PATH
|
||||
>&2 echo consider installing 'systemd-container'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
set -ex
|
||||
|
||||
machinectl remove "$NSPAWN_NAME" || true # TODO: is this interactive?
|
||||
#machinectl pull-tar "https://github.com/tfc/nspawn-nixos/releases/download/v1.0/nixos-system-x86_64-linux.tar.xz" "$NSPAWN_NAME" --verify=no
|
||||
machinectl import-tar "$TARBALL" "$NSPAWN_NAME"
|
||||
|
||||
# use host network
|
||||
mkdir -p /etc/systemd/nspawn
|
||||
tee /etc/systemd/nspawn/"$NSPAWN_NAME".nspawn <<"EOF"
|
||||
[Network]
|
||||
VirtualEthernet=no
|
||||
EOF
|
||||
|
||||
NSPAWN_NAME=nixos-brumlebasse
|
||||
machinectl enable "$NSPAWN_NAME"
|
||||
machinectl start "$NSPAWN_NAME"
|
||||
|
||||
echo Please set a root password
|
||||
machinectl shell "$NSPAWN_NAME" /usr/bin/env passwd
|
||||
|
||||
machinectl status "$NSPAWN_NAME"
|
||||
Reference in New Issue
Block a user