From 059081865afab59142364fc6c78af29304702a98 Mon Sep 17 00:00:00 2001 From: Tom Barrett Date: Mon, 14 Jun 2021 17:55:29 +0200 Subject: starting out --- config/config.nix | 10 ++++++++++ config/nixos-config | 8 ++++++++ init | 31 +++++++++++++++++++++++++++++++ teardown | 5 +++++ 4 files changed, 54 insertions(+) create mode 100644 config/config.nix create mode 100644 config/nixos-config create mode 100755 init create mode 100755 teardown diff --git a/config/config.nix b/config/config.nix new file mode 100644 index 0000000..498a806 --- /dev/null +++ b/config/config.nix @@ -0,0 +1,10 @@ +{ +packageOverrides = pkgs: with pkgs; { + myPackages = pkgs.buildEnv { + name = "my-packages"; + paths = [ + bc + ]; + }; +}; +} diff --git a/config/nixos-config b/config/nixos-config new file mode 100644 index 0000000..135240d --- /dev/null +++ b/config/nixos-config @@ -0,0 +1,8 @@ +{ config, pkgs, ... }: { + services.sshd.enable = true; + services.nginx = { + enable = true; + user = "user"; + group = "user"; + }; +} diff --git a/init b/init new file mode 100755 index 0000000..8b6eed0 --- /dev/null +++ b/init @@ -0,0 +1,31 @@ +#!/bin/bash +set -e + +lxc launch images:debian/buster "$1" +USER=user + +EXE="lxc exec $1 -- bash -c" + +$EXE "useradd -m $USER" +$EXE "groupadd nixbld" +$EXE "usermod -a -G nixbld $USER" +$EXE "mkdir -m 0755 /nix && chown $USER /nix" +$EXE "apt -y install curl stterm xz-utils sudo" + +lxc config set "$1" security.nesting true +lxc restart "$1" +sleep 1 + +UEXE="lxc exec $1 -- sudo --login --user $USER bash -ilc" +$UEXE "curl -L https://nixos.org/nix/install | sh" + +$UEXE "mkdir -p /home/$USER/.config/nixpkgs/" +lxc file push config/config.nix "$1/home/$USER/.config/nixpkgs/" + +$UEXE "nix-env -iA nixpkgs.myPackages" + +lxc file push config/nixos-config "$1/home/$USER/" +$UEXE "nix-build '' -A vm -I." + +$EXE "ln -s /home/user/result/system/etc/systemd/system/* /etc/systemd/system/" +$EXE "ln -s /home/user/result/system/etc/ssh/* /etc/ssh/" diff --git a/teardown b/teardown new file mode 100755 index 0000000..4ceeb4f --- /dev/null +++ b/teardown @@ -0,0 +1,5 @@ +#!/bin/bash +set -e + +lxc stop $1 +lxc rm $1 -- cgit v1.2.3