nixos/system-path: add corePackages option

This allows users to override all packages. This is useful to build
minimal systems that really don't required these packages that
previously were "required".
This commit is contained in:
nikstur 2025-08-10 22:47:37 +02:00
parent f087e5c94b
commit 42cf56db09
2 changed files with 70 additions and 36 deletions

View File

@ -8,41 +8,47 @@
}: }:
let let
requiredPackages = corePackageNames = [
map (pkg: lib.setPrio ((pkg.meta.priority or lib.meta.defaultPriority) + 3) pkg) "acl"
[ "attr"
pkgs.acl "bashInteractive" # bash with ncurses support
pkgs.attr "bzip2"
pkgs.bashInteractive # bash with ncurses support "coreutils-full"
pkgs.bzip2 "cpio"
pkgs.coreutils-full "curl"
pkgs.cpio "diffutils"
pkgs.curl "findutils"
pkgs.diffutils "gawk"
pkgs.findutils "getent"
pkgs.gawk "getconf"
pkgs.stdenv.cc.libc "gnugrep"
pkgs.getent "gnupatch"
pkgs.getconf "gnused"
pkgs.gnugrep "gnutar"
pkgs.gnupatch "gzip"
pkgs.gnused "xz"
pkgs.gnutar "less"
pkgs.gzip "libcap"
pkgs.xz "ncurses"
pkgs.less "netcat"
pkgs.libcap "mkpasswd"
pkgs.ncurses "procps"
pkgs.netcat "su"
config.programs.ssh.package "time"
pkgs.mkpasswd "util-linux"
pkgs.procps "which"
pkgs.su "zstd"
pkgs.time
pkgs.util-linux
pkgs.which
pkgs.zstd
]; ];
corePackages =
(map (
n:
let
pkg = pkgs.${n};
in
lib.setPrio ((pkg.meta.priority or lib.meta.defaultPriority) + 3) pkg
) corePackageNames)
++ [ pkgs.stdenv.cc.libc ];
corePackagesText = "[ ${lib.concatMapStringsSep " " (n: "pkgs.${n}") corePackageNames} ]";
defaultPackageNames = [ defaultPackageNames = [
"perl" "perl"
@ -80,6 +86,28 @@ in
''; '';
}; };
corePackages = lib.mkOption {
type = lib.types.listOf lib.types.package;
defaultText = lib.literalMD ''
these packages, with their `meta.priority` numerically increased
(thus lowering their installation priority):
${corePackagesText}
'';
example = [ ];
description = ''
Set of core packages for a normal interactive system.
Only change this if you know what you're doing!
Like with systemPackages, packages are installed to
{file}`/run/current-system/sw`. They are
automatically available to all users, and are
automatically updated every time you rebuild the system
configuration.
'';
};
defaultPackages = lib.mkOption { defaultPackages = lib.mkOption {
type = lib.types.listOf lib.types.package; type = lib.types.listOf lib.types.package;
default = defaultPackages; default = defaultPackages;
@ -151,7 +179,11 @@ in
config = { config = {
environment.systemPackages = requiredPackages ++ config.environment.defaultPackages; # Set this here so that it has the right priority and allows ergonomic
# merging.
environment.corePackages = corePackages;
environment.systemPackages = config.environment.corePackages ++ config.environment.defaultPackages;
environment.pathsToLink = [ environment.pathsToLink = [
"/bin" "/bin"

View File

@ -335,6 +335,8 @@ in
} }
); );
environment.corePackages = [ cfg.package ];
# SSH configuration. Slight duplication of the sshd_config # SSH configuration. Slight duplication of the sshd_config
# generation in the sshd service. # generation in the sshd service.
environment.etc."ssh/ssh_config".text = '' environment.etc."ssh/ssh_config".text = ''