diff --git a/modules/module-list.nix b/modules/module-list.nix index 71ba9d06e24c..ce131b8a55d2 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -44,6 +44,7 @@ ./security/sudo.nix ./services/audio/alsa.nix ./services/audio/pulseaudio.nix + ./services/backup/hydra-mirror.nix ./services/backup/mysql-backup.nix ./services/backup/postgresql-backup.nix ./services/backup/sitecopy-backup.nix diff --git a/modules/services/backup/hydra-mirror.nix b/modules/services/backup/hydra-mirror.nix new file mode 100644 index 000000000000..89971095763a --- /dev/null +++ b/modules/services/backup/hydra-mirror.nix @@ -0,0 +1,93 @@ +{ config, pkgs, ... }: + +with pkgs.lib; + +let + cfg = config.services.hydraChannelMirror ; + mirrorChannel = pkgs.fetchsvn { + url = https://svn.nixos.org/repos/nix/release/trunk/channels/mirror-channel.pl; + rev = 23988; + sha256 = "1h06clvhr3zz378d8fblhwynvzk1smq7fipv7caakakfd31cv8i6"; + }; + cronjob = jobset : '' + ${cfg.period} root perl -I${config.environment.nix}/libexec/nix ${mirrorChannel} \ + ${cfg.hydraURL}/jobset/${jobset.project}/${jobset.jobset}/channel/latest \ + ${cfg.dataDir}/channels/${jobset.relURL} \ + ${cfg.dataDir}/nars \ + ${cfg.mirrorURL}/nars \ + ${cfg.dataDir}/patches \ + ${cfg.mirrorURL}/patches \ + ${if jobset.nixexprs == "" then "" else "${cfg.hydraURL}/job/${jobset.project}/${jobset.jobset}/${jobset.nixexprs}/latest/download-by-type/file/source-dist"} \ + >> ${cfg.dataDir}/logs/${jobset.name}.log + ''; +in +{ + options = { + + services.hydraChannelMirror = { + + enable = mkOption { + default = false; + description = '' + Whether to enable Hydra channel mirroring. + ''; + }; + + period = mkOption { + default = "15 * * * *"; + description = '' + This option defines (in the format used by cron) when the + mirroring should occur. + ''; + }; + + jobsets = mkOption { + default = [ rec { name = "nixpkgs-unstable"; project = "nixpkgs"; jobset = "trunk"; nixexprs = "tarball"; relURL = "nixpkgs/channels/${name}"; } ]; + description = '' + List of jobsets to mirror. + ''; + }; + + hydraURL = mkOption { + default = "http://hydra.nixos.org"; + description = '' + Location (URL) of Hydra instance + ''; + }; + + mirrorURL = mkOption { + default = "http://nixos.org/releases"; + description = '' + Location (URL) of Hydra mirror + ''; + }; + + dataDir = mkOption { + default = "/data/hydra-mirror"; + description = '' + Location of Hydra mirror data + ''; + }; + }; + + }; + + config = mkIf cfg.enable { + + services.cron.systemCronJobs = map cronjob cfg.jobsets ; + + system.activationScripts.hydraChannelMirror = stringAfter [ "stdio" "users" ] + '' + mkdir -m 0755 -p ${cfg.dataDir} + mkdir -m 0755 -p ${cfg.dataDir}/nars + mkdir -m 0755 -p ${cfg.dataDir}/patches + mkdir -m 0755 -p ${cfg.dataDir}/channels + mkdir -m 0755 -p ${cfg.dataDir}/logs + ${concatMapStrings (j : '' + mkdir -m 0755 -p ${cfg.dataDir}/channels/${j.relURL} + '') cfg.jobsets} + ''; + + }; + +}