nixos/services.gitDaemon: remove with lib;

This commit is contained in:
Felix Buehler 2024-08-28 21:19:08 +02:00 committed by Jörg Thalheim
parent 0b865525e8
commit 878c5dc6eb

View File

@ -1,5 +1,4 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.gitDaemon;
@ -12,8 +11,8 @@ in
options = {
services.gitDaemon = {
enable = mkOption {
type = types.bool;
enable = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''
Enable Git daemon, which allows public hosting of git repositories
@ -27,10 +26,10 @@ in
'';
};
package = mkPackageOption pkgs "git" { };
package = lib.mkPackageOption pkgs "git" { };
basePath = mkOption {
type = types.str;
basePath = lib.mkOption {
type = lib.types.str;
default = "";
example = "/srv/git/";
description = ''
@ -40,8 +39,8 @@ in
'';
};
exportAll = mkOption {
type = types.bool;
exportAll = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''
Publish all directories that look like Git repositories (have the objects
@ -55,8 +54,8 @@ in
'';
};
repositories = mkOption {
type = types.listOf types.str;
repositories = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [];
example = [ "/srv/git" "/home/user/git/repo2" ];
description = ''
@ -68,33 +67,33 @@ in
'';
};
listenAddress = mkOption {
type = types.str;
listenAddress = lib.mkOption {
type = lib.types.str;
default = "";
example = "example.com";
description = "Listen on a specific IP address or hostname.";
};
port = mkOption {
type = types.port;
port = lib.mkOption {
type = lib.types.port;
default = 9418;
description = "Port to listen on.";
};
options = mkOption {
type = types.str;
options = lib.mkOption {
type = lib.types.str;
default = "";
description = "Extra configuration options to be passed to Git daemon.";
};
user = mkOption {
type = types.str;
user = lib.mkOption {
type = lib.types.str;
default = "git";
description = "User under which Git daemon would be running.";
};
group = mkOption {
type = types.str;
group = lib.mkOption {
type = lib.types.str;
default = "git";
description = "Group under which Git daemon would be running.";
};
@ -104,9 +103,9 @@ in
###### implementation
config = mkIf cfg.enable {
config = lib.mkIf cfg.enable {
users.users = optionalAttrs (cfg.user == "git") {
users.users = lib.optionalAttrs (cfg.user == "git") {
git = {
uid = config.ids.uids.git;
group = "git";
@ -114,18 +113,18 @@ in
};
};
users.groups = optionalAttrs (cfg.group == "git") {
users.groups = lib.optionalAttrs (cfg.group == "git") {
git.gid = config.ids.gids.git;
};
systemd.services.git-daemon = {
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
script = "${getExe cfg.package} daemon --reuseaddr "
+ (optionalString (cfg.basePath != "") "--base-path=${cfg.basePath} ")
+ (optionalString (cfg.listenAddress != "") "--listen=${cfg.listenAddress} ")
script = "${lib.getExe cfg.package} daemon --reuseaddr "
+ (lib.optionalString (cfg.basePath != "") "--base-path=${cfg.basePath} ")
+ (lib.optionalString (cfg.listenAddress != "") "--listen=${cfg.listenAddress} ")
+ "--port=${toString cfg.port} --user=${cfg.user} --group=${cfg.group} ${cfg.options} "
+ "--verbose " + (optionalString cfg.exportAll "--export-all ") + concatStringsSep " " cfg.repositories;
+ "--verbose " + (lib.optionalString cfg.exportAll "--export-all ") + lib.concatStringsSep " " cfg.repositories;
};
};