From 1f34c048b3b5e6aad099b0a4931752939bbe30e6 Mon Sep 17 00:00:00 2001 From: Nicolas Berbiche Date: Thu, 27 Aug 2020 12:38:15 -0400 Subject: [PATCH 1/3] flake: add nix-darwin module --- flake.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/flake.nix b/flake.nix index 697f66ac8..2d53d603a 100644 --- a/flake.nix +++ b/flake.nix @@ -4,6 +4,8 @@ outputs = { self, nixpkgs }: rec { nixosModules.home-manager = import ./nixos; + darwinModules.home-manager = import ./nix-darwin; + lib = { homeManagerConfiguration = { configuration, system, homeDirectory , username From bd4c2b06515fb7cdef9dda19bccd47f37aa66324 Mon Sep 17 00:00:00 2001 From: Nicolas Berbiche Date: Thu, 27 Aug 2020 13:57:56 -0400 Subject: [PATCH 2/3] nix-darwin: add missing options Add useGlobalPkgs, verbose and backupFileExtension support --- doc/installation.xml | 17 +++++++++++++++++ nix-darwin/default.nix | 34 +++++++++++++++++++++++++++++----- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/doc/installation.xml b/doc/installation.xml index 4c5d1f735..3e1f75abb 100644 --- a/doc/installation.xml +++ b/doc/installation.xml @@ -313,5 +313,22 @@ home-manager.useUserPackages = true; value in the future. + + + + By default, Home Manager uses a private pkgs instance + that is configured via the options. + To instead use the global pkgs that is configured via + the system level options, set + + +home-manager.useGlobalPkgs = true; + + + This saves an extra Nixpkgs evaluation, adds consistency, and removes the + dependency on NIX_PATH, which is otherwise used for + importing Nixpkgs. + + diff --git a/nix-darwin/default.nix b/nix-darwin/default.nix index ce6105d4b..12d021743 100644 --- a/nix-darwin/default.nix +++ b/nix-darwin/default.nix @@ -10,11 +10,12 @@ let hmModule = types.submoduleWith { specialArgs = { lib = extendedLib; }; - modules = [( - {name, ...}: { + modules = [ + ({ name, ... }: { imports = import ../modules/modules.nix { inherit pkgs; lib = extendedLib; + useNixpkgsModule = !cfg.useGlobalPkgs; }; config = { @@ -24,8 +25,8 @@ let home.username = config.users.users.${name}.name; home.homeDirectory = config.users.users.${name}.home; }; - } - )]; + }) + ]; }; in @@ -38,6 +39,24 @@ in option. ''; + useGlobalPkgs = mkEnableOption '' + using the system configuration's pkgs + argument in Home Manager. This disables the Home Manager + options + ''; + + backupFileExtension = mkOption { + type = types.nullOr types.str; + default = null; + example = "backup"; + description = '' + On activation move existing files by appending the given + file extension rather than exiting with an error. + ''; + }; + + verbose = mkEnableOption "verbose output on activation"; + users = mkOption { type = types.attrsOf hmModule; default = {}; @@ -77,7 +96,12 @@ in system.activationScripts.postActivation.text = concatStringsSep "\n" (mapAttrsToList (username: usercfg: '' echo Activating home-manager configuration for ${username} - sudo -u ${username} -i ${usercfg.home.activationPackage}/activate + sudo -u ${username} -i ${pkgs.writeShellScript "activation-${username}" '' + ${lib.optionalString (cfg.backupFileExtension != null) + "export HOME_MANAGER_BACKUP_EXT=${lib.escapeShellArg cfg.backupFileExtension}"} + ${lib.optionalString cfg.verbose "export VERBOSE=1"} + exec ${usercfg.home.activationPackage}/activate + ''} '') cfg.users); }; } From d3aee544b686a72b2bb7eeb379f72c6b6b2665b7 Mon Sep 17 00:00:00 2001 From: Nicolas Berbiche Date: Fri, 28 Aug 2020 09:42:05 -0400 Subject: [PATCH 3/3] targets.darwin: add module Currently, this module makes sure that `/Applications` directories for packages in `home.packages` get linked into the user's environment. --- modules/modules.nix | 1 + modules/targets/darwin.nix | 14 +++++++++++++ tests/default.nix | 4 +++- tests/modules/targets-darwin/darwin.nix | 20 +++++++++++++++++++ tests/modules/targets-darwin/default.nix | 1 + .../{targets => targets-linux}/default.nix | 0 .../generic-linux.nix | 0 7 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 modules/targets/darwin.nix create mode 100644 tests/modules/targets-darwin/darwin.nix create mode 100644 tests/modules/targets-darwin/default.nix rename tests/modules/{targets => targets-linux}/default.nix (100%) rename tests/modules/{targets => targets-linux}/generic-linux.nix (100%) diff --git a/modules/modules.nix b/modules/modules.nix index b4eb4d402..08c978b17 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -189,6 +189,7 @@ let (loadModule ./services/xscreensaver.nix { }) (loadModule ./services/xsuspender.nix { condition = hostPlatform.isLinux; }) (loadModule ./systemd.nix { }) + (loadModule ./targets/darwin.nix { condition = hostPlatform.isDarwin; }) (loadModule ./targets/generic-linux.nix { condition = hostPlatform.isLinux; }) (loadModule ./xcursor.nix { }) (loadModule ./xresources.nix { }) diff --git a/modules/targets/darwin.nix b/modules/targets/darwin.nix new file mode 100644 index 000000000..0d434234b --- /dev/null +++ b/modules/targets/darwin.nix @@ -0,0 +1,14 @@ +{ config, lib, pkgs, ... }: + +{ + config = lib.mkIf pkgs.stdenv.hostPlatform.isDarwin { + # Install MacOS applications to the user environment. + home.file."Applications/Home Manager Apps".source = let + apps = pkgs.buildEnv { + name = "home-manager-applications"; + paths = config.home.packages; + pathsToLink = "/Applications"; + }; + in "${apps}/Applications"; + }; +} diff --git a/tests/default.nix b/tests/default.nix index 02afd5a25..b44e4185f 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -69,6 +69,8 @@ import nmt { ./modules/programs/zplug ./modules/programs/zsh ./modules/xresources + ] ++ lib.optionals pkgs.stdenv.hostPlatform.isDarwin [ + ./modules/targets-darwin ] ++ lib.optionals pkgs.stdenv.hostPlatform.isLinux [ ./meta # Suffices to run on one platform. ./modules/misc/debug @@ -93,6 +95,6 @@ import nmt { ./modules/services/window-managers/i3 ./modules/services/window-managers/sway ./modules/systemd - ./modules/targets + ./modules/targets-linux ]); } diff --git a/tests/modules/targets-darwin/darwin.nix b/tests/modules/targets-darwin/darwin.nix new file mode 100644 index 000000000..511ae87fd --- /dev/null +++ b/tests/modules/targets-darwin/darwin.nix @@ -0,0 +1,20 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + darwinTestApp = pkgs.runCommandLocal "target-darwin-example-app" { } '' + mkdir -p $out/Applications + touch $out/Applications/example-app + ''; + +in { + config = { + home.packages = [ darwinTestApp ]; + + nmt.script = '' + assertFileExists 'home-files/Applications/Home Manager Apps/example-app' + ''; + }; +} diff --git a/tests/modules/targets-darwin/default.nix b/tests/modules/targets-darwin/default.nix new file mode 100644 index 000000000..479f586ee --- /dev/null +++ b/tests/modules/targets-darwin/default.nix @@ -0,0 +1 @@ +{ targets-darwin = ./darwin.nix; } diff --git a/tests/modules/targets/default.nix b/tests/modules/targets-linux/default.nix similarity index 100% rename from tests/modules/targets/default.nix rename to tests/modules/targets-linux/default.nix diff --git a/tests/modules/targets/generic-linux.nix b/tests/modules/targets-linux/generic-linux.nix similarity index 100% rename from tests/modules/targets/generic-linux.nix rename to tests/modules/targets-linux/generic-linux.nix