From b3cf056b949e88d7a2ca2cbc7482b458819d5092 Mon Sep 17 00:00:00 2001 From: Trolli Schmittlauch Date: Sun, 17 Mar 2024 19:54:46 +0100 Subject: [PATCH] flake: add `nix run .#hm -- switch` command convenience shell script for invoking home-manager with the correct homeConfiguration output --- flake.nix | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/flake.nix b/flake.nix index 3a9e708..6a2c5f7 100644 --- a/flake.nix +++ b/flake.nix @@ -135,6 +135,48 @@ checks.formatting = treefmtEval.config.build.check self; # expose nixpkgs with overlay; TODO: figure out role of config #legacyPackages = nixpkgs; + + # inspired by https://github.com/Mic92/dotfiles/blob/main/home-manager/flake-module.nix + # run like: `nix run .#hm -- ` + apps.hm = { + type = "app"; + program = "${pkgs.writeShellScriptBin "hm" '' + set -x + export PATH=${ + pkgs.lib.makeBinPath [ + pkgs.git + pkgs.coreutils + pkgs.findutils + pkgs.nix + pkgs.jq + pkgs.unixtools.hostname + ] + } + declare -A profiles=( + ["framenix"]="spiollinux-desktop" + ["thinknix"]="spiollinux-desktop" + # TODO: hostname workmac + ["os"]="workmac" + ) + user=$(id -un) + host=$(hostname) + if [[ -n ''${profiles["$host-$user"]} ]]; then + profile=''${profiles["$host-$user"]}; + elif [[ -n ''${profiles[$host]:-} ]]; then + profile=''${profiles[$host]} + else + echo "No suitable profile found." >2 + exit 2 + fi + if [[ "''${1:-}" == profile ]]; then + echo $profile + exit 0 + fi + ${ + inputs.home-manager.packages.${pkgs.system}.home-manager + }/bin/home-manager --flake "${self}#$profile" "$@" + ''}/bin/hm"; + }; } ); }