1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-11-18 11:40:45 +00:00

nixos/services.jenkins.jobBuilder: remove with lib;

This commit is contained in:
Felix Buehler 2024-08-27 20:42:55 +02:00
parent 4b3987ab25
commit 5fb90466e8

View file

@ -1,7 +1,4 @@
{ config, lib, pkgs, ... }:
with lib;
let
jenkinsCfg = config.services.jenkins;
cfg = config.services.jenkins.jobBuilder;
@ -9,7 +6,7 @@ let
in {
options = {
services.jenkins.jobBuilder = {
enable = mkEnableOption ''
enable = lib.mkEnableOption ''
the Jenkins Job Builder (JJB) service. It
allows defining jobs for Jenkins in a declarative manner.
@ -24,17 +21,17 @@ in {
<https://jenkins-job-builder.readthedocs.io/>
'';
accessUser = mkOption {
accessUser = lib.mkOption {
default = "admin";
type = types.str;
type = lib.types.str;
description = ''
User id in Jenkins used to reload config.
'';
};
accessToken = mkOption {
accessToken = lib.mkOption {
default = "";
type = types.str;
type = lib.types.str;
description = ''
User token in Jenkins used to reload config.
WARNING: This token will be world readable in the Nix store. To keep
@ -42,10 +39,10 @@ in {
'';
};
accessTokenFile = mkOption {
accessTokenFile = lib.mkOption {
default = "${config.services.jenkins.home}/secrets/initialAdminPassword";
defaultText = literalExpression ''"''${config.services.jenkins.home}/secrets/initialAdminPassword"'';
type = types.str;
defaultText = lib.literalExpression ''"''${config.services.jenkins.home}/secrets/initialAdminPassword"'';
type = lib.types.str;
example = "/run/keys/jenkins-job-builder-access-token";
description = ''
File containing the API token for the {option}`accessUser`
@ -53,9 +50,9 @@ in {
'';
};
yamlJobs = mkOption {
yamlJobs = lib.mkOption {
default = "";
type = types.lines;
type = lib.types.lines;
example = ''
- job:
name: jenkins-job-test-1
@ -67,10 +64,10 @@ in {
'';
};
jsonJobs = mkOption {
jsonJobs = lib.mkOption {
default = [ ];
type = types.listOf types.str;
example = literalExpression ''
type = lib.types.listOf lib.types.str;
example = lib.literalExpression ''
[
'''
[ { "job":
@ -87,10 +84,10 @@ in {
'';
};
nixJobs = mkOption {
nixJobs = lib.mkOption {
default = [ ];
type = types.listOf types.attrs;
example = literalExpression ''
type = lib.types.listOf lib.types.attrs;
example = lib.literalExpression ''
[ { job =
{ name = "jenkins-job-test-3";
builders = [
@ -110,7 +107,7 @@ in {
};
};
config = mkIf (jenkinsCfg.enable && cfg.enable) {
config = lib.mkIf (jenkinsCfg.enable && cfg.enable) {
assertions = [
{ assertion =
if cfg.accessUser != ""
@ -213,7 +210,7 @@ in {
# Create / update jobs
mkdir -p ${jobBuilderOutputDir}
for inputFile in ${yamlJobsFile} ${concatStringsSep " " jsonJobsFiles}; do
for inputFile in ${yamlJobsFile} ${lib.concatStringsSep " " jsonJobsFiles}; do
HOME="${jenkinsCfg.home}" "${pkgs.jenkins-job-builder}/bin/jenkins-jobs" --ignore-cache test --config-xml -o "${jobBuilderOutputDir}" "$inputFile"
done
@ -237,7 +234,7 @@ in {
jobdir="${jenkinsCfg.home}/$jenkinsjobname"
rm -rf "$jobdir"
done
'' + (optionalString (cfg.accessUser != "") reloadScript);
'' + (lib.optionalString (cfg.accessUser != "") reloadScript);
serviceConfig = {
Type = "oneshot";
User = jenkinsCfg.user;