Add guest user with same ssh keys as root and fix nodeinfo not waiting for clightning to warm up

This commit is contained in:
Jonas Nick 2018-11-23 15:49:13 +00:00
parent eca9864cf3
commit ac2be00c7f
4 changed files with 33 additions and 10 deletions

View File

@ -24,6 +24,7 @@ in {
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs; [
vim tmux clightning bitcoin vim tmux clightning bitcoin
nodeinfo nodeinfo
jq
]; ];
nixpkgs.config.packageOverrides = pkgs: { nixpkgs.config.packageOverrides = pkgs: {
inherit nodeinfo; inherit nodeinfo;
@ -69,12 +70,6 @@ in {
# Open ports in the firewall. # Open ports in the firewall.
# Or disable the firewall altogether. # Or disable the firewall altogether.
# Define a user account. Don't forget to set a password with passwd.
# users.users.guest = {
# isNormalUser = true;
# uid = 1000;
# };
# This value determines the NixOS release with which your system is to be # This value determines the NixOS release with which your system is to be
# compatible, in order to avoid breaking some software such as database # compatible, in order to avoid breaking some software such as database
# servers. You should change this only after NixOS release notes say you # servers. You should change this only after NixOS release notes say you

View File

@ -52,6 +52,8 @@ in {
{ description = "Run clightningd"; { description = "Run clightningd";
path = [ pkgs.clightning pkgs.bitcoin ]; path = [ pkgs.clightning pkgs.bitcoin ];
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
requires = [ "bitcoind.service" ];
after = [ "bitcoind.service" ];
preStart = '' preStart = ''
mkdir -p ${home}/.lightning mkdir -p ${home}/.lightning
ln -sf ${configFile} ${home}/.lightning/config ln -sf ${configFile} ${home}/.lightning/config
@ -61,6 +63,7 @@ in {
ExecStart = "${pkgs.clightning}/bin/lightningd"; ExecStart = "${pkgs.clightning}/bin/lightningd";
User = "clightning"; User = "clightning";
Restart = "on-failure"; Restart = "on-failure";
RestartSec = "10s";
PrivateTmp = "true"; PrivateTmp = "true";
ProtectSystem = "full"; ProtectSystem = "full";
NoNewPrivileges = "true"; NoNewPrivileges = "true";

View File

@ -51,12 +51,31 @@ in {
systemd.services.nodeinfo = { systemd.services.nodeinfo = {
description = "Get node info"; description = "Get node info";
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
after = [ "clightning.service" "tor.service" ];
path = [ pkgs.clightning pkgs.jq pkgs.sudo ]; path = [ pkgs.clightning pkgs.jq pkgs.sudo ];
serviceConfig = { serviceConfig = {
ExecStart = "${pkgs.bash}/bin/bash -c ${pkgs.nodeinfo}/bin/nodeinfo"; ExecStart="${pkgs.bash}/bin/bash ${pkgs.nodeinfo}/bin/nodeinfo";
User = "root";
Type = "simple";
RemainAfterExit="yes";
Restart = "on-failure";
RestartSec = "10s";
};
};
# Define a user account. Don't forget to set a password with passwd.
users.users.guest = {
isNormalUser = true;
};
systemd.services.copy-root-authorized-keys = {
description = "Copy root authorized keys";
wantedBy = [ "multi-user.target" ];
path = [ ];
serviceConfig = {
ExecStart = "${pkgs.bash}/bin/bash -c \"mkdir -p ${config.users.users.guest.home}/.ssh && cp ${config.users.users.root.home}/.vbox-nixops-client-key ${config.users.users.guest.home}/.ssh/authorized_keys && chown -R guest ${config.users.users.guest.home}/.ssh\"";
user = "root"; user = "root";
type = "oneshot"; type = "oneshot";
}; };
}; };
}; };
} }

View File

@ -1,9 +1,15 @@
sleep 5 set -e
set -o pipefail
OUTFILE=/var/lib/nodeinfo.nix OUTFILE=/var/lib/nodeinfo.nix
BITCOIND_ONION=$(cat /var/lib/tor/onion/bitcoind/hostname)
CLIGHTNING_ID=$(sudo -u clightning lightning-cli getinfo | jq -r '.id')
rm -f $OUTFILE rm -f $OUTFILE
{ {
echo \{ echo \{
echo " bitcoind_onion = \"$(cat /var/lib/tor/onion/bitcoind/hostname)\";" echo " bitcoind_onion = \"$BITCOIND_ONION\";"
echo " clightning_id = \"$(sudo -u clightning lightning-cli getinfo | jq -r '.id')\";" echo " clightning_id = \"$CLIGHTNING_ID\";"
echo \} echo \}
} > $OUTFILE } > $OUTFILE