From 4fa1e6e4efaa4ac4783ebe7d42dc221b626dc6b9 Mon Sep 17 00:00:00 2001 From: kalipso Date: Tue, 31 Oct 2023 16:43:52 +0100 Subject: [PATCH] [nix] extract nixos-module/gokill --- flake.nix | 80 +--------------------------------------- nixos-modules/gokill.nix | 73 ++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 78 deletions(-) create mode 100644 nixos-modules/gokill.nix diff --git a/flake.nix b/flake.nix index ddee458..5ce8e9f 100644 --- a/flake.nix +++ b/flake.nix @@ -44,89 +44,13 @@ packages.x86_64-linux.default = self.packages.x86_64-linux.gokill; - nixosModules.gokill = { config, lib, pkgs, ... }: - 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" ]; - }; - }; - }; + nixosModules.gokill = import ./nixos-modules/gokill.nix { self = self; }; packages.x86_64-linux.testVm = let nixos = nixpkgs.lib.nixosSystem { system = "x86_64-linux"; + specialArgs = { inherit self; }; modules = [ self.nixosModules.gokill { diff --git a/nixos-modules/gokill.nix b/nixos-modules/gokill.nix new file mode 100644 index 0000000..9209a95 --- /dev/null +++ b/nixos-modules/gokill.nix @@ -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" ]; + }; + }; +} + +