Skip to content

Commit

Permalink
Merge pull request #1172 from Enzime/push-yxtrnyuxzmny
Browse files Browse the repository at this point in the history
openssh: init module
  • Loading branch information
Enzime authored Jan 11, 2025
2 parents 57733bd + be4c1b8 commit 6ace2f2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/module-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
./services/nix-gc
./services/nix-optimise
./services/ofborg
./services/openssh.nix
./services/postgresql
./services/privoxy
./services/redis
Expand Down
33 changes: 33 additions & 0 deletions modules/services/openssh.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{ config, lib, ... }:

let
cfg = config.services.openssh;
in
{
options = {
services.openssh.enable = lib.mkOption {
type = lib.types.nullOr lib.types.bool;
default = null;
description = ''
Whether to enable Apple's built-in OpenSSH server.
The default is null which means let macOS manage the OpenSSH server.
'';
};
};

config = {
# We don't use `systemsetup -setremotelogin` as it requires Full Disk Access
system.activationScripts.launchd.text = lib.mkIf (cfg.enable != null) (if cfg.enable then ''
if [[ "$(systemsetup -getremotelogin | sed 's/Remote Login: //')" == "Off" ]]; then
launchctl enable system/com.openssh.sshd
launchctl bootstrap system /System/Library/LaunchDaemons/ssh.plist
fi
'' else ''
if [[ "$(systemsetup -getremotelogin | sed 's/Remote Login: //')" == "On" ]]; then
launchctl bootout system/com.openssh.sshd
launchctl disable system/com.openssh.sshd
fi
'');
};
}

0 comments on commit 6ace2f2

Please sign in to comment.