This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

superconfig / tools / install-ssh-keys / flake-module.nix
1.2 kB 38 lines
1{ self, ... }: 2{ 3 perSystem = 4 { pkgs, lib, ... }: 5 let 6 authorizedKeysFile = pkgs.writeText "authorized_keys" '' 7 # SSH keys installed by install-ssh-keys tool 8 # Generated from self.keys.ssh 9 10 ${lib.concatMapStringsSep "\n" (key: key.public) (lib.attrValues self.keys.ssh)} 11 ''; 12 in 13 { 14 packages.install-ssh-keys = pkgs.writeShellApplication { 15 name = "install-ssh-keys"; 16 runtimeInputs = [ ]; 17 text = '' 18 set -euo pipefail 19 20 # Check if we're running as root 21 if [[ $EUID -ne 0 ]]; then 22 echo "Not running as root. Using sudo to install keys to /root/.ssh/authorized_keys" 23 exec sudo "$0" "$@" 24 fi 25 26 # Create /root/.ssh directory if it doesn't exist 27 mkdir -p /root/.ssh 28 chmod 700 /root/.ssh 29 30 # Append the authorized_keys 31 cat ${authorizedKeysFile} >> /root/.ssh/authorized_keys 32 chmod 600 /root/.ssh/authorized_keys 33 34 echo "Appended SSH keys to /root/.ssh/authorized_keys: ${lib.concatStringsSep ", " (lib.attrNames self.keys.ssh)}" 35 ''; 36 }; 37 }; 38}