fix: module

This commit is contained in:
shimun 2022-12-01 10:38:05 +00:00 committed by shimun
parent 93337a9b46
commit 812b065cec
Signed by: shimun
GPG Key ID: E0420647856EA39E
3 changed files with 66 additions and 47 deletions

View File

@ -99,53 +99,12 @@
}; };
}; };
nixosModules.default = { config, pkgs, lib, ... }: with lib; let cfg = config.services.ssh-cert-dist; in { nixosModules.default = {
options.services.ssh-cert-dist = { imports = [ ./modules/nixos.nix ];
enable = mkEnableOption "ssh-cert-dist";
host = mkOption {
type = types.str;
default = "127.0.0.1";
}; };
port = mkOption { homeManagerModules.default = {
type = types.port; imports = [ ./modules/home-manager.nix ];
default = 6877;
}; };
package = mkOption {
type = types.package;
default = pkgs.ssh-cert-dist;
};
dataDir = mkOption {
type = types.path;
default = "/var/lib/ssh-cert-dist";
};
user = mkOption {
type = types.str;
default = "cert-dist";
};
group = mkOption {
type = types.str;
default = "cert-dist";
};
};
config = mkIf {
users = {
users.${cfg.user} = {
isSystemUser = true;
group = cfg.group;
};
groups.${cfg.group} = { };
};
systemd.services.ssh-cert-dist = {
preStart = ''
chown ${cfg.user}:${cfg.group} ${cfg.dataDir}
'';
serviceConfig.User = cfg.user;
serviceConfig.ExecStart = "${cfg.package}/bin/ssh-cert-dist server --address ${cfg.host}:${toString cfg.port} -c ${cfg.dataDir} --ca ${cfg.ca}";
};
};
};
homeManagerModules.default = { config, pkgs, lib, ... }: with lib; let cfg = config.services.ssh-cert-dist; in { };
}; };

2
modules/home-manager.nix Normal file
View File

@ -0,0 +1,2 @@
{ config, pkgs, lib, ... }: with lib; let cfg = config.services.ssh-cert-dist; in { }

58
modules/nixos.nix Normal file
View File

@ -0,0 +1,58 @@
{ config, pkgs, lib, ... }: with lib; let
cfg = config.services.ssh-cert-dist;
ca = if builtins.isPath cfg.ca then cfg.ca else pkgs.writeText "ssh-ca" cfg.ca;
in
{
options.services.ssh-cert-dist = {
enable = mkEnableOption "ssh-cert-dist";
host = mkOption {
type = types.str;
default = "127.0.0.1";
};
port = mkOption {
type = types.port;
default = 6877;
};
package = mkOption {
type = types.package;
default = pkgs.ssh-cert-dist;
};
ca = mkOption {
type = with types; either str path;
};
dataDir = mkOption {
type = types.path;
default = "/var/lib/ssh-cert-dist";
};
user = mkOption {
type = types.str;
default = "cert-dist";
};
group = mkOption {
type = types.str;
default = "cert-dist";
};
};
config = mkIf cfg.enable {
users = {
users.${cfg.user} = {
isSystemUser = true;
group = cfg.group;
};
groups.${cfg.group} = { };
};
systemd.services.ssh-cert-dist = {
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStartPre = "+${pkgs.writeShellScript "pre-start" ''
mkdir -p ${cfg.dataDir}
chown ${cfg.user}:${cfg.group} ${cfg.dataDir}
''}";
User = cfg.user;
ExecStart = "${cfg.package}/bin/ssh-cert-dist server --address ${cfg.host}:${toString cfg.port} -c ${cfg.dataDir} --ca ${ca}";
};
};
};
}