From 1f34c048b3b5e6aad099b0a4931752939bbe30e6 Mon Sep 17 00:00:00 2001 From: Nicolas Berbiche Date: Thu, 27 Aug 2020 12:38:15 -0400 Subject: flake: add nix-darwin module --- flake.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/flake.nix b/flake.nix index 697f66ac8e6..2d53d603a61 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 -- cgit v1.2.3 From bd4c2b06515fb7cdef9dda19bccd47f37aa66324 Mon Sep 17 00:00:00 2001 From: Nicolas Berbiche Date: Thu, 27 Aug 2020 13:57:56 -0400 Subject: 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 4c5d1f735bb..3e1f75abb59 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 ce6105d4b12..12d02174332 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); }; } -- cgit v1.2.3 From d3aee544b686a72b2bb7eeb379f72c6b6b2665b7 Mon Sep 17 00:00:00 2001 From: Nicolas Berbiche Date: Fri, 28 Aug 2020 09:42:05 -0400 Subject: 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 + tests/modules/targets-linux/default.nix | 1 + tests/modules/targets-linux/generic-linux.nix | 19 +++++++++++++++++++ tests/modules/targets/default.nix | 1 - tests/modules/targets/generic-linux.nix | 19 ------------------- 9 files changed, 59 insertions(+), 21 deletions(-) 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 create mode 100644 tests/modules/targets-linux/default.nix create mode 100644 tests/modules/targets-linux/generic-linux.nix delete mode 100644 tests/modules/targets/default.nix delete mode 100644 tests/modules/targets/generic-linux.nix diff --git a/modules/modules.nix b/modules/modules.nix index b4eb4d4027c..08c978b177d 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 00000000000..0d434234bbb --- /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 02afd5a2518..b44e4185fcc 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 00000000000..511ae87fd98 --- /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 00000000000..479f586eef3 --- /dev/null +++ b/tests/modules/targets-darwin/default.nix @@ -0,0 +1 @@ +{ targets-darwin = ./darwin.nix; } diff --git a/tests/modules/targets-linux/default.nix b/tests/modules/targets-linux/default.nix new file mode 100644 index 00000000000..e13617ccb74 --- /dev/null +++ b/tests/modules/targets-linux/default.nix @@ -0,0 +1 @@ +{ targets-generic-linux = ./generic-linux.nix; } diff --git a/tests/modules/targets-linux/generic-linux.nix b/tests/modules/targets-linux/generic-linux.nix new file mode 100644 index 00000000000..d9bb85b651a --- /dev/null +++ b/tests/modules/targets-linux/generic-linux.nix @@ -0,0 +1,19 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + targets.genericLinux.enable = true; + + nmt.script = '' + assertFileExists home-path/etc/profile.d/hm-session-vars.sh + assertFileContains \ + home-path/etc/profile.d/hm-session-vars.sh \ + 'export XDG_DATA_DIRS="''${NIX_STATE_DIR:-/nix/var/nix}/profiles/default/share:/home/hm-user/.nix-profile/share''${XDG_DATA_DIRS:+:}$XDG_DATA_DIRS"' + assertFileContains \ + home-path/etc/profile.d/hm-session-vars.sh \ + '. "${pkgs.nix}/etc/profile.d/nix.sh"' + ''; + }; +} diff --git a/tests/modules/targets/default.nix b/tests/modules/targets/default.nix deleted file mode 100644 index e13617ccb74..00000000000 --- a/tests/modules/targets/default.nix +++ /dev/null @@ -1 +0,0 @@ -{ targets-generic-linux = ./generic-linux.nix; } diff --git a/tests/modules/targets/generic-linux.nix b/tests/modules/targets/generic-linux.nix deleted file mode 100644 index d9bb85b651a..00000000000 --- a/tests/modules/targets/generic-linux.nix +++ /dev/null @@ -1,19 +0,0 @@ -{ config, lib, pkgs, ... }: - -with lib; - -{ - config = { - targets.genericLinux.enable = true; - - nmt.script = '' - assertFileExists home-path/etc/profile.d/hm-session-vars.sh - assertFileContains \ - home-path/etc/profile.d/hm-session-vars.sh \ - 'export XDG_DATA_DIRS="''${NIX_STATE_DIR:-/nix/var/nix}/profiles/default/share:/home/hm-user/.nix-profile/share''${XDG_DATA_DIRS:+:}$XDG_DATA_DIRS"' - assertFileContains \ - home-path/etc/profile.d/hm-session-vars.sh \ - '. "${pkgs.nix}/etc/profile.d/nix.sh"' - ''; - }; -} -- cgit v1.2.3