xin/lib/default.nix

92 lines
2.2 KiB
Nix
Raw Normal View History

{ lib, ... }:
2023-02-02 05:35:19 -07:00
let
inherit (builtins) toString readFile fromJSON filter;
getPrStatus = pr:
2023-05-23 12:05:33 -06:00
let
prstr = toString pr;
prStatus = fromJSON (readFile ../pull_requests/${prstr}.json);
in prStatus;
prIsOpen = {
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;
2023-06-06 11:08:47 -06:00
in if pr == 0 || prStatus.status == "open" then
overlay
else
lib.warn "PR: ${
toString pr
} (${prStatus.title}) is complete, ignoring overlay..." (_: _: { });
};
filterList = pkgList: filter (x: x != null) pkgList;
2023-02-02 05:35:19 -07:00
mkCronScript = name: src: ''
. /etc/profile;
set -x
# autogenreated ${name}
${src}
'';
2023-03-03 07:06:30 -07:00
jobToUserService = job: {
name = "${job.name}";
value = {
script = mkCronScript "${job.name}_script" job.script;
inherit (job) startAt path;
};
};
2023-02-02 05:35:19 -07:00
jobToService = job: {
name = "${job.name}";
value = {
script = mkCronScript "${job.name}_script" job.script;
inherit (job) startAt path;
serviceConfig = { User = "${job.user}"; };
2023-02-02 05:35:19 -07:00
};
};
buildShell = pkgs:
pkgs.mkShell {
shellHook = ''
PS1='\u@\h:\w; '
( . ./common.sh; start ) || true;
'';
nativeBuildInputs = with pkgs; [
2023-05-23 12:05:33 -06:00
curl
deadnix
git
2023-03-02 06:34:36 -07:00
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");
};
2023-02-02 05:35:19 -07:00
xinlib = {
2023-05-23 12:05:33 -06:00
inherit buildVer mkCronScript jobToUserService jobToService buildShell
prIsOpen filterList;
};
2023-02-02 05:35:19 -07:00
in xinlib