diff --git a/home/default.nix b/home/default.nix index ec0ed68..e27b5af 100644 --- a/home/default.nix +++ b/home/default.nix @@ -1,25 +1,32 @@ { nixpkgs, nurpkgs, home-manager, username ? builtins.getEnv "USER", ... }: let - homeDirectory = if username == "root" then "/root" else "/home/${username}"; - configDir = "${homeDirectory}/.config"; - - pkgs = import nixpkgs { - config.allowUnfree = true; - config.xdg.configHome = configDir; - overlays = [ - nurpkgs.overlay - (import ../overlays) - ]; - }; - - nur = import nurpkgs { - inherit pkgs; - nur = pkgs; - }; + home = system: + if username == "root" then "/root" else + ( if ( nixpkgs.lib.hasSuffix "-darwin" system ) then "/Users/${username}" else "/home/${username}" ); mkhome = system: gui: - home-manager.lib.homeManagerConfiguration rec { + let + homeDirectory = home system; + + configDir = "${homeDirectory}/.config"; + + pkgs = import nixpkgs { + config.allowUnfree = true; + config.xdg.configHome = configDir; + overlays = [ + nurpkgs.overlay + (import ../overlays) + ]; + }; + + nur = import nurpkgs { + inherit pkgs; + nur = pkgs; + }; + + + in home-manager.lib.homeManagerConfiguration rec { inherit pkgs system username homeDirectory; stateVersion = "22.05"; configuration = import ./home.nix username { @@ -32,4 +39,5 @@ in { "aarch64-nogui" = mkhome "aarch64-linux" false; "x86_64-gui" = mkhome "x86_64-linux" true; "x86_64-nogui" = mkhome "x86_64-linux" false; + "x86_64-darwin" = mkhome "x86_64-darwin" true; } diff --git a/overlays/hms.nix b/overlays/hms.nix index a89d443..4f47acc 100644 --- a/overlays/hms.nix +++ b/overlays/hms.nix @@ -3,16 +3,19 @@ pkgs.writeShellScriptBin "hms" '' set -eo pipefail # Build different targets with GUI or not -if [ -z "$DISPLAY" ]; then - target="nogui" -else - target="gui" -fi +arch="$(uname -m)" if [ "$(uname -s)" == "Darwin" ]; then + # On macOS src="$HOME/.config/nix/" - target=gui + target="''${arch}-darwin" else + # On Linux/WSL2 systems + if [ -z "$DISPLAY" ]; then + target="''${arch}-nogui" + else + target="''${arch}-gui" + fi src=/etc/nixos fi @@ -20,7 +23,7 @@ fi echo "Building $(uname -m)-$target" dest=$(mktemp -d) pushd "$dest" > /dev/null -nix build --impure "$src#homeConfigurations.$(uname -m)-$target.activationPackage" +nix build --impure "$src#homeConfigurations.$target.activationPackage" ./result/activate popd > /dev/null rm -r "$dest"