refactor so that my update scripts can apply to the nixpkgs bootstrap

This commit is contained in:
2024-10-03 12:19:27 +00:00
parent 16ded395fd
commit 083dcd03f7
6 changed files with 43 additions and 27 deletions

View File

@@ -7,7 +7,7 @@
{ }: { }:
let let
mkPkgs = branch: args: ( mkPkgs = branch: args: (
import ./pkgs/by-name/nixpkgs/package.nix args import ./pkgs/by-name/nixpkgs-bootstrap/package.nix args
)."${branch}".extend (import ./overlays/all.nix); )."${branch}".extend (import ./overlays/all.nix);
pkgs = mkPkgs "master" {}; pkgs = mkPkgs "master" {};
inherit (pkgs) lib; inherit (pkgs) lib;
@@ -78,25 +78,37 @@ let
) )
attrs; attrs;
# update only packages maintained by me:
# shouldUpdate = pkg: let
# maintainers = ((pkg.meta or {}).maintainers or []);
# in
# pkg ? updateScript &&
# (lib.elem lib.maintainers.colinsane maintainers || maintainers == [])
# ;
# update any package possible, and just rely on good namespacing:
shouldUpdate = pkg: pkg ? updateScript;
# given the path to a package, and that package, returns a list of all attr-paths (stringified) # given the path to a package, and that package, returns a list of all attr-paths (stringified)
# which should be updated as part of that package (including the package in question). # which should be updated as part of that package (including the package in question).
mkUpdateList = prefix: pkg: (lib.optionals (pkg ? updateScript) [ prefix ]) ++ mkUpdateList = prefix: pkg: (lib.optionals (shouldUpdate pkg) [ prefix ]) ++
lib.foldl' lib.concatMap
(acc: nestedName: acc ++ mkUpdateListIfAuto "${prefix}.${nestedName}" pkg."${nestedName}") (nestedName: mkUpdateListIfAuto "${prefix}.${nestedName}" pkg."${nestedName}")
[]
(lib.optionals (pkg.recurseForDerivations or false) (subAttrNames pkg)) (lib.optionals (pkg.recurseForDerivations or false) (subAttrNames pkg))
; ;
# a package can set `passthru.updateWithSuper = false;` if it doesn't want to be auto-updated. # a package can set `passthru.updateWithSuper = false;` if it doesn't want to be auto-updated.
mkUpdateListIfAuto = prefix: pkg: lib.optionals (pkg.updateWithSuper or true) (mkUpdateList prefix pkg); mkUpdateListIfAuto = prefix: pkg: lib.optionals (pkg.updateWithSuper or true) (mkUpdateList prefix pkg);
mkUpdateInfo = prefix: pkg: { mkUpdateInfo = prefix: pkg: let
"${prefix}" = rec { # the actual shell command which can update the package, after an environment has been configured for the updater:
updateArgv = lib.optionals (pkg ? updateScript) (
if builtins.isList pkg.updateScript then pkg.updateScript
else if pkg.updateScript ? command then builtins.map builtins.toString pkg.updateScript.command
else []
);
in {
"${prefix}" = {
subPackages = mkUpdateList prefix pkg; subPackages = mkUpdateList prefix pkg;
updateArgv = lib.optionals (pkg ? updateScript) (
if builtins.isList pkg.updateScript then pkg.updateScript
else if pkg.updateScript ? command then builtins.map builtins.toString pkg.updateScript.command
else []
);
updateScript = let updateScript = let
pname = pkg.pname or (pkg.name or "unknown"); pname = pkg.pname or (pkg.name or "unknown");
script = pkgs.writeShellScriptBin "update-${pname}" '' script = pkgs.writeShellScriptBin "update-${pname}" ''
@@ -110,7 +122,7 @@ let
${lib.escapeShellArgs updateArgv} ${lib.escapeShellArgs updateArgv}
popd popd
''; '';
in lib.optionalString (updateArgv != []) (lib.getExe script); in lib.optionalString (shouldUpdate pkg && updateArgv != []) (lib.getExe script);
}; };
} // builtins.foldl' } // builtins.foldl'
(acc: subPkgName: acc // mkUpdateInfo "${prefix}.${subPkgName}" pkg."${subPkgName}") (acc: subPkgName: acc // mkUpdateInfo "${prefix}.${subPkgName}" pkg."${subPkgName}")
@@ -122,6 +134,8 @@ let
in { in {
inherit hosts; inherit hosts;
inherit updateInfo; inherit updateInfo;
# AttrSet mapping attrpath to a list of attrpaths representing all updatable packages beneath it
updateTargets = builtins.mapAttrs (_: v: v.subPackages) (lib.filterAttrs (_: v: v.subPackages != []) updateInfo); updateTargets = builtins.mapAttrs (_: v: v.subPackages) (lib.filterAttrs (_: v: v.subPackages != []) updateInfo);
# AttrSet mapping attrpath to the path of a shell script which can be used to update the package at that attrpath
updateScripts = builtins.mapAttrs (_: v: v.updateScript) (lib.filterAttrs (_: v: v.updateScript != "") updateInfo); updateScripts = builtins.mapAttrs (_: v: v.updateScript) (lib.filterAttrs (_: v: v.updateScript != "") updateInfo);
} // pkgs } // pkgs

View File

@@ -37,21 +37,19 @@ let
staging-next.sha256 = "sha256-NFLhqDfWf49M4t6/YvK7XMqpLhTU1t1PcRUrGhODTM0="; staging-next.sha256 = "sha256-NFLhqDfWf49M4t6/YvK7XMqpLhTU1t1PcRUrGhODTM0=";
}; };
mkVariant = variant: args: let mkVariant = variant: let
lock' = lock."${variant}"; lock' = lock."${variant}";
in import ./common.nix ({ in import ./common.nix {
inherit doPatch localSystem nix-update-script system; inherit doPatch localSystem nix-update-script system;
inherit (lock') rev; inherit (lock') rev;
src = fetchzip { src = fetchzip {
url = "https://github.com/NixOS/nixpkgs/archive/${lock'.rev}.tar.gz"; url = "https://github.com/NixOS/nixpkgs/archive/${lock'.rev}.tar.gz";
inherit (lock') sha256; inherit (lock') sha256;
}; };
} // args); };
in {
nixpkgs = mkVariant "master" {}; recurseForDerivations = true;
in master = mkVariant "master";
nixpkgs.lib.recurseIntoAttrs (mkVariant "master" { staging = mkVariant "staging";
passthru.master = nixpkgs; staging-next = mkVariant "staging-next";
passthru.staging = mkVariant "staging" {}; }
passthru.staging-next = mkVariant "staging-next" {};
})

View File

@@ -5,7 +5,7 @@
# using the correct invocation is critical if any packages mentioned here are # using the correct invocation is critical if any packages mentioned here are
# additionally patched elsewhere # additionally patched elsewhere
# #
{ pkgs ? import ./additional/nixpkgs { }, final ? null }: { pkgs ? (import ./by-name/nixpkgs-bootstrap { }).master, final ? null }:
let let
lib = pkgs.lib; lib = pkgs.lib;
unpatched = pkgs; unpatched = pkgs;
@@ -24,6 +24,9 @@ let
# build like `nix-build -A linuxPackages.rk818-charger` # build like `nix-build -A linuxPackages.rk818-charger`
# or `nix-build -A hosts.moby.config.boot.kernelPackages.rk818-charger` # or `nix-build -A hosts.moby.config.boot.kernelPackages.rk818-charger`
linuxKernel = unpatched.linuxKernel // { linuxKernel = unpatched.linuxKernel // {
# don't update by default since most of these packages are from a different repo (i.e. nixpkgs).
updateWithSuper = false;
packagesFor = kernel: (unpatched.linuxKernel.packagesFor kernel).extend (kFinal: kPrev: ( packagesFor = kernel: (unpatched.linuxKernel.packagesFor kernel).extend (kFinal: kPrev: (
lib.filesystem.packagesFromDirectoryRecursive { lib.filesystem.packagesFromDirectoryRecursive {
inherit (kFinal) callPackage; inherit (kFinal) callPackage;
@@ -33,8 +36,9 @@ let
}; };
### aliases ### aliases
nixpkgs-staging = nixpkgs.staging; # nixpkgs = nixpkgs-bootstrap.master;
nixpkgs-next = nixpkgs.staging-next; # nixpkgs-staging = nixpkgs-bootstrap.staging;
# nixpkgs-next = nixpkgs-bootstrap.staging-next;
inherit (trivial-builders) inherit (trivial-builders)
copyIntoOwnPackage copyIntoOwnPackage
deepLinkIntoOwnPackage deepLinkIntoOwnPackage