From 5743e4bc8281546f99846d18fb095c6ed2523c30 Mon Sep 17 00:00:00 2001 From: Ingolf Wagner Date: Wed, 20 May 2020 00:30:53 +0200 Subject: [PATCH] dummy: create dummy server for tests --- configs/dummy/configuration.nix | 61 ++++++++++++++++++++++++ configs/dummy/hardware-configuration.nix | 9 ++++ shell.nix | 9 +++- terranix/dummy_server/config.nix | 32 +++++++++++++ terranix/dummy_server/shell.nix | 46 ++++++++++++++++++ 5 files changed, 155 insertions(+), 2 deletions(-) create mode 100644 configs/dummy/configuration.nix create mode 100644 configs/dummy/hardware-configuration.nix create mode 100644 terranix/dummy_server/config.nix create mode 100644 terranix/dummy_server/shell.nix diff --git a/configs/dummy/configuration.nix b/configs/dummy/configuration.nix new file mode 100644 index 0000000..c472567 --- /dev/null +++ b/configs/dummy/configuration.nix @@ -0,0 +1,61 @@ +{ lib, config, pkgs, ... }: { + imports = [ + + + + + + ./hardware-configuration.nix + + ]; + + # enable initrd ssh + configuration.init-ssh = { + enable = "enabled"; + kernelModules = [ "virtio_pci" ]; + hostECDSAKey = ; + }; + + networking.hostName = "dummy"; + + # font + # ---- + programs.custom.urxvt.fontSize = 17; + programs.custom.xterm.fontSize = 17; + system.custom.fonts.dpi = 140; + + # allow un-free + # ------------- + nixpkgs.config.allowUnfree = true; + environment.variables.NIXPKGS_ALLOW_UNFREE = "1"; + + # some system stuff + # ----------------- + time.timeZone = lib.mkDefault "Europe/Berlin"; + #time.timeZone = lib.mkDefault "Pacific/Auckland"; + #time.timeZone = lib.mkDefault "Asia/Singapore"; + #time.timeZone = lib.mkDefault "Asia/Makassar"; + + i18n.defaultLocale = "en_US.UTF-8"; + console.font = "Lat2-Terminus16"; + console.keyMap = "us"; + + # swappiness + # ---------- + # 0 = only when running out of RAM + # 100 = always swapp + boot.kernel.sysctl."vm.swappiness" = 0; + + # rewire NIX_PATH + # --------------- + environment.variables.NIX_PATH = lib.mkForce "/var/src"; + + environment.systemPackages = [ pkgs.git ]; + + boot.initrd.network.postCommands = lib.mkAfter '' + echo "sleep engineering" + sleep 120 + ''; + +} + diff --git a/configs/dummy/hardware-configuration.nix b/configs/dummy/hardware-configuration.nix new file mode 100644 index 0000000..81c8290 --- /dev/null +++ b/configs/dummy/hardware-configuration.nix @@ -0,0 +1,9 @@ +{ ... }: { + imports = [ ]; + boot.loader.grub.device = "/dev/sda"; + fileSystems."/" = { + device = "/dev/sda1"; + fsType = "ext4"; + }; +} + diff --git a/shell.nix b/shell.nix index d507e95..ecfd5d3 100644 --- a/shell.nix +++ b/shell.nix @@ -128,7 +128,12 @@ let }; hostPattern = name: - if name == "porani" then "${name}.insecure" else "${name}.private"; + if name == "porani" then + "${name}.insecure" + else if name == "dummy" then + "95.217.223.75" + else + "${name}.private"; deployment = { secrets, content }: name: @@ -224,7 +229,7 @@ let in pkgs.mkShell { buildInputs = with pkgs; - (servers [ "workhorse" "sputnik" "porani" ]) + (servers [ "workhorse" "sputnik" "porani" "dummy" ]) ++ (desktops [ "pepe" "workout" "sterni" "mobi" ]) ++ [ (pkgs.writers.writeBashBin "reformat" '' find ${ diff --git a/terranix/dummy_server/config.nix b/terranix/dummy_server/config.nix new file mode 100644 index 0000000..85ff990 --- /dev/null +++ b/terranix/dummy_server/config.nix @@ -0,0 +1,32 @@ +{ pkgs, lib, ... }: +let + hcloud-modules = pkgs.fetchgit { + url = "https://github.com/mrVanDalo/terranix-hcloud.git"; + rev = "c3571f76664e1813f90d97b8c194a1e0149e895e"; + sha256 = "0plld74wincyy3c5gdfqh78pzrqibxh6r839dm0c717fajr9imwb"; + }; +in { + imports = [ (toString hcloud-modules) ]; + + # configure admin ssh keys + users.admins.palo.publicKey = + "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC6uza62+Go9sBFs3XZE2OkugBv9PJ7Yv8ebCskE5WYPcahMZIKkQw+zkGI8EGzOPJhQEv2xk+XBf2VOzj0Fto4nh8X5+Llb1nM+YxQPk1SVlwbNAlhh24L1w2vKtBtMy277MF4EP+caGceYP6gki5+DzlPUSdFSAEFFWgN1WPkiyUii15Xi3QuCMR8F18dbwVUYbT11vwNhdiAXWphrQG+yPguALBGR+21JM6fffOln3BhoDUp2poVc5Qe2EBuUbRUV3/fOU4HwWVKZ7KCFvLZBSVFutXCj5HuNWJ5T3RuuxJSmY5lYuFZx9gD+n+DAEJt30iXWcaJlmUqQB5awcB1S2d9pJ141V4vjiCMKUJHIdspFrI23rFNYD9k2ZXDA8VOnQE33BzmgF9xOVh6qr4G0oEpsNqJoKybVTUeSyl4+ifzdQANouvySgLJV/pcqaxX1srSDIUlcM2vDMWAs3ryCa0aAlmAVZIHgRhh6wa+IXW8gIYt+5biPWUuihJ4zGBEwkyVXXf2xsecMWCAGPWPDL0/fBfY9krNfC5M2sqxey2ShFIq+R/wMdaI7yVjUCF2QIUNiIdFbJL6bDrDyHnEXJJN+rAo23jUoTZZRv7Jq3DB/A5H7a73VCcblZyUmwMSlpg3wos7pdw5Ctta3zQPoxoAKGS1uZ+yTeZbPMmdbw== cardno:000611343142"; + + users.admins.terranix.publicKey = "${lib.fileContents ./sshkey.pub}"; + + # configure provisioning private Key to be used when running provisioning on the machines + provisioner.privateKeyFile = toString ./sshkey; + + hcloud.nixserver = { + playground = { + enable = true; + configurationFile = pkgs.writeText "configuration.nix" '' + { pkgs, lib, config, ... }: + { environment.systemPackages = [ pkgs.git ]; } + ''; + }; + }; + + hcloud.export.nix = null; + +} diff --git a/terranix/dummy_server/shell.nix b/terranix/dummy_server/shell.nix new file mode 100644 index 0000000..8b33b71 --- /dev/null +++ b/terranix/dummy_server/shell.nix @@ -0,0 +1,46 @@ +{ pkgs ? import { } }: +let + + terranix = pkgs.callPackage (pkgs.fetchgit { + url = "https://github.com/mrVanDalo/terranix.git"; + rev = "dfbf4d1fae08da8052ff880c5d02b2eb5857d54c"; + sha256 = "1qilbvldlq7ybxa3yx99hb8vbmj0sk5x9qqxa4f1czpzj2mja0fn"; + }) { }; + + terraform = pkgs.writers.writeBashBin "terraform" '' + export TF_VAR_hcloud_api_token=`${pkgs.pass}/bin/pass development/hetzner.com/api-token` + ${pkgs.terraform_0_12}/bin/terraform "$@" + ''; + +in pkgs.mkShell { + + buildInputs = [ + + terranix + terraform + + (pkgs.writers.writeBashBin "prepare" '' + set -e + set -o pipefail + ${pkgs.openssh}/bin/ssh-keygen -P "" -f ${toString ./.}/sshkey + '') + + (pkgs.writers.writeBashBin "build" '' + set -e + set -o pipefail + ${terranix}/bin/terranix | ${pkgs.jq}/bin/jq '.' > config.tf.json + ${terraform}/bin/terraform init + ${terraform}/bin/terraform apply + '') + + (pkgs.writers.writeBashBin "cleanup" '' + ${terraform}/bin/terraform destroy + rm ${toString ./.}/config.tf.json + rm ${toString ./.}/sshkey + rm ${toString ./.}/sshkey.pub + rm ${toString ./.}/terraform.tfstate* + '') + + ]; + +}