-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
107 lines (98 loc) · 3.44 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
{
inputs = {
utils.url = "github:numtide/flake-utils";
};
outputs = {
self,
nixpkgs,
utils,
}:
utils.lib.eachDefaultSystem (
system: let
pkgs = nixpkgs.legacyPackages.${system};
in {
devShell = pkgs.mkShell {
buildInputs = with pkgs; [
# self.packages.${system}.default
];
};
nixosModules = rec {
ec2-instance-connect-config = {selfPackages}: {
config,
pkgs,
...
}: {
users.groups.ec2-instance-connect = {};
users.users.ec2-instance-connect = {
isSystemUser = true;
group = "ec2-instance-connect";
};
# Ugly: sshd refuses to start if a store path is given because /nix/store is group-writable.
# So indirect by a symlink.
environment.etc."ssh/aws-ec2-instance-connect" = {
mode = "0755";
text = ''
#!/bin/sh
exec ${selfPackages.ec2-instance-connect-run}/bin/eic_run_authorized_keys "$@"
'';
};
services.openssh = {
# AWS Instance Connect SSH offers the following kex algorithms
# ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,ext-info-c,[email protected]
settings.KexAlgorithms =
# TODO: replace with nixos default options value
[
"curve25519-sha256"
"diffie-hellman-group-exchange-sha256"
]
++ ["ecdh-sha2-nistp521"];
authorizedKeysCommandUser = "ec2-instance-connect";
authorizedKeysCommand = "/etc/ssh/aws-ec2-instance-connect %u %f";
};
};
default = ec2-instance-connect-config;
};
packages = rec {
ec2-instance-connect-script = pkgs.stdenvNoCC.mkDerivation {
name = "ec2-instance-connect-script";
src = pkgs.fetchFromGitHub {
owner = "aws";
repo = "aws-ec2-instance-connect-config";
rev = "1.1.17";
hash = "sha256-XXrVcmgsYFOj/1cD45ulFry5gY7XOkyhmDV7yXvgNhI=";
};
dontBuild = true;
dontPatchShebangs = true;
dontPatch = true;
installPhase = ''
mkdir -p $out/bin
cp $src/src/bin/eic_parse_authorized_keys $out/bin
cp $src/src/bin/eic_run_authorized_keys $out/bin
# TODO: move to fixup phase!
sed "s%^ca_path=/etc/ssl/certs$%ca_path=/etc/ssl/certs/ca-bundle.crt%" "src/bin/eic_curl_authorized_keys" > "$out/bin/eic_curl_authorized_keys"
chmod a+x "$out/bin/eic_curl_authorized_keys"
'';
};
ec2-instance-connect-run = pkgs.buildFHSEnv {
name = "eic_run_authorized_keys";
runScript = "${ec2-instance-connect-script}/bin/eic_run_authorized_keys";
targetPkgs = p:
with p; [
coreutils
curl
openssh
cacert
gnugrep
util-linux
openssl
gawk
gnused
];
};
default = ec2-instance-connect-run;
};
}
);
}