From b6b1bed228d10955fcf3946a6b34416422bb78b1 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Thu, 5 Oct 2023 22:48:43 +0100 Subject: [PATCH] flake.nix: add home-manager as devShell --- flake.nix | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index fe4fa51f..1053f9ac 100644 --- a/flake.nix +++ b/flake.nix @@ -112,7 +112,7 @@ }; }; - outputs = { self, nixpkgs, ... }@inputs: + outputs = { self, nixpkgs, flake-utils, ... }@inputs: let inherit (import ./lib/attrsets.nix { inherit (nixpkgs) lib; }) recursiveMergeAttrs; inherit (import ./lib/flake.nix inputs) mkGHActionsYAMLs mkRunCmd mkNixOSConfig mkHomeConfig; @@ -190,5 +190,51 @@ "update-flakes-darwin" "validate-flakes" ]) + + (flake-utils.lib.eachDefaultSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + homeManager = (mkHomeConfig { + inherit system; + hostname = "devShell"; + homePath = "/tmp"; + username = "home"; + extraModules = [{ + # Disable systemd services/sockets/timers/etc. + systemd.user = { + automounts = pkgs.lib.mkForce { }; + mounts = pkgs.lib.mkForce { }; + paths = pkgs.lib.mkForce { }; + services = pkgs.lib.mkForce { }; + sessionVariables = pkgs.lib.mkForce { }; + slices = pkgs.lib.mkForce { }; + sockets = pkgs.lib.mkForce { }; + targets = pkgs.lib.mkForce { }; + timers = pkgs.lib.mkForce { }; + }; + }]; + }).homeConfigurations.devShell; + in + { + devShells.default = pkgs.mkShell { + shellHook = '' + # Home Manager checks if the USER environment variable matches + # username + OLD_USER="$USER" + export USER="${homeManager.config.home.username}" + export HOME="${homeManager.config.home.homeDirectory}" + mkdir -p $HOME + + trap "rm -rf $HOME" EXIT + + ${homeManager.activationPackage}/activate + + export USER="$OLD_USER" + unset OLD_USER + + zsh -l && exit 0 + ''; + }; + })) ]); # END recursiveMergeAttrs }