ssh.nix (1258B)
1 { 2 liminix 3 , dropbear 4 , serviceFns 5 , lib 6 }: 7 p : 8 let 9 inherit (liminix.services) longrun; 10 inherit (lib) concatStringsSep; 11 options = 12 [ 13 "-e" # pass environment to child 14 "-E" # log to stderr 15 "-R" # create hostkeys if needed 16 "-P /run/dropbear.pid" 17 "-F" # don't fork into background 18 ] ++ 19 (lib.optional (! p.allowRoot) "-w") ++ 20 (lib.optional (! p.allowPasswordLogin) "-s") ++ 21 (lib.optional (! p.allowPasswordLoginForRoot) "-g") ++ 22 (lib.optional (! p.allowLocalPortForward) "-j") ++ 23 (lib.optional (! p.allowRemotePortForward) "-k") ++ 24 (lib.optional (! p.allowRemoteConnectionToForwardedPorts) "-a") ++ 25 [(if p.address != null 26 then "-p ${p.address}:${p.port}" 27 else "-p ${builtins.toString p.port}")] ++ 28 [p.extraConfig]; 29 in 30 longrun { 31 name = "sshd"; 32 # we need /run/dropbear to point to hostkey storage, as that 33 # pathname is hardcoded into the binary. 34 # env -i clears the environment so we don't pass anything weird to 35 # ssh sessions 36 run = '' 37 ln -s $(mkstate dropbear) /run 38 . /etc/profile # sets PATH but do we need this? it's the same file as ashrc 39 exec env -i ENV=/etc/ashrc PATH=$PATH ${dropbear}/bin/dropbear ${concatStringsSep " " options} 40 ''; 41 }