-
Notifications
You must be signed in to change notification settings - Fork 3
/
thymis-device-nixos-module.nix
110 lines (109 loc) · 3.58 KB
/
thymis-device-nixos-module.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
108
109
110
{ config, lib, pkgs, inputs, modulesPath, ... }:
let
cfg = config.thymis.config;
use-wifi = cfg.wifi-ssid != "" && cfg.wifi-password != "";
settingsFormat = pkgs.formats.json { };
in
{
imports = [
inputs.thymis.inputs.home-manager.nixosModules.default
"${modulesPath}/profiles/base.nix"
];
options = {
thymis.config = lib.mkOption {
type = lib.types.submodule {
freeformType = settingsFormat.type;
options = {
device-type = lib.mkOption {
type = lib.types.str;
default = "generic-x86_64";
description = "Type of the device";
};
device-name = lib.mkOption {
type = lib.types.str;
default = "thymis";
description = "Name of the device";
};
password = lib.mkOption {
type = lib.types.nullOr lib.types.str;
description = "Password for the root user";
default = null;
};
wifi-ssid = lib.mkOption {
type = lib.types.str;
default = "";
description = "SSID of the wifi network";
};
wifi-password = lib.mkOption {
type = lib.types.str;
default = "";
description = "Password for the wifi network";
};
agent = lib.mkOption {
type = lib.types.submodule {
options = {
enable = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Enable the agent";
};
controller-url = lib.mkOption {
type = lib.types.str;
default = "";
description = "URL of the Thymis Controller";
};
};
};
};
};
};
default = { };
description = "Thymis configuration";
};
};
config = {
nix.settings.experimental-features = [ "nix-command" "flakes" ];
users.users.root.password = lib.mkIf (cfg.password != null) cfg.password;
services.openssh = {
enable = true;
settings.PermitRootLogin = "yes";
};
networking.hostName = cfg.device-name;
networking.wireless = lib.mkIf use-wifi {
enable = true;
networks = {
"${cfg.wifi-ssid}" = {
psk = "${cfg.wifi-password}";
};
};
};
boot.supportedFilesystems = lib.mkForce [ "btrfs" "cifs" "f2fs" "jfs" "ntfs" "reiserfs" "vfat" "xfs" "ext4" ];
services.getty.greetingLine = ''<<< Welcome to Thymis - NixOS ${config.system.nixos.label} (\m) - \l >>>'';
services.getty.helpLine = lib.mkForce ''
This is a Thymis device. You can login as root with the password you set during installation.
'';
system.nixos.distroName = "Thymis - NixOS";
systemd.services.display-manager.restartIfChanged = lib.mkForce true;
users.users.thymis = {
isNormalUser = true;
createHome = true;
password = lib.mkIf (cfg.password != null) cfg.password;
};
networking.firewall = {
allowedTCPPorts = [ 22 ];
};
thymis.config.agent.enable = lib.mkDefault false;
systemd.services.thymis-agent = lib.mkIf cfg.agent.enable {
description = "Thymis agent";
after = [ "network.target" "sshd.service" ];
wantedBy = [ "multi-user.target" ];
script = "${inputs.thymis.packages.${config.nixpkgs.hostPlatform.system}.thymis-agent}/bin/thymis-agent";
path = [
"/run/current-system/sw"
];
environment = {
CONTROLLER_HOST = cfg.agent.controller-url;
};
};
};
}