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.3 kB 40 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 = 15 (pkgs.writeShellApplication { 16 name = "install-ssh-keys"; 17 runtimeInputs = [ ]; 18 text = '' 19 set -euo pipefail 20 21 # Check if we're running as root 22 if [[ $EUID -ne 0 ]]; then 23 echo "Not running as root. Using sudo to install keys to /root/.ssh/authorized_keys" 24 exec sudo "$0" "$@" 25 fi 26 27 # Create /root/.ssh directory if it doesn't exist 28 mkdir -p /root/.ssh 29 chmod 700 /root/.ssh 30 31 # Append the authorized_keys 32 cat ${authorizedKeysFile} >> /root/.ssh/authorized_keys 33 chmod 600 /root/.ssh/authorized_keys 34 35 echo "Appended SSH keys to /root/.ssh/authorized_keys: ${lib.concatStringsSep ", " (lib.attrNames self.keys.ssh)}" 36 ''; 37 }).overrideAttrs 38 { passthru.usage = builtins.readFile ./usage.kdl; }; 39 }; 40}