nixpkgs-update: add new source, derivations with updateScripts

This commit is contained in:
Ryan Mulligan 2021-08-27 13:17:06 -07:00
parent 55a97ceafa
commit b7b2fa0765
3 changed files with 87 additions and 7 deletions

View file

@ -50,6 +50,8 @@ let
};
};
nixpkgs-update-command = "${nixpkgs-update-bin} update-list --pr --outpaths --nixpkgs-review";
in
{
@ -61,14 +63,13 @@ in
extraGroups = [ "r-ryantm" ];
};
systemd.services.nixpkgs-update-repology = mkNixpkgsUpdateService "repology" // {
script = ''
${nixpkgs-update-bin} delete-done --delete
${nixpkgs-update-bin} fetch-repology > /var/lib/nixpkgs-update/repology/packages-to-update-regular.txt
# reverse list
sed '1!G;h;$!d' /var/lib/nixpkgs-update/repology/packages-to-update-regular.txt > /var/lib/nixpkgs-update/repology/packages-to-update.txt
${nixpkgs-update-bin} update-list --pr --outpaths --nixpkgs-review
${nixpkgs-update-command}
'';
};
@ -76,7 +77,7 @@ in
script = ''
${nixpkgs-update-bin} delete-done --delete
${nixpkgs-update-github-releases} > /var/lib/nixpkgs-update/github/packages-to-update.txt
${nixpkgs-update-bin} update-list --pr --outpaths --nixpkgs-review || true
${nixpkgs-update-command}
'';
};
@ -85,7 +86,15 @@ in
${nixpkgs-update-bin} delete-done --delete
grep -rl $XDG_CACHE_HOME/nixpkgs -e buildPython | grep default | \
${nixpkgs-update-pypi-releases} --nixpkgs=/var/cache/nixpkgs-update/pypi/nixpkgs > /var/lib/nixpkgs-update/pypi/packages-to-update.txt
${nixpkgs-update-bin} update-list --pr --outpaths --nixpkgs-review || true
${nixpkgs-update-command}
'';
};
systemd.services.nixpkgs-update-updatescript = mkNixpkgsUpdateService "updatescript" // {
script = ''
${pkgs.nixUnstable}/bin/nix eval --raw -f ${./packages-with-update-script.nix} > /var/lib/nixpkgs-update/updatescript/packages-to-update.txt
${nixpkgs-update-bin} update-list --pr --outpaths --nixpkgs-review --attrpath
${nixpkgs-update-bin} delete-done --delete
'';
};

View file

@ -0,0 +1,71 @@
let
pkgs = import /var/cache/nixpkgs-update/updatescript/nixpkgs {};
in
# code in the following let block was copied from nixos/nixpkgs under
# the MIT License
let
inherit (pkgs) lib;
/* Remove duplicate elements from the list based on some extracted value. O(n^2) complexity.
*/
nubOn = f: list:
if list == [] then
[]
else
let
x = lib.head list;
xs = lib.filter (p: f x != f p) (lib.drop 1 list);
in
[x] ++ nubOn f xs;
/* Recursively find all packages (derivations) in `pkgs` matching `cond` predicate.
Type: packagesWithPath :: AttrPath (AttrPath derivation bool) AttrSet List<AttrSet{attrPath :: str; package :: derivation; }>
AttrPath :: [str]
The packages will be returned as a list of named pairs comprising of:
- attrPath: stringified attribute path (based on `rootPath`)
- package: corresponding derivation
*/
packagesWithPath = rootPath: cond: pkgs:
let
packagesWithPathInner = path: pathContent:
let
result = builtins.tryEval pathContent;
dedupResults = lst: nubOn ({ package, attrPath }: package.updateScript) (lib.concatLists lst);
in
if result.success then
let
evaluatedPathContent = result.value;
in
if lib.isDerivation evaluatedPathContent then
lib.optional (cond path evaluatedPathContent) { attrPath = lib.concatStringsSep "." path; package = evaluatedPathContent; }
else if lib.isAttrs evaluatedPathContent then
# If user explicitly points to an attrSet or it is marked for recursion, we recur.
if path == rootPath || evaluatedPathContent.recurseForDerivations or false || evaluatedPathContent.recurseForRelease or false then
dedupResults (lib.mapAttrsToList (name: elem: packagesWithPathInner (path ++ [name]) elem) evaluatedPathContent)
else []
else []
else [];
in
packagesWithPathInner rootPath pkgs;
/* Recursively find all packages (derivations) in `pkgs` matching `cond` predicate.
*/
packagesWith = packagesWithPath [];
/* Recursively find all packages in `pkgs` with updateScript matching given predicate.
*/
packagesWithUpdateScriptMatchingPredicate = cond:
packagesWith (path: pkg: builtins.hasAttr "updateScript" pkg && cond path pkg);
in
let
allPackagesWithUpdateScript = packagesWithUpdateScriptMatchingPredicate (path: package: true) pkgs;
in
lib.concatMapStrings (p: "${p.attrPath} 0 1\n") allPackagesWithUpdateScript

View file

@ -41,10 +41,10 @@
"homepage": "",
"owner": "ryantm",
"repo": "nixpkgs-update",
"rev": "a0a53c2d765b2f85ed6b1f7ee53e4c5638cbd2de",
"sha256": "1zk3fp2r8mx2fcqxncd4aklmk9fma5qqm0xy36v8q74jlfjzs412",
"rev": "7267bc6968583ed486e9575f6498c877a6680a8f",
"sha256": "14x03kg6h3chkwafxnign3xfvpgg2l817vaicpa1hb43z1xlmwmr",
"type": "tarball",
"url": "https://github.com/ryantm/nixpkgs-update/archive/a0a53c2d765b2f85ed6b1f7ee53e4c5638cbd2de.tar.gz",
"url": "https://github.com/ryantm/nixpkgs-update/archive/7267bc6968583ed486e9575f6498c877a6680a8f.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"nixpkgs-update-github-releases": {