2022-04-10 22:08:57 +02:00
|
|
|
{ nixpkgs-update
|
|
|
|
, nixpkgs-update-github-releases
|
|
|
|
, nixpkgs-update-pypi-releases
|
|
|
|
}:
|
2020-01-15 00:15:23 -08:00
|
|
|
{ pkgs, lib, config, ... }:
|
|
|
|
let
|
|
|
|
userLib = import ../users/lib.nix { inherit lib; };
|
|
|
|
|
2022-07-28 20:47:41 -07:00
|
|
|
nixpkgs-update-bin = "/var/lib/nixpkgs-update/bin/nixpkgs-update";
|
2020-08-01 09:54:23 -07:00
|
|
|
|
2020-01-15 00:15:23 -08:00
|
|
|
nixpkgsUpdateSystemDependencies = with pkgs; [
|
2020-07-21 06:28:51 -07:00
|
|
|
nix # for nix-shell used by python packges to update fetchers
|
2020-10-11 07:21:54 -07:00
|
|
|
git # used by update-scripts
|
2020-03-29 23:59:38 -07:00
|
|
|
gnugrep
|
2021-08-21 10:25:47 -07:00
|
|
|
gnused
|
2020-02-05 20:33:57 -08:00
|
|
|
curl
|
2021-10-26 10:10:29 -07:00
|
|
|
getent # used by hub
|
2021-12-05 10:25:05 -08:00
|
|
|
cachix
|
2020-08-01 09:54:23 -07:00
|
|
|
];
|
2020-01-15 00:15:23 -08:00
|
|
|
|
2022-04-10 22:08:57 +02:00
|
|
|
nixpkgs-update-github-releases' = "${nixpkgs-update-github-releases}/main.py";
|
|
|
|
nixpkgs-update-pypi-releases' = "${nixpkgs-update-pypi-releases}/main.py";
|
2020-01-25 15:05:09 -08:00
|
|
|
|
2022-07-27 19:34:53 -07:00
|
|
|
mkWorker = name: {
|
2022-09-07 15:53:26 -07:00
|
|
|
after = [ "network-online.target" ];
|
2022-07-27 19:34:53 -07:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2021-08-12 21:43:34 -07:00
|
|
|
description = "nixpkgs-update ${name} service";
|
2020-06-13 20:23:50 -07:00
|
|
|
enable = true;
|
2022-07-27 19:34:53 -07:00
|
|
|
restartIfChanged = true;
|
2020-01-15 00:15:23 -08:00
|
|
|
path = nixpkgsUpdateSystemDependencies;
|
2022-07-27 19:34:53 -07:00
|
|
|
environment.XDG_CONFIG_HOME = "/var/lib/nixpkgs-update/worker";
|
|
|
|
environment.XDG_CACHE_HOME = "/var/cache/nixpkgs-update/worker";
|
2022-09-07 15:53:26 -07:00
|
|
|
environment.XDG_RUNTIME_DIR = "/run/nixpkgs-update-worker"; # for nix-update update scripts
|
2020-01-15 00:15:23 -08:00
|
|
|
|
2021-01-03 00:07:49 +01:00
|
|
|
serviceConfig = {
|
2020-10-11 10:07:31 -07:00
|
|
|
Type = "simple";
|
|
|
|
User = "r-ryantm";
|
|
|
|
Group = "r-ryantm";
|
2022-07-27 19:34:53 -07:00
|
|
|
Restart = "on-abort";
|
|
|
|
RestartSec = "5s";
|
|
|
|
WorkingDirectory = "/var/lib/nixpkgs-update/worker";
|
|
|
|
StateDirectory = "nixpkgs-update/worker";
|
2020-10-11 10:07:31 -07:00
|
|
|
StateDirectoryMode = "700";
|
2022-07-27 19:34:53 -07:00
|
|
|
CacheDirectory = "nixpkgs-update/worker";
|
2020-10-11 10:07:31 -07:00
|
|
|
CacheDirectoryMode = "700";
|
2022-07-27 19:34:53 -07:00
|
|
|
LogsDirectory = "nixpkgs-update/";
|
2020-10-11 10:07:31 -07:00
|
|
|
LogsDirectoryMode = "755";
|
2022-09-07 15:53:26 -07:00
|
|
|
RuntimeDirectory = "nixpkgs-update-worker";
|
2020-10-24 14:00:47 -07:00
|
|
|
RuntimeDirectoryMode = "700";
|
2020-10-11 10:07:31 -07:00
|
|
|
StandardOutput = "journal";
|
|
|
|
};
|
2022-07-27 19:34:53 -07:00
|
|
|
|
|
|
|
script = ''
|
|
|
|
pipe=/var/lib/nixpkgs-update/fifo
|
|
|
|
|
|
|
|
if [[ ! -p $pipe ]]; then
|
|
|
|
mkfifo $pipe || true
|
|
|
|
fi
|
|
|
|
|
|
|
|
exec 8<$pipe
|
|
|
|
while true
|
|
|
|
do
|
|
|
|
if read -u 8 line; then
|
|
|
|
set -x
|
|
|
|
${nixpkgs-update-bin} update-batch --pr --outpaths --nixpkgs-review "$line" || true
|
|
|
|
set +x
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
'';
|
2021-08-12 21:43:34 -07:00
|
|
|
};
|
|
|
|
|
2022-07-27 19:34:53 -07:00
|
|
|
mkFetcher = cmd: {
|
2022-09-07 15:53:26 -07:00
|
|
|
after = [ "network-online.target" ];
|
2022-07-27 19:34:53 -07:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
path = nixpkgsUpdateSystemDependencies;
|
|
|
|
# API_TOKEN is used by nixpkgs-update-github-releases
|
|
|
|
environment.API_TOKEN_FILE = "/var/lib/nixpkgs-update/github_token_with_username.txt";
|
|
|
|
# Used by nixpkgs-update-github-releases to install python dependencies
|
|
|
|
# Used by nixpkgs-update-pypi-releases
|
|
|
|
environment.NIX_PATH = "nixpkgs=/var/cache/nixpkgs-update/fetcher/nixpkgs";
|
|
|
|
environment.XDG_CACHE_HOME = "/var/cache/nixpkgs-update/fetcher/";
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
|
|
|
User = "r-ryantm";
|
|
|
|
Group = "r-ryantm";
|
|
|
|
Restart = "on-abort";
|
|
|
|
RestartSec = "5s";
|
|
|
|
WorkingDirectory = "/var/lib/nixpkgs-update/";
|
|
|
|
StateDirectory = "nixpkgs-update";
|
|
|
|
StateDirectoryMode = "700";
|
2022-09-07 15:53:26 -07:00
|
|
|
CacheDirectory = "nixpkgs-update/worker";
|
|
|
|
CacheDirectoryMode = "700";
|
2022-07-27 19:34:53 -07:00
|
|
|
};
|
|
|
|
script = ''
|
|
|
|
pipe=/var/lib/nixpkgs-update/fifo
|
|
|
|
|
|
|
|
if [[ ! -p $pipe ]]; then
|
|
|
|
mkfifo $pipe || true
|
|
|
|
fi
|
|
|
|
|
2022-12-16 18:27:20 -05:00
|
|
|
${cmd} | sort -R > $pipe
|
2022-07-27 19:34:53 -07:00
|
|
|
'';
|
|
|
|
};
|
2021-08-27 13:17:06 -07:00
|
|
|
|
2021-08-12 21:43:34 -07:00
|
|
|
in
|
|
|
|
{
|
|
|
|
users.groups.r-ryantm = { };
|
|
|
|
users.users.r-ryantm = {
|
|
|
|
useDefaultShell = true;
|
|
|
|
isNormalUser = true; # The hub cli seems to really want stuff to be set up like a normal user
|
|
|
|
uid = userLib.mkUid "rrtm";
|
|
|
|
extraGroups = [ "r-ryantm" ];
|
|
|
|
};
|
|
|
|
|
2022-07-27 19:34:53 -07:00
|
|
|
systemd.services.nixpkgs-update-delete-done = {
|
|
|
|
startAt = "daily";
|
2022-09-07 15:53:26 -07:00
|
|
|
after = [ "network-online.target" ];
|
2022-07-27 19:34:53 -07:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
description = "nixpkgs-update delete done branches";
|
|
|
|
restartIfChanged = true;
|
|
|
|
path = nixpkgsUpdateSystemDependencies;
|
|
|
|
environment.XDG_CONFIG_HOME = "/var/lib/nixpkgs-update/worker";
|
|
|
|
environment.XDG_CACHE_HOME = "/var/cache/nixpkgs-update/worker";
|
2020-01-15 00:15:23 -08:00
|
|
|
|
2022-07-27 19:34:53 -07:00
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
|
|
|
User = "r-ryantm";
|
|
|
|
Group = "r-ryantm";
|
|
|
|
Restart = "on-abort";
|
|
|
|
RestartSec = "5s";
|
|
|
|
WorkingDirectory = "/var/lib/nixpkgs-update/worker";
|
|
|
|
StateDirectory = "nixpkgs-update/worker";
|
|
|
|
StateDirectoryMode = "700";
|
|
|
|
CacheDirectoryMode = "700";
|
|
|
|
LogsDirectory = "nixpkgs-update/";
|
|
|
|
LogsDirectoryMode = "755";
|
|
|
|
StandardOutput = "journal";
|
|
|
|
};
|
2021-08-12 21:43:34 -07:00
|
|
|
|
2022-07-27 19:34:53 -07:00
|
|
|
script = "${nixpkgs-update-bin} delete-done --delete";
|
2021-08-27 13:17:06 -07:00
|
|
|
};
|
|
|
|
|
2022-07-27 19:34:53 -07:00
|
|
|
systemd.services.nixpkgs-update-fetch-repology = mkFetcher "${nixpkgs-update-bin} fetch-repology";
|
2022-11-29 18:13:41 +10:00
|
|
|
systemd.services.nixpkgs-update-fetch-updatescript = mkFetcher "${pkgs.nix}/bin/nix eval --raw -f ${./packages-with-update-script.nix}";
|
2022-07-27 19:34:53 -07:00
|
|
|
systemd.services.nixpkgs-update-fetch-pypi = mkFetcher "grep -rl $XDG_CACHE_HOME/nixpkgs -e buildPython | grep default | ${nixpkgs-update-pypi-releases'} --nixpkgs=/var/cache/nixpkgs-update/fetcher/nixpkgs";
|
|
|
|
systemd.services.nixpkgs-update-fetch-github = mkFetcher nixpkgs-update-github-releases';
|
|
|
|
|
|
|
|
systemd.services.nixpkgs-update-worker1 = mkWorker "worker1";
|
|
|
|
systemd.services.nixpkgs-update-worker2 = mkWorker "worker2";
|
2022-11-10 14:42:41 +01:00
|
|
|
# Too many workers cause out-of-memory.
|
|
|
|
#systemd.services.nixpkgs-update-worker3 = mkWorker "worker3";
|
|
|
|
#systemd.services.nixpkgs-update-worker4 = mkWorker "worker4";
|
2020-01-15 00:15:23 -08:00
|
|
|
|
2021-09-22 21:21:09 -07:00
|
|
|
systemd.tmpfiles.rules = [
|
2022-08-13 07:33:20 -07:00
|
|
|
"L+ /home/r-ryantm/.gitconfig - - - - ${./gitconfig.txt}"
|
2021-10-26 17:24:07 -07:00
|
|
|
"d /home/r-ryantm/.ssh 700 r-ryantm r-ryantm - -"
|
2022-07-27 19:34:53 -07:00
|
|
|
|
|
|
|
"e /var/cache/nixpkgs-update/worker/nixpkgs-review - - - 1d -"
|
|
|
|
|
2022-08-13 07:33:20 -07:00
|
|
|
"L+ /var/lib/nixpkgs-update/bin/nixpkgs-update - - - - ${nixpkgs-update.defaultPackage.${pkgs.system}}/bin/nixpkgs-update"
|
|
|
|
"L+ /var/lib/nixpkgs-update/worker/github_token.txt - - - - ${config.sops.secrets.github-r-ryantm-token.path}"
|
|
|
|
"L+ /var/lib/nixpkgs-update/worker/cachix/cachix.dhall - - - - ${config.sops.secrets.nix-community-cachix.path}"
|
2022-07-27 19:34:53 -07:00
|
|
|
];
|
2021-12-05 18:08:09 -08:00
|
|
|
|
2021-10-26 10:10:29 -07:00
|
|
|
sops.secrets.github-r-ryantm-key = {
|
|
|
|
path = "/home/r-ryantm/.ssh/id_rsa";
|
|
|
|
owner = "r-ryantm";
|
|
|
|
group = "r-ryantm";
|
|
|
|
};
|
|
|
|
|
|
|
|
sops.secrets.github-r-ryantm-token = {
|
|
|
|
path = "/var/lib/nixpkgs-update/github_token.txt";
|
|
|
|
owner = "r-ryantm";
|
|
|
|
group = "r-ryantm";
|
|
|
|
};
|
|
|
|
|
|
|
|
sops.secrets.github-token-with-username = {
|
|
|
|
path = "/var/lib/nixpkgs-update/github_token_with_username.txt";
|
|
|
|
owner = "r-ryantm";
|
|
|
|
group = "r-ryantm";
|
|
|
|
};
|
|
|
|
|
2021-12-05 12:18:21 -08:00
|
|
|
sops.secrets.nix-community-cachix = {
|
2021-12-05 13:46:25 -08:00
|
|
|
path = "/home/r-ryantm/.config/cachix/cachix.dhall";
|
2022-11-17 08:57:22 +10:00
|
|
|
sopsFile = ../roles/nix-community-cache/secrets.yaml;
|
2021-12-05 18:08:09 -08:00
|
|
|
owner = "r-ryantm";
|
|
|
|
group = "r-ryantm";
|
2021-12-05 12:18:21 -08:00
|
|
|
};
|
|
|
|
|
2020-03-21 19:05:01 -07:00
|
|
|
services.nginx.virtualHosts."r.ryantm.com" = {
|
|
|
|
forceSSL = true;
|
|
|
|
enableACME = true;
|
|
|
|
locations."/log/" = {
|
|
|
|
alias = "/var/log/nixpkgs-update/";
|
2020-07-03 20:26:52 -07:00
|
|
|
extraConfig = ''
|
|
|
|
charset utf-8;
|
|
|
|
autoindex on;
|
|
|
|
'';
|
2020-03-21 19:05:01 -07:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-01-15 00:15:23 -08:00
|
|
|
}
|