flake: add nix run .#hm -- switch
command
convenience shell script for invoking home-manager with the correct homeConfiguration output
This commit is contained in:
parent
f14b290937
commit
b3cf056b94
42
flake.nix
42
flake.nix
|
@ -135,6 +135,48 @@
|
||||||
checks.formatting = treefmtEval.config.build.check self;
|
checks.formatting = treefmtEval.config.build.check self;
|
||||||
# expose nixpkgs with overlay; TODO: figure out role of config
|
# expose nixpkgs with overlay; TODO: figure out role of config
|
||||||
#legacyPackages = nixpkgs;
|
#legacyPackages = nixpkgs;
|
||||||
|
|
||||||
|
# inspired by https://github.com/Mic92/dotfiles/blob/main/home-manager/flake-module.nix
|
||||||
|
# run like: `nix run .#hm -- <action>`
|
||||||
|
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";
|
||||||
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue