feat: nixos systemd module

This commit is contained in:
Guz
2024-12-15 22:01:37 -03:00
parent fde69ec65b
commit f9ee818103
2 changed files with 70 additions and 0 deletions

View File

@@ -34,6 +34,28 @@
default = self.packages.${system}.keikos; default = self.packages.${system}.keikos;
}); });
nixosModules = {
keikos = {
pkgs,
lib,
...
}: {
options._keikos-flake = with lib;
with lib.types; {
pkg = mkOption {
type = anything;
default = self.packages.${pkgs.system}.default;
};
};
imports = [
./module.nix
];
};
default = self.nixosModules.keikos;
};
legacyPackages = self.packages;
devShells = forAllSystems (system: pkgs: { devShells = forAllSystems (system: pkgs: {
default = pkgs.mkShell { default = pkgs.mkShell {
CGO_ENABLED = "0"; CGO_ENABLED = "0";

48
module.nix Normal file
View File

@@ -0,0 +1,48 @@
{
config,
lib,
...
}: let
cfg = config.services.keikos.web;
in {
options.services.keikos.web = with lib;
with lib.types; {
enable = mkEnableOption "";
port = mkOption {
type = port;
default = 7331;
};
package = mkOption {
type = package;
default = config._keikos-flake.pkg;
};
user = mkOption {
type = str;
default = "keikoswork";
};
group = mkOption {
type = str;
default = "keikoswork";
};
};
config = with lib;
mkIf cfg.enable {
systemd.services."keikoswork" = {
after = ["network.target"];
wantedBy = ["multi-user.target"];
serviceConfig = {
Type = "simple";
User = cfg.user;
Group = cfg.group;
ExecStart = "${lib.escapeShellArg (lib.getExe cfg.package)} web -port ${toString cfg.port}";
Restart = "on-success";
};
};
users.users."${cfg.user}" = {
isSystemUser = true;
group = cfg.group;
};
users.groups."${cfg.group}" = {};
};
}