6 , include-overlays ? false
11 # TODO: add assert statements
14 pkgs = import ./../../default.nix (
15 if include-overlays == false then
17 else if include-overlays == true then
18 { } # Let Nixpkgs include overlays impurely.
19 else { overlays = include-overlays; }
24 /* Remove duplicate elements from the list based on some extracted value. O(n^2) complexity.
32 xs = lib.filter (p: f x != f p) (lib.drop 1 list);
36 /* Recursively find all packages (derivations) in `pkgs` matching `cond` predicate.
38 Type: packagesWithPath :: AttrPath → (AttrPath → derivation → bool) → AttrSet → List<AttrSet{attrPath :: str; package :: derivation; }>
41 The packages will be returned as a list of named pairs comprising of:
42 - attrPath: stringified attribute path (based on `rootPath`)
43 - package: corresponding derivation
45 packagesWithPath = rootPath: cond: pkgs:
47 packagesWithPathInner = path: pathContent:
49 result = builtins.tryEval pathContent;
51 somewhatUniqueRepresentant =
52 { package, attrPath }: {
53 inherit (package) updateScript;
54 # Some updaters use the same `updateScript` value for all packages.
55 # Also compare `meta.description`.
56 position = package.meta.position or null;
57 # We cannot always use `meta.position` since it might not be available
58 # or it might be shared among multiple packages.
61 dedupResults = lst: nubOn somewhatUniqueRepresentant (lib.concatLists lst);
63 if result.success then
65 evaluatedPathContent = result.value;
67 if lib.isDerivation evaluatedPathContent then
68 lib.optional (cond path evaluatedPathContent) { attrPath = lib.concatStringsSep "." path; package = evaluatedPathContent; }
69 else if lib.isAttrs evaluatedPathContent then
70 # If user explicitly points to an attrSet or it is marked for recursion, we recur.
71 if path == rootPath || evaluatedPathContent.recurseForDerivations or false || evaluatedPathContent.recurseForRelease or false then
72 dedupResults (lib.mapAttrsToList (name: elem: packagesWithPathInner (path ++ [name]) elem) evaluatedPathContent)
77 packagesWithPathInner rootPath pkgs;
79 /* Recursively find all packages (derivations) in `pkgs` matching `cond` predicate.
81 packagesWith = packagesWithPath [];
83 /* Recursively find all packages in `pkgs` with updateScript matching given predicate.
85 packagesWithUpdateScriptMatchingPredicate = cond:
86 packagesWith (path: pkg: builtins.hasAttr "updateScript" pkg && cond path pkg);
88 /* Recursively find all packages in `pkgs` with updateScript by given maintainer.
90 packagesWithUpdateScriptAndMaintainer = maintainer':
93 if ! builtins.hasAttr maintainer' lib.maintainers then
94 builtins.throw "Maintainer with name `${maintainer'} does not exist in `maintainers/maintainer-list.nix`."
96 builtins.getAttr maintainer' lib.maintainers;
98 packagesWithUpdateScriptMatchingPredicate (path: pkg:
99 (if builtins.hasAttr "maintainers" pkg.meta
100 then (if builtins.isList pkg.meta.maintainers
101 then builtins.elem maintainer pkg.meta.maintainers
102 else maintainer == pkg.meta.maintainers
108 /* Recursively find all packages under `path` in `pkgs` with updateScript.
110 packagesWithUpdateScript = path: pkgs:
112 prefix = lib.splitString "." path;
113 pathContent = lib.attrByPath prefix null pkgs;
115 if pathContent == null then
116 builtins.throw "Attribute path `${path}` does not exist."
118 packagesWithPath prefix (path: pkg: builtins.hasAttr "updateScript" pkg)
121 /* Find a package under `path` in `pkgs` and require that it has an updateScript.
123 packageByName = path: pkgs:
125 package = lib.attrByPath (lib.splitString "." path) null pkgs;
127 if package == null then
128 builtins.throw "Package with an attribute name `${path}` does not exist."
129 else if ! builtins.hasAttr "updateScript" package then
130 builtins.throw "Package with an attribute name `${path}` does not have a `passthru.updateScript` attribute defined."
132 { attrPath = path; inherit package; };
134 /* List of packages matched based on the CLI arguments.
137 if package != null then
138 [ (packageByName package pkgs) ]
139 else if predicate != null then
140 packagesWithUpdateScriptMatchingPredicate predicate pkgs
141 else if maintainer != null then
142 packagesWithUpdateScriptAndMaintainer maintainer pkgs
143 else if path != null then
144 packagesWithUpdateScript path pkgs
146 builtins.throw "No arguments provided.\n\n${helpText}";
151 % nix-shell maintainers/scripts/update.nix --argstr maintainer garbas
153 to run all update scripts for all packages that lists \`garbas\` as a maintainer
154 and have \`updateScript\` defined, or:
156 % nix-shell maintainers/scripts/update.nix --argstr package gnome.nautilus
158 to run update script for specific package, or
160 % nix-shell maintainers/scripts/update.nix --arg predicate '(path: pkg: pkg.updateScript.name or null == "gnome-update-script")'
162 to run update script for all packages matching given predicate, or
164 % nix-shell maintainers/scripts/update.nix --argstr path gnome
166 to run update script for all package under an attribute path.
170 --argstr max-workers 8
172 to increase the number of jobs in parallel, or
174 --argstr keep-going true
176 to continue running when a single update fails.
178 You can also make the updater automatically commit on your behalf from updateScripts
179 that support it by adding
184 /* Transform a matched package into an object for update.py.
186 packageData = { package, attrPath }: {
188 pname = lib.getName package;
189 oldVersion = lib.getVersion package;
190 updateScript = map builtins.toString (lib.toList (package.updateScript.command or package.updateScript));
191 supportedFeatures = package.updateScript.supportedFeatures or [];
192 attrPath = package.updateScript.attrPath or attrPath;
195 /* JSON file with data for update.py.
197 packagesJson = pkgs.writeText "packages.json" (builtins.toJSON (map packageData packages));
200 lib.optional (max-workers != null) "--max-workers=${max-workers}"
201 ++ lib.optional (keep-going == "true") "--keep-going"
202 ++ lib.optional (commit == "true") "--commit";
204 args = [ packagesJson ] ++ optionalArgs;
206 in pkgs.stdenv.mkDerivation {
207 name = "nixpkgs-update-script";
210 echo "----------------------------------------------------------------"
212 echo "Not possible to update packages using \`nix-build\`"
215 echo "----------------------------------------------------------------"
219 unset shellHook # do not contaminate nested shells
220 exec ${pkgs.python3.interpreter} ${./update.py} ${builtins.concatStringsSep " " args}