Skip to content

Commit 1cb8803

Browse files
nixos/whoami: init module (NixOS#397396)
2 parents c1f3bc6 + 0e02f93 commit 1cb8803

File tree

6 files changed

+149
-6
lines changed

6 files changed

+149
-6
lines changed

nixos/doc/manual/release-notes/rl-2505.section.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@
189189

190190
- [echoip](https://github.com/mpolden/echoip), a simple service for looking up your IP address. Available as [services.echoip](#opt-services.echoip.enable).
191191

192+
- [whoami](https://github.com/traefik/whoami), a tiny Go server that prints OS information and HTTP request to output. Available as [services.whoami](#opt-services.whoami.enable).
193+
192194
- [LiteLLM](https://github.com/BerriAI/litellm), a LLM Gateway to provide model access, fallbacks and spend tracking across 100+ LLMs. All in the OpenAI format. Available as [services.litellm](#opt-services.litellm.enable).
193195

194196
- [Buffyboard](https://gitlab.postmarketos.org/postmarketOS/buffybox/-/tree/master/buffyboard), a framebuffer on-screen keyboard. Available as [services.buffyboard](option.html#opt-services.buffyboard).

nixos/modules/module-list.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,6 +1639,7 @@
16391639
./services/web-apps/wakapi.nix
16401640
./services/web-apps/weblate.nix
16411641
./services/web-apps/whitebophir.nix
1642+
./services/web-apps/whoami.nix
16421643
./services/web-apps/wiki-js.nix
16431644
./services/web-apps/windmill.nix
16441645
./services/web-apps/wordpress.nix
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
{
2+
config,
3+
lib,
4+
pkgs,
5+
...
6+
}:
7+
8+
let
9+
cfg = config.services.whoami;
10+
in
11+
12+
{
13+
meta.maintainers = with lib.maintainers; [ defelo ];
14+
15+
options.services.whoami = {
16+
enable = lib.mkEnableOption "whoami";
17+
18+
package = lib.mkPackageOption pkgs "whoami" { };
19+
20+
port = lib.mkOption {
21+
type = lib.types.port;
22+
description = "The port whoami should listen on.";
23+
default = 8000;
24+
};
25+
26+
extraArgs = lib.mkOption {
27+
type = lib.types.listOf lib.types.str;
28+
description = "Extra command line arguments to pass to whoami. See <https://github.com/traefik/whoami#flags> for details.";
29+
default = [ ];
30+
};
31+
};
32+
33+
config = lib.mkIf cfg.enable {
34+
systemd.services.whoami = {
35+
wantedBy = [ "multi-user.target" ];
36+
37+
wants = [ "network-online.target" ];
38+
after = [ "network-online.target" ];
39+
40+
serviceConfig = {
41+
User = "whoami";
42+
Group = "whoami";
43+
DynamicUser = true;
44+
ExecStart = lib.escapeShellArgs (
45+
[
46+
(lib.getExe cfg.package)
47+
"-port"
48+
cfg.port
49+
]
50+
++ cfg.extraArgs
51+
);
52+
53+
# Hardening
54+
AmbientCapabilities = "";
55+
CapabilityBoundingSet = [ "" ];
56+
DevicePolicy = "closed";
57+
LockPersonality = true;
58+
MemoryDenyWriteExecute = true;
59+
NoNewPrivileges = true;
60+
PrivateDevices = true;
61+
PrivateTmp = true;
62+
PrivateUsers = true;
63+
ProcSubset = "pid";
64+
ProtectClock = true;
65+
ProtectControlGroups = true;
66+
ProtectHome = true;
67+
ProtectHostname = true;
68+
ProtectKernelLogs = true;
69+
ProtectKernelModules = true;
70+
ProtectKernelTunables = true;
71+
ProtectProc = "invisible";
72+
ProtectSystem = "strict";
73+
RemoveIPC = true;
74+
RestrictAddressFamilies = [ "AF_INET AF_INET6" ];
75+
RestrictNamespaces = true;
76+
RestrictRealtime = true;
77+
RestrictSUIDSGID = true;
78+
SocketBindAllow = "tcp:${toString cfg.port}";
79+
SocketBindDeny = "any";
80+
SystemCallArchitectures = "native";
81+
SystemCallFilter = [
82+
"@system-service"
83+
"~@privileged"
84+
"~@resources"
85+
];
86+
UMask = "0077";
87+
};
88+
};
89+
};
90+
}

nixos/tests/all-tests.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,6 +1446,7 @@ in
14461446
webhook = runTest ./webhook.nix;
14471447
weblate = handleTest ./web-apps/weblate.nix { };
14481448
whisparr = handleTest ./whisparr.nix { };
1449+
whoami = runTest ./whoami.nix;
14491450
whoogle-search = handleTest ./whoogle-search.nix { };
14501451
wiki-js = runTest ./wiki-js.nix;
14511452
wine = handleTest ./wine.nix { };

nixos/tests/whoami.nix

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{ lib, ... }:
2+
3+
{
4+
name = "echoip";
5+
meta.maintainers = with lib.maintainers; [ defelo ];
6+
7+
nodes.machine = {
8+
services.whoami.enable = true;
9+
};
10+
11+
interactive.nodes.machine = {
12+
networking.firewall.allowedTCPPorts = [ 8000 ];
13+
virtualisation.forwardPorts = [
14+
{
15+
from = "host";
16+
host.port = 8000;
17+
guest.port = 8000;
18+
}
19+
];
20+
};
21+
22+
testScript = ''
23+
import re
24+
25+
machine.wait_for_unit("whoami.service")
26+
machine.wait_for_open_port(8000)
27+
28+
response = machine.succeed("curl -H 'X-Test-Header: Hello World!' http://127.0.0.1:8000/test")
29+
assert re.search(r"^GET /test", response, re.M)
30+
assert re.search(r"^X-Test-Header: Hello World!", response, re.M)
31+
'';
32+
}

pkgs/by-name/wh/whoami/package.nix

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
lib,
33
buildGoModule,
44
fetchFromGitHub,
5+
nixosTests,
6+
nix-update-script,
57
}:
68

7-
buildGoModule rec {
9+
buildGoModule (finalAttrs: {
810
pname = "whoami";
911
version = "1.11.0";
1012

1113
src = fetchFromGitHub {
1214
owner = "traefik";
1315
repo = "whoami";
14-
rev = "v${version}";
16+
tag = "v${finalAttrs.version}";
1517
hash = "sha256-3jzLdCmmts/7S1Oxig9Dg3kRGh/H5l5UD7ztev0yvXY=";
1618
};
1719

@@ -21,14 +23,29 @@ buildGoModule rec {
2123

2224
env.CGO_ENABLED = 0;
2325

24-
doCheck = false;
26+
doInstallCheck = true;
27+
installCheckPhase = ''
28+
runHook preInstallCheck
29+
30+
$out/bin/whoami --help 2> /dev/null
31+
32+
runHook postInstallCheck
33+
'';
34+
35+
passthru = {
36+
tests = { inherit (nixosTests) whoami; };
37+
updateScript = nix-update-script { };
38+
};
2539

2640
meta = {
2741
description = "Tiny Go server that prints os information and HTTP request to output";
2842
mainProgram = "whoami";
2943
homepage = "https://github.com/traefik/whoami";
30-
changelog = "https://github.com/traefik/whoami/releases/tag/v${version}";
44+
changelog = "https://github.com/traefik/whoami/releases/tag/v${finalAttrs.version}";
3145
license = lib.licenses.asl20;
32-
maintainers = with lib.maintainers; [ dvcorreia ];
46+
maintainers = with lib.maintainers; [
47+
dvcorreia
48+
defelo
49+
];
3350
};
34-
}
51+
})

0 commit comments

Comments
 (0)