2021-07-30 21:09:20 +00:00
|
|
|
{ pkgs, lib, config, ... }:
|
2020-05-09 14:04:35 +00:00
|
|
|
let
|
2021-07-05 15:45:47 +00:00
|
|
|
inherit (config.m-0) hostName;
|
|
|
|
modes = pkgs.lib.attrNames (import ../machines.nix).${hostName};
|
2021-07-30 16:25:35 +00:00
|
|
|
modeFile = "${config.home.homeDirectory}/.mode";
|
2021-07-30 21:09:20 +00:00
|
|
|
modeDir = "${config.home.homeDirectory}/.volatile/modes";
|
2021-07-09 11:39:48 +00:00
|
|
|
configPath = "${config.home.homeDirectory}/git/config";
|
2021-07-08 22:52:35 +00:00
|
|
|
configGit = "${pkgs.git}/bin/git -C ${configPath}";
|
2021-05-18 14:33:28 +00:00
|
|
|
in
|
|
|
|
{
|
2020-05-16 13:59:02 +00:00
|
|
|
home.packages = builtins.attrValues rec {
|
2020-05-05 23:40:57 +00:00
|
|
|
maintenance = pkgs.writeShellScriptBin "maintenance" ''
|
2021-07-08 23:08:48 +00:00
|
|
|
set -e
|
2021-07-09 11:39:48 +00:00
|
|
|
${configGit} pull --ff-only
|
2021-07-08 22:52:35 +00:00
|
|
|
${configGit} submodule update
|
|
|
|
${updateModes}/bin/update-modes
|
2021-07-08 23:55:57 +00:00
|
|
|
/run/wrappers/bin/sudo -A /run/current-system/sw/bin/update-system
|
2020-05-05 23:40:57 +00:00
|
|
|
'';
|
2020-05-27 13:20:08 +00:00
|
|
|
activateMode = pkgs.writeHaskellScript { name = "activate-mode"; } ''
|
2020-05-16 13:59:02 +00:00
|
|
|
getMode :: IO Text
|
2021-07-05 15:45:47 +00:00
|
|
|
getMode = decodeUtf8 <$> (cat "${modeFile}" |> captureTrim)
|
2020-05-16 13:59:02 +00:00
|
|
|
|
2021-10-26 21:06:34 +00:00
|
|
|
wallpaperCmd = "random-wallpaper"
|
|
|
|
|
2020-05-16 13:59:02 +00:00
|
|
|
main = do
|
|
|
|
mode <- getMode
|
|
|
|
say [i|Switching to mode #{mode}...|]
|
2021-07-05 15:45:47 +00:00
|
|
|
exe ([i|${modeDir}/#{mode}/activate|] :: String)
|
2021-10-26 21:06:34 +00:00
|
|
|
whenM (elem wallpaperCmd <$> pathBins) $ exe wallpaperCmd
|
2020-05-09 14:04:35 +00:00
|
|
|
'';
|
2021-05-18 14:33:28 +00:00
|
|
|
updateModes = pkgs.writeHaskellScript
|
|
|
|
{
|
|
|
|
name = "update-modes";
|
|
|
|
bins = [ activateMode pkgs.git pkgs.nix-output-monitor ];
|
|
|
|
} ''
|
2021-07-05 15:45:47 +00:00
|
|
|
params = ["${configPath}/home-manager/target.nix", "-A", "${hostName}", "-o", "${modeDir}"]
|
2020-10-01 00:32:51 +00:00
|
|
|
|
2020-05-16 13:59:02 +00:00
|
|
|
main = do
|
2021-07-05 15:45:47 +00:00
|
|
|
say "Building ~/.modes for ${hostName}"
|
2020-05-16 14:47:52 +00:00
|
|
|
nixPath <- myNixPath "${configPath}"
|
2020-12-16 18:26:20 +00:00
|
|
|
setEnv "WITH_SECRETS" "false"
|
2021-07-20 16:52:24 +00:00
|
|
|
nom_build nixPath (params ++ remoteBuildParams)
|
2020-12-16 18:26:20 +00:00
|
|
|
setEnv "WITH_SECRETS" "true"
|
2021-07-20 16:52:24 +00:00
|
|
|
nom_build nixPath params
|
2020-05-16 13:59:02 +00:00
|
|
|
activate_mode
|
2020-05-05 23:40:57 +00:00
|
|
|
'';
|
2021-05-18 14:33:28 +00:00
|
|
|
quickUpdateMode = pkgs.writeHaskellScript
|
|
|
|
{
|
|
|
|
name = "quick-update-mode";
|
|
|
|
bins = [ updateModes pkgs.git pkgs.home-manager pkgs.nix-output-monitor ];
|
|
|
|
} ''
|
2020-10-11 13:03:01 +00:00
|
|
|
getMode :: IO Text
|
2021-07-05 15:45:47 +00:00
|
|
|
getMode = decodeUtf8 <$> (cat "${modeFile}" |> captureTrim)
|
2020-10-11 13:03:01 +00:00
|
|
|
|
|
|
|
main = do
|
|
|
|
nixPath <- myNixPath "${configPath}"
|
|
|
|
mode <- getMode
|
|
|
|
say [i|Quick switching to mode #{mode} ...|]
|
2021-07-05 15:45:47 +00:00
|
|
|
home_manager (nixPath <> ["switch", "-A", [i|${hostName}-#{mode}|]]) &!> StdOut |> nom
|
2020-10-11 13:03:01 +00:00
|
|
|
update_modes
|
|
|
|
'';
|
2021-05-18 14:33:28 +00:00
|
|
|
selectMode = pkgs.writeHaskellScript
|
|
|
|
{
|
|
|
|
name = "select-mode";
|
|
|
|
bins = [
|
|
|
|
pkgs.dialog
|
|
|
|
activateMode
|
|
|
|
pkgs.ncurses
|
2021-07-31 11:22:52 +00:00
|
|
|
pkgs.psmisc
|
2021-05-18 14:33:28 +00:00
|
|
|
];
|
|
|
|
} ''
|
2020-09-21 08:39:24 +00:00
|
|
|
main = do
|
|
|
|
mode <- decodeUtf8 <$> (dialog "--menu" "Select Mode" "20" "80" "5" ${
|
2020-10-09 21:05:13 +00:00
|
|
|
lib.concatStrings (map (mode: ''"${mode}" "" '') modes)
|
|
|
|
} |!> captureTrim)
|
2020-09-21 08:39:24 +00:00
|
|
|
clear
|
2021-07-05 15:45:47 +00:00
|
|
|
writeFile "${modeFile}" mode
|
2020-09-21 08:39:24 +00:00
|
|
|
activate_mode
|
2021-11-18 21:43:49 +00:00
|
|
|
ignoreFailure $ killall "GeckoMain"
|
2020-05-06 09:01:08 +00:00
|
|
|
'';
|
2020-05-05 23:40:57 +00:00
|
|
|
};
|
|
|
|
}
|