xin/lib/default.nix

101 lines
2.4 KiB
Nix

{ lib, ... }:
let
inherit (builtins) toString readFile fromJSON filter;
getPrStatus = pr:
let
prstr = toString pr;
prStatus = fromJSON (readFile ../pull_requests/${prstr}.json);
in prStatus;
prIsOpen = {
option = pr: a:
let prStatus = getPrStatus pr;
in if prStatus.status == "open" then a else { };
pkg = pr: localPkg: upstreamPkg:
let prStatus = getPrStatus pr;
in if prStatus.status == "open" then
localPkg
else
lib.warn
"PR: ${toString pr} (${prStatus.title}) is complete, ignoring pkg..."
upstreamPkg;
overlay = pr: overlay:
let prStatus = getPrStatus pr;
in if pr == 0 || prStatus.status == "open" then
overlay
else
lib.warn "PR: ${
toString pr
} (${prStatus.title}) is complete, ignoring overlay..." (_: _: { });
};
todo = msg: lib.warn "TODO: ${msg}";
filterList = pkgList: filter (x: x != null) pkgList;
mkCronScript = name: src: ''
. /etc/profile;
set -x
# autogenreated ${name}
${src}
'';
jobToUserService = job: {
name = "${job.name}";
value = {
script = mkCronScript "${job.name}_script" job.script;
inherit (job) startAt path;
serviceConfig = { Type = "oneshot"; };
};
};
jobToService = job: {
name = "${job.name}";
value = {
script = mkCronScript "${job.name}_script" job.script;
inherit (job) startAt path;
serviceConfig = {
User = "${job.user}";
Type = "oneshot";
};
};
};
buildShell = pkgs:
pkgs.mkShell {
shellHook = ''
PS1='\u@\h:\w; '
( . ./common.sh; start ) || true;
'';
nativeBuildInputs = with pkgs; [
curl
deadnix
git
git-bug
jo
jq
nil
nix-diff
nix-output-monitor
shfmt
sops
ssh-to-age
ssh-to-pgp
statix
];
};
# Set our configurationRevison based on the status of our git repo.
# If the repo is dirty, disable autoUpgrade as it means we are
# testing something.
buildVer = self:
let state = self.rev or "DIRTY";
in {
system.configurationRevision = state;
system.autoUpgrade.enable = lib.mkDefault (state != "DIRTY");
};
xinlib = {
inherit buildVer mkCronScript jobToUserService jobToService buildShell
prIsOpen filterList todo;
};
in xinlib