Skip to content

Commit

Permalink
Add daed module (#12)
Browse files Browse the repository at this point in the history
* add: daed module

* chore: add daed module to doc

* chore: expand default overlay to both
  • Loading branch information
oluceps authored Sep 6, 2023
1 parent e2815aa commit 8a47e47
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 12 deletions.
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Modify flake.nix
nixosConfigurations.HOSTNAME = nixpkgs.lib.nixosSystem {
modules = [
inputs.daeuniverse.nixosModules.dae
inputs.daeuniverse.nixosModules.daed
];
};
}
Expand All @@ -32,6 +33,20 @@ Modify flake.nix
# configuration.nix
{inputs, pkgs, ...}: {
# with daed
services.daed = {
enable = true;
configDir = "/etc/daed";
listen = "0.0.0.0:2023";
openFirewall = {
enable = true;
port = 12345;
};
};
# or with dae
services.dae = {
enable = true;
disableTxChecksumIpGeneric = false;
Expand All @@ -41,8 +56,8 @@ Modify flake.nix
enable = true;
port = 12345;
};
};
}
};
};
# use packages
Expand Down
113 changes: 113 additions & 0 deletions daed/module.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
inputs: { config, lib, pkgs, ... }:

let
cfg = config.services.daed;
defaultDaedPackage = inputs.self.packages.${pkgs.stdenv.hostPlatform.system}.daed;
in
{
# disables Nixpkgs daed module to avoid conflicts
disabledModules = [ "services/networking/daed.nix" ];

options = {
services.daed = with lib;{
enable = mkEnableOption
(mdDoc "A modern dashboard for dae");

package = mkOption {
type = types.path;
default = defaultDaedPackage;
defaultText = literalExpression ''
daed.packages.${pkgs.stdenv.hostPlatform.system}.daed
'';
example = literalExpression "pkgs.daed";
description = mdDoc ''
The daed package to use.
'';
};

configDir = mkOption {
type = types.str;
default = "/etc/daed";
description = mdDoc ''
The daed work directory.
'';
};

listen = mkOption {
type = types.str;
default = "0.0.0.0:2023";
description = mdDoc ''
The daed listen address.
'';
};

openFirewall = mkOption {
type = with types; submodule {
options = {
enable = mkEnableOption "enable";
port = mkOption {
type = types.int;
description = ''
Port to be opened. Consist with field `tproxy_port` in config file.
'';
};
};
};
default = {
enable = true;
port = 12345;
};
defaultText = literalExpression ''
{
enable = true;
port = 12345;
}
'';
description = mdDoc ''
Open the firewall port.
'';
};
};
};

config = lib.mkIf cfg.enable

{
environment.systemPackages = [ cfg.package ];
systemd.packages = [ cfg.package ];

networking = lib.mkIf cfg.openFirewall.enable {
firewall =
let portToOpen = cfg.openFirewall.port;
in
{
allowedTCPPorts = [ portToOpen ];
allowedUDPPorts = [ portToOpen ];
};
};

systemd.services.daed =
let
daedBin = lib.getExe cfg.package;
in
{
wantedBy = [ "multi-user.target" ];
after = [
"network-online.target"
"systemd-sysctl.service"
];
wants = [
"network-online.target"
];

serviceConfig = {
Type = "simple";
User = "root";
LimitNPROC = 512;
LimitNOFILE = 1048576;
ExecStart = "${daedBin} run -c ${cfg.configDir} -l ${cfg.listen}";
Restart = "on-abnormal";
};
};
};
}
27 changes: 17 additions & 10 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,23 @@
};
};
};
flake = {
nixosModules = { dae = import ./dae/module.nix inputs; };
overlays = {
default = final: prev: {
dae = inputs.self.packages.dae;
daed = inputs.self.packages.daed;
flake =
let
moduleName = [ "dae" "daed" ];
genFlake = n: {
nixosModules = {
${n} = import ./${n}/module.nix inputs;
};
overlays = {
${n} = final: prev: { ${n} = inputs.self.packages.${n}; };
};
};
dae = final: prev: { dae = inputs.self.packages.dae; };
daed = final: prev: { daed = inputs.self.packages.daed; };
};
};
in
inputs.nixpkgs.lib.mkMerge (
(map genFlake moduleName) ++ [{
overlays.default = final: prev: inputs.nixpkgs.lib.genAttrs moduleName
(n: { ${n} = inputs.self.packages.${n}; });
}]
);
};
}

0 comments on commit 8a47e47

Please sign in to comment.