Browse Source

Crond and cronie

Signed-off-by: Magic_RB <magic_rb@redalder.org>
master
Magic_RB 1 month ago
parent
commit
f844d70db1
Signed by: Magic_RB GPG Key ID: 08D5287CC5DDCA0E
6 changed files with 137 additions and 14 deletions
  1. +25
    -0
      examples/crond/default.nix
  2. +2
    -0
      flake.nix
  3. +0
    -13
      modules/runit/stage-2.sh
  4. +97
    -0
      modules/services/crond.nix
  5. +12
    -0
      overlay/cronie.nix
  6. +1
    -1
      overlay/default.nix

+ 25
- 0
examples/crond/default.nix View File

@ -0,0 +1,25 @@
nglib:
(nglib "x86_64-linux").makeSystem {
system = "x86_64-linux";
name = "nixng-crond";
config = ({ pkgs, config, ... }:
{
config = {
dumb-init.enable = true;
services.crond = {
enable = true;
crontabs = {
hydra = {
environment = {
PATH="${pkgs.busybox}/bin";
};
jobs = [
''*/2 * * * * root echo "asd"''
];
};
};
};
};
}
);
}

+ 2
- 0
flake.nix View File

@ -31,11 +31,13 @@
writeSubstitutedShellScript = callPackage ./lib/write-substituted-shell-script.nix {};
writeSubstitutedFile = callPackage ./lib/write-substituted-file.nix {};
writeSubstitutedShellScriptBin = callPackage ./lib/write-substituted-shell-script-bin.nix {};
dag = callPackage ./lib/dag.nix {};
};
giteaSystem = import ./examples/gitea self.lib;
apacheSystem = import ./examples/apache self.lib;
apacheRunitSystem = import ./examples/apache-runit self.lib;
crondSystem = import ./examples/crond self.lib;
overlay = import ./overlay;
packages = nixpkgs.lib.genAttrs


+ 0
- 13
modules/runit/stage-2.sh View File

@ -2,17 +2,4 @@ export PATH=@runit@/bin:@findutils@/bin:@busybox@/bin
echo "<--- Stage 2.2 --->"
mkdir -p @runtimeServiceDirectory@
function linkFarm() {
src="$1"
dst="$2"
find "$src" -mindepth 1 -type d -printf "%P\n" | xargs -I {} mkdir "$dst/{}"
find "$src" -mindepth 1 -type f -printf "%P\n" | xargs -I {} ln -s "$src/{}" "$dst/{}"
find "$src" -mindepth 1 -type l -printf "%P\n" | xargs -I {} cp "$src/{}" "$dst/{}"
}
linkFarm @serviceDir@ @runtimeServiceDirectory@
runsvdir @runtimeServiceDirectory@

+ 97
- 0
modules/services/crond.nix View File

@ -0,0 +1,97 @@
{ config, nglib, lib, pkgs, ... }:
with lib;
let
cfg = config.services.crond;
in
{
options.services.crond = {
enable = mkEnableOption "Enable crond, the daemon to execute scheduled commands, specifically cronie.";
package = mkOption {
type = types.package;
description = "The package which contains a cron implementation.";
default = pkgs.cronie;
};
crontabs = mkOption {
type = with types; attrsOf (submodule {
options = {
environment = mkOption {
type = attrsOf str;
description = ''
A set of environment variable to set for this specific crontab.
'';
example = ''
{
MAILTO="root";
}
'';
default = {};
};
jobs = mkOption {
type = listOf str;
description = ''
A list of job entries, in the usual cron format.
'';
example = ''
[
"5 0 * * * www-data rm /var/log/{httpd.access,httpd.error}"
]
'';
default = [];
};
};
});
description = ''
Defines cron jobs, allows for the creation of multiple files and entries.
'';
default = {};
example = ''
{
"delete-log" = {
environment = {
MAILTO="root";
};
jobs = [
"5 0 * * * www-data rm /var/log/{httpd.access,httpd.error}"
];
};
}
'';
apply = x:
let
cronfiles =
(mapAttrsToList
(n: v: pkgs.writeText n
''
${concatStringsSep "\n" (mapAttrsToList (n: v: ''"${n}"="${v}"'') v.environment)}
${concatStringsSep "\n" v.jobs}
'')
x);
in
pkgs.runCommandNoCCLocal "cron.d" {} ''
CRONFILES="${concatStringsSep " " cronfiles}"
mkdir -p $out
for cronfile in "$CRONFILES" ; do
ln -s "$cronfile" $out/$(basename "$cronfile")
done
'';
};
};
config = mkIf cfg.enable {
system.activation."crond" = nglib.dag.dagEntryAnywhere
''
mkdir -p /etc /var/run /var/spool/cron /var/cron
ln -s ${cfg.crontabs}/ /etc/cron.d
ls -lahR /etc/cron.d/
'';
init.services.crond =
{
script = ''
${cfg.package}/bin/crond -n -x ext,sch,misc
'';
};
};
}

+ 12
- 0
overlay/cronie.nix View File

@ -0,0 +1,12 @@
{ stdenv, lib, fetchurl }:
stdenv.mkDerivation {
name = "cronie";
version = "1.5.7";
configureFlags = "--localstatedir=/var --sysconfdir=/etc";
src = fetchurl {
url = "https://github.com/cronie-crond/cronie/releases/download/cronie-1.5.7/cronie-1.5.7.tar.gz";
sha256 = "sha256-U4vPry6Yblrh7fbRRyp36oJx1qkAWu4kl6ntbhMyDrM=";
};
}

+ 1
- 1
overlay/default.nix View File

@ -3,7 +3,7 @@ let
callPackage = super.callPackage;
in
{
bootloaderLinux = callPackage ./bootloader-linux.nix {};
tinyLinux = callPackage ./tiny-linux.nix {};
runVmLinux = callPackage ./run-vm-linux.nix {};
cronie = callPackage ./cronie.nix {};
}

Loading…
Cancel
Save