git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #5255 from offlinehacker/nixos/fleet
4a993dcJaka Hudoklin
nixos/modules/misc/ids.nix+1
@@ -307,6 +307,7 @@
307 scollector = 156;
307 scollector = 156;
308 bosun = 157;
308 bosun = 157;
309 kubernetes = 158;
309 kubernetes = 158;
310+ fleet = 159;
310
311
311 # When adding a gid, make sure it doesn't match an existing uid. And don't use gids above 399!
312 # When adding a gid, make sure it doesn't match an existing uid. And don't use gids above 399!
312
313
nixos/modules/module-list.nix+1
@@ -399,6 +399,7 @@
399 ./virtualisation/container-config.nix
399 ./virtualisation/container-config.nix
400 ./virtualisation/containers.nix
400 ./virtualisation/containers.nix
401 ./virtualisation/docker.nix
401 ./virtualisation/docker.nix
402+ ./virtualisation/fleet.nix
402 ./virtualisation/kubernetes.nix
403 ./virtualisation/kubernetes.nix
403 ./virtualisation/libvirtd.nix
404 ./virtualisation/libvirtd.nix
404 ./virtualisation/lxc.nix
405 ./virtualisation/lxc.nix
nixos/modules/system/boot/systemd.nix+2−1
@@ -348,7 +348,8 @@ let
348 [Service]
348 [Service]
349 ${let env = cfg.globalEnvironment // def.environment;
349 ${let env = cfg.globalEnvironment // def.environment;
350 in concatMapStrings (n:
350 in concatMapStrings (n:
351+ let s = optionalString (env."${n}" != null)
351− let s = "Environment=\"${n}=${env.${n}}\"\n";
352+ "Environment=\"${n}=${env.${n}}\"\n";
352 in if stringLength s >= 2048 then throw "The value of the environment variable ‘${n}’ in systemd service ‘${name}.service’ is too long." else s) (attrNames env)}
353 in if stringLength s >= 2048 then throw "The value of the environment variable ‘${n}’ in systemd service ‘${name}.service’ is too long." else s) (attrNames env)}
353 ${if def.reloadIfChanged then ''
354 ${if def.reloadIfChanged then ''
354 X-ReloadIfChanged=true
355 X-ReloadIfChanged=true
nixos/modules/virtualisation/fleet.nixnew file+147
@@ -0,0 +1,147 @@
1+{ config, lib, pkgs, ... }:
2+
3+with lib;
4+
5+let
6+ cfg = config.virtualisation.fleet;
7+
8+in {
9+
10+ ##### Interface
11+ options.virtualisation.fleet = {
12+ enable = mkOption {
13+ type = types.bool;
14+ default = false;
15+ description = ''
16+ Whether to enable fleet service.
17+ '';
18+ };
19+
20+ listen = mkOption {
21+ type = types.listOf types.str;
22+ default = [ "/var/run/fleet.sock" ];
23+ example = [ "/var/run/fleet.sock" "127.0.0.1:49153" ];
24+ description = ''
25+ Fleet listening addresses.
26+ '';
27+ };
28+
29+ etcdServers = mkOption {
30+ type = types.listOf types.str;
31+ default = [ "http://127.0.0.1:4001" ];
32+ description = ''
33+ Fleet list of etcd endpoints to use.
34+ '';
35+ };
36+
37+ publicIp = mkOption {
38+ type = types.nullOr types.str;
39+ default = "";
40+ description = ''
41+ Fleet IP address that should be published with the local Machine's
42+ state and any socket information. If not set, fleetd will attempt
43+ to detect the IP it should publish based on the machine's IP
44+ routing information.
45+ '';
46+ };
47+
48+ etcdCafile = mkOption {
49+ type = types.nullOr types.path;
50+ default = null;
51+ description = ''
52+ Fleet TLS ca file when SSL certificate authentication is enabled
53+ in etcd endpoints.
54+ '';
55+ };
56+
57+ etcdKeyfile = mkOption {
58+ type = types.nullOr types.path;
59+ default = null;
60+ description = ''
61+ Fleet TLS key file when SSL certificate authentication is enabled
62+ in etcd endpoints.
63+ '';
64+ };
65+
66+ etcdCertfile = mkOption {
67+ type = types.nullOr types.path;
68+ default = null;
69+ description = ''
70+ Fleet TLS cert file when SSL certificate authentication is enabled
71+ in etcd endpoints.
72+ '';
73+ };
74+
75+ metadata = mkOption {
76+ type = types.attrsOf types.str;
77+ default = {};
78+ apply = attrs: concatMapStringsSep "," (n: "${n}=${attrs."${n}"}") (attrNames attrs);
79+ example = literalExample ''
80+ {
81+ region = "us-west";
82+ az = "us-west-1";
83+ }
84+ '';
85+ description = ''
86+ Key/value pairs that are published with the local to the fleet registry.
87+ This data can be used directly by a client of fleet to make scheduling decisions.
88+ '';
89+ };
90+
91+ extraConfig = mkOption {
92+ type = types.attrsOf types.str;
93+ apply = mapAttrs' (n: v: nameValuePair ("ETCD_" + n) v);
94+ default = {};
95+ example = literalExample ''
96+ {
97+ VERBOSITY = 1;
98+ ETCD_REQUEST_TIMEOUT = "2.0";
99+ AGENT_TTL = "40s";
100+ }
101+ '';
102+ description = ''
103+ Fleet extra config. See
104+ <link xlink:href="https://github.com/coreos/fleet/blob/master/Documentation/deployment-and-configuration.md"/>
105+ for configuration options.
106+ '';
107+ };
108+
109+ };
110+
111+ ##### Implementation
112+ config = mkIf cfg.enable {
113+ systemd.services.fleet = {
114+ description = "Fleet Init System Daemon";
115+ wantedBy = [ "multi-user.target" ];
116+ after = [ "network.target" "fleet.socket" "etcd.service" "docker.service" ];
117+ requires = [ "fleet.socket" ];
118+ environment = {
119+ FLEET_ETCD_SERVERS = concatStringsSep "," cfg.etcdServers;
120+ FLEET_PUBLIC_IP = cfg.publicIp;
121+ FLEET_ETCD_CAFILE = cfg.etcdCafile;
122+ FLEET_ETCD_KEYFILE = cfg.etcdKeyfile;
123+ FEELT_ETCD_CERTFILE = cfg.etcdCertfile;
124+ FLEET_METADATA = cfg.metadata;
125+ } // cfg.extraConfig;
126+ serviceConfig = {
127+ ExecStart = "${pkgs.fleet}/bin/fleetd";
128+ Group = "fleet";
129+ };
130+ };
131+
132+ systemd.sockets.fleet = {
133+ description = "Fleet Socket for the API";
134+ wantedBy = [ "sockets.target" ];
135+ listenStreams = cfg.listen;
136+ socketConfig = {
137+ ListenStream = "/var/run/fleet.sock";
138+ SocketMode = "0660";
139+ SocketUser = "root";
140+ SocketGroup = "fleet";
141+ };
142+ };
143+
144+ environment.systemPackages = [ pkgs.fleet ];
145+ users.extraGroups.fleet.gid = config.ids.gids.fleet;
146+ };
147+}
nixos/release.nix+1
@@ -244,6 +244,7 @@ in rec {
244 tests.etcd = scrubDrv (import tests/etcd.nix { system = "x86_64-linux"; });
244 tests.etcd = scrubDrv (import tests/etcd.nix { system = "x86_64-linux"; });
245 tests.firefox = callTest tests/firefox.nix {};
245 tests.firefox = callTest tests/firefox.nix {};
246 tests.firewall = callTest tests/firewall.nix {};
246 tests.firewall = callTest tests/firewall.nix {};
247+ tests.fleet = scrubDrv (import tests/fleet.nix { system = "x86_64-linux"; });
247 tests.gnome3 = callTest tests/gnome3.nix {};
248 tests.gnome3 = callTest tests/gnome3.nix {};
248 tests.installer.grub1 = forAllSystems (system: scrubDrv (import tests/installer.nix { inherit system; }).grub1.test);
249 tests.installer.grub1 = forAllSystems (system: scrubDrv (import tests/installer.nix { inherit system; }).grub1.test);
249 tests.installer.lvm = forAllSystems (system: scrubDrv (import tests/installer.nix { inherit system; }).lvm.test);
250 tests.installer.lvm = forAllSystems (system: scrubDrv (import tests/installer.nix { inherit system; }).lvm.test);
nixos/tests/fleet.nixnew file+73
@@ -0,0 +1,73 @@
1+import ./make-test.nix rec {
2+ name = "simple";
3+
4+ nodes = {
5+ node1 =
6+ { config, pkgs, ... }:
7+ {
8+ services = {
9+ etcd = {
10+ enable = true;
11+ listenPeerUrls = ["http://0.0.0.0:7001"];
12+ initialAdvertisePeerUrls = ["http://node1:7001"];
13+ initialCluster = ["node1=http://node1:7001" "node2=http://node2:7001"];
14+ };
15+ };
16+
17+ virtualisation.fleet = {
18+ enable = true;
19+ metadata.name = "node1";
20+ };
21+
22+ networking.firewall.allowedTCPPorts = [ 7001 ];
23+ };
24+
25+ node2 =
26+ { config, pkgs, ... }:
27+ {
28+ services = {
29+ etcd = {
30+ enable = true;
31+ listenPeerUrls = ["http://0.0.0.0:7001"];
32+ initialAdvertisePeerUrls = ["http://node2:7001"];
33+ initialCluster = ["node1=http://node1:7001" "node2=http://node2:7001"];
34+ };
35+ };
36+
37+ virtualisation.fleet = {
38+ enable = true;
39+ metadata.name = "node2";
40+ };
41+
42+ networking.firewall.allowedTCPPorts = [ 7001 ];
43+ };
44+ };
45+
46+ service = builtins.toFile "hello.service" ''
47+ [Unit]
48+ Description=Hello World
49+
50+ [Service]
51+ ExecStart=/bin/sh -c "while true; do echo \"Hello, world\"; /var/run/current-system/sw/bin/sleep 1; done"
52+
53+ [X-Fleet]
54+ MachineMetadata=name=node2
55+ '';
56+
57+ testScript =
58+ ''
59+ startAll;
60+ $node1->waitForUnit("fleet.service");
61+ $node2->waitForUnit("fleet.service");
62+
63+ $node2->waitUntilSucceeds("fleetctl list-machines | grep node1");
64+ $node1->waitUntilSucceeds("fleetctl list-machines | grep node2");
65+
66+ $node1->succeed("cp ${service} hello.service && fleetctl submit hello.service");
67+ $node1->succeed("fleetctl list-unit-files | grep hello");
68+ $node1->succeed("fleetctl start hello.service");
69+ $node1->waitUntilSucceeds("fleetctl list-units | grep running");
70+ $node1->succeed("fleetctl stop hello.service");
71+ $node1->succeed("fleetctl destroy hello.service");
72+ '';
73+}