Skip to content

Commit 4a88dde

Browse files
committed
initial flake
0 parents  commit 4a88dde

File tree

2 files changed

+161
-0
lines changed

2 files changed

+161
-0
lines changed

flake.lock

Lines changed: 59 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

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

0 commit comments

Comments
 (0)