Compare commits
2 Commits
54c0e8a46b
...
4fa1e6e4ef
| Author | SHA1 | Date | |
|---|---|---|---|
| 4fa1e6e4ef | |||
| 06c48f2927 |
80
flake.nix
80
flake.nix
@@ -44,89 +44,13 @@
|
|||||||
|
|
||||||
packages.x86_64-linux.default = self.packages.x86_64-linux.gokill;
|
packages.x86_64-linux.default = self.packages.x86_64-linux.gokill;
|
||||||
|
|
||||||
nixosModules.gokill = { config, lib, pkgs, ... }:
|
nixosModules.gokill = import ./nixos-modules/gokill.nix { self = self; };
|
||||||
let
|
|
||||||
cfg = config.services.gokill;
|
|
||||||
configFile = pkgs.writeText "config.json" (builtins.toJSON cfg.triggers);
|
|
||||||
gokill-pkg = self.packages.x86_64-linux.gokill;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
options = {
|
|
||||||
services.gokill = {
|
|
||||||
enable = lib.mkOption {
|
|
||||||
default = false;
|
|
||||||
type = lib.types.bool;
|
|
||||||
description = lib.mdDoc ''
|
|
||||||
Enables gokill daemon
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
triggers = lib.mkOption {
|
|
||||||
description = "list of triggers";
|
|
||||||
default = [];
|
|
||||||
type = with lib.types; lib.types.listOf ( submodule {
|
|
||||||
options = {
|
|
||||||
type = lib.mkOption {
|
|
||||||
type = lib.types.str;
|
|
||||||
};
|
|
||||||
|
|
||||||
name = lib.mkOption {
|
|
||||||
type = lib.types.str;
|
|
||||||
};
|
|
||||||
|
|
||||||
options = lib.mkOption {
|
|
||||||
type = lib.types.attrs;
|
|
||||||
};
|
|
||||||
|
|
||||||
actions = lib.mkOption {
|
|
||||||
description = "list of actions";
|
|
||||||
type = with lib.types; lib.types.listOf ( submodule {
|
|
||||||
options = {
|
|
||||||
type = lib.mkOption {
|
|
||||||
type = lib.types.str;
|
|
||||||
};
|
|
||||||
|
|
||||||
options = lib.mkOption {
|
|
||||||
type = lib.types.attrs;
|
|
||||||
};
|
|
||||||
|
|
||||||
stage = lib.mkOption {
|
|
||||||
type = lib.types.int;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
});
|
|
||||||
};
|
|
||||||
};
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
extraConfig = lib.mkOption {
|
|
||||||
type = lib.types.str;
|
|
||||||
description = lib.mdDoc ''
|
|
||||||
gokill config.json
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
config = lib.mkIf cfg.enable {
|
|
||||||
systemd.services.gokill = {
|
|
||||||
description = "gokill daemon";
|
|
||||||
serviceConfig = {
|
|
||||||
Type = "simple";
|
|
||||||
ExecStart = "${gokill-pkg}/bin/gokill -c ${configFile}";
|
|
||||||
Restart = "on-failure";
|
|
||||||
};
|
|
||||||
|
|
||||||
wantedBy = [ "default.target" ];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
packages.x86_64-linux.testVm =
|
packages.x86_64-linux.testVm =
|
||||||
let
|
let
|
||||||
nixos = nixpkgs.lib.nixosSystem {
|
nixos = nixpkgs.lib.nixosSystem {
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
|
specialArgs = { inherit self; };
|
||||||
modules = [
|
modules = [
|
||||||
self.nixosModules.gokill
|
self.nixosModules.gokill
|
||||||
{
|
{
|
||||||
|
|||||||
73
nixos-modules/gokill.nix
Normal file
73
nixos-modules/gokill.nix
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
flake: { config, lib, pkgs, self, ... }:
|
||||||
|
let
|
||||||
|
cfg = config.services.gokill;
|
||||||
|
configFile = pkgs.writeText "config.json" (builtins.toJSON cfg.triggers);
|
||||||
|
gokill-pkg = self.packages.x86_64-linux.gokill;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options = with lib; {
|
||||||
|
services.gokill = {
|
||||||
|
enable = mkOption {
|
||||||
|
default = false;
|
||||||
|
type = types.bool;
|
||||||
|
description = mdDoc ''
|
||||||
|
Enables gokill daemon
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
triggers = mkOption {
|
||||||
|
description = "list of triggers";
|
||||||
|
default = [];
|
||||||
|
type = with types; types.listOf ( submodule {
|
||||||
|
options = {
|
||||||
|
type = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
};
|
||||||
|
|
||||||
|
name = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
};
|
||||||
|
|
||||||
|
options = mkOption {
|
||||||
|
type = types.attrs;
|
||||||
|
};
|
||||||
|
|
||||||
|
actions = mkOption {
|
||||||
|
description = "list of actions";
|
||||||
|
type = with types; types.listOf ( submodule {
|
||||||
|
options = {
|
||||||
|
type = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
};
|
||||||
|
|
||||||
|
options = mkOption {
|
||||||
|
type = types.attrs;
|
||||||
|
};
|
||||||
|
|
||||||
|
stage = mkOption {
|
||||||
|
type = types.int;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = lib.mkIf cfg.enable {
|
||||||
|
systemd.services.gokill = {
|
||||||
|
description = "gokill daemon";
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "simple";
|
||||||
|
ExecStart = "${gokill-pkg}/bin/gokill -c ${configFile}";
|
||||||
|
Restart = "on-failure";
|
||||||
|
};
|
||||||
|
|
||||||
|
wantedBy = [ "default.target" ];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
# ./tests/hello-world-server.nix
|
|
||||||
(import ./lib.nix) {
|
(import ./lib.nix) {
|
||||||
name = "gokill-base-test";
|
name = "gokill-base-test";
|
||||||
nodes = {
|
nodes = {
|
||||||
# `self` here is set by using specialArgs in `lib.nix`
|
|
||||||
node1 = { self, pkgs, ... }: {
|
node1 = { self, pkgs, ... }: {
|
||||||
imports = [ self.nixosModules.gokill ];
|
imports = [ self.nixosModules.gokill ];
|
||||||
|
|
||||||
@@ -13,7 +11,7 @@
|
|||||||
type = "Timeout";
|
type = "Timeout";
|
||||||
name = "custom timeout";
|
name = "custom timeout";
|
||||||
options = {
|
options = {
|
||||||
duration = 10;
|
duration = 3;
|
||||||
};
|
};
|
||||||
actions = [
|
actions = [
|
||||||
{
|
{
|
||||||
@@ -34,9 +32,9 @@
|
|||||||
import time
|
import time
|
||||||
start_all() # wait for our service to start
|
start_all() # wait for our service to start
|
||||||
node1.wait_for_unit("gokill")
|
node1.wait_for_unit("gokill")
|
||||||
time.sleep(11)
|
time.sleep(4)
|
||||||
output = node1.succeed("journalctl -u gokill.service | tail -n 2 | head -n 1")
|
output = node1.succeed("journalctl -u gokill.service | tail -n 2 | head -n 1")
|
||||||
# Check if our webserver returns the expected result
|
# Check if our webserver returns the expected result
|
||||||
assert "hellow world" in output
|
assert "hello world" in output
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user