From 9951b44d5bdebd062dab70701d7b21350cbbc6ab Mon Sep 17 00:00:00 2001 From: isabel Date: Sun, 2 Feb 2025 13:50:37 +0000 Subject: [PATCH] nix-darwin: system tools can be configured indvidually --- modules/nix/nix-darwin.nix | 47 ++++++++++++++++------------- pkgs/darwin-uninstaller/default.nix | 2 +- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/modules/nix/nix-darwin.nix b/modules/nix/nix-darwin.nix index 9c78f3a6..677acbe5 100644 --- a/modules/nix/nix-darwin.nix +++ b/modules/nix/nix-darwin.nix @@ -9,39 +9,44 @@ let darwin-uninstaller = pkgs.callPackage ../../pkgs/darwin-uninstaller { }; - inherit (nix-tools) darwin-option darwin-rebuild darwin-version; + mkToolModule = { name, package ? nix-tools.${name} }: { config, ... }: { + options.system.tools.${name}.enable = lib.mkEnableOption "${name} script" // { + default = config.system.tools.enable; + }; + + config = lib.mkIf config.system.tools.${name}.enable { + environment.systemPackages = [ package ]; + }; + }; in { options.system = { - disableInstallerTools = lib.mkOption { - type = lib.types.bool; - internal = true; - default = false; - description = '' - Disable darwin-rebuild and darwin-option. This is useful to shrink - systems which are not expected to rebuild or reconfigure themselves. - Use at your own risk! - ''; - }; - - includeUninstaller = lib.mkOption { + tools.enable = lib.mkOption { type = lib.types.bool; internal = true; default = true; + description = '' + Disable internal tools, such as darwin-rebuild and darwin-option. This + is useful to shrink systems which are not expected to rebuild or + reconfigure themselves. Use at your own risk! + ''; }; }; - config = { - environment.systemPackages = - [ darwin-version ] - ++ lib.optionals (!config.system.disableInstallerTools) [ - darwin-option - darwin-rebuild - ] ++ lib.optional config.system.includeUninstaller darwin-uninstaller; + imports = [ + (lib.mkRenamedOptionModule [ "system" "includeUninstaller" ] [ "system" "tools" "darwin-uninstaller" "enable" ]) + (lib.mkRemovedOptionModule [ "system" "disableInstallerTools" ] "Please use system.tools.enable instead") + (mkToolModule { name = "darwin-option"; }) + (mkToolModule { name = "darwin-rebuild"; }) + (mkToolModule { name = "darwin-version"; }) + (mkToolModule { name = "darwin-uninstaller"; package = darwin-uninstaller; }) + ]; + + config = { system.build = { - inherit darwin-option darwin-rebuild darwin-version; + inherit (nix-tools) darwin-option darwin-rebuild darwin-version; }; }; } diff --git a/pkgs/darwin-uninstaller/default.nix b/pkgs/darwin-uninstaller/default.nix index 6b43bcfc..658991b1 100644 --- a/pkgs/darwin-uninstaller/default.nix +++ b/pkgs/darwin-uninstaller/default.nix @@ -8,7 +8,7 @@ let { nixpkgs.source = path; nixpkgs.hostPlatform = stdenv.hostPlatform.system; - system.includeUninstaller = false; + system.tools.darwin-uninstaller.enable = false; } ]; };