132 lines
3.7 KiB
Nix
132 lines
3.7 KiB
Nix
{ config, inputs, ... }:
|
|
{
|
|
flake.modules.nixos.walker = {
|
|
home-manager.sharedModules = [ config.flake.modules.homeManager.walker ];
|
|
|
|
nix.settings = {
|
|
extra-substituters = [
|
|
"https://walker.cachix.org"
|
|
"https://walker-git.cachix.org"
|
|
];
|
|
extra-trusted-public-keys = [
|
|
"walker.cachix.org-1:fG8q+uAaMqhsMxWjwvk0IMb4mFPFLqHjuvfwQxE4oJM="
|
|
"walker-git.cachix.org-1:vmC0ocfPWh0S/vRAQGtChuiZBTAe4wiKDeyyXM0/7pM="
|
|
];
|
|
};
|
|
};
|
|
|
|
flake.modules.homeManager.walker =
|
|
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
...
|
|
}:
|
|
let
|
|
homeDir = config.home.homeDirectory;
|
|
projectRoots =
|
|
map
|
|
(scope: {
|
|
inherit scope;
|
|
path = "${homeDir}/dev/${scope}";
|
|
})
|
|
[
|
|
"work"
|
|
"own"
|
|
"ext"
|
|
"forks"
|
|
];
|
|
walkerDefaults = builtins.fromTOML (builtins.readFile "${inputs.walker}/resources/config.toml");
|
|
|
|
launcher = pkgs.writeShellApplication {
|
|
name = "walker-launcher";
|
|
runtimeInputs = [ pkgs.libressl.nc ];
|
|
text = ''
|
|
exec nc -U "$XDG_RUNTIME_DIR/walker/walker.sock"
|
|
'';
|
|
};
|
|
openProject = pkgs.writeShellApplication {
|
|
name = "open-project";
|
|
text = ''
|
|
project_path="''${1:-}"
|
|
if [[ -z "$project_path" ]]; then
|
|
IFS= read -r project_path || [[ -n "$project_path" ]]
|
|
fi
|
|
|
|
exec ${lib.getExe config.xdg.terminal-exec.package} --dir="$project_path" \
|
|
${lib.getExe pkgs.zsh} -lic 'nvim .; exec zsh -l'
|
|
'';
|
|
};
|
|
in
|
|
{
|
|
imports = [ inputs.walker.homeManagerModules.default ];
|
|
|
|
desktop.commands.launcher = [ (lib.getExe launcher) ];
|
|
home.packages = [ openProject ];
|
|
|
|
xdg.configFile."elephant/menus/projects.lua".text = ''
|
|
Name = "projects"
|
|
NamePretty = "Projects"
|
|
Description = "Git repositories"
|
|
Icon = "folder"
|
|
Action = "${lib.getExe openProject}"
|
|
SearchName = true
|
|
RefreshOnChange = {
|
|
${lib.concatMapStringsSep "\n " (root: ''"${root.path}",'') projectRoots}
|
|
}
|
|
|
|
local roots = {
|
|
${lib.concatMapStringsSep "\n " (
|
|
root: ''{ scope = "${root.scope}", path = "${root.path}" },''
|
|
) projectRoots}
|
|
}
|
|
|
|
local function repositories(root)
|
|
return io.popen(
|
|
"${lib.getExe pkgs.findutils} " .. root ..
|
|
" -mindepth 1 \\( -type d \\( -name .archive -o -name .worktrees \\) -prune \\)" ..
|
|
" -o \\( -name .git -print \\) 2>/dev/null"
|
|
)
|
|
end
|
|
|
|
function GetEntries()
|
|
local entries = {}
|
|
|
|
for _, root in ipairs(roots) do
|
|
local handle = repositories(root.path)
|
|
if handle then
|
|
for git_path in handle:lines() do
|
|
local project = git_path:gsub("/%.git$", "")
|
|
local relative = project:sub(#root.path + 2)
|
|
table.insert(entries, {
|
|
Text = project:match("([^/]+)$"),
|
|
Subtext = root.scope .. " · " .. relative,
|
|
Value = project,
|
|
Keywords = { root.scope, relative, project },
|
|
})
|
|
end
|
|
handle:close()
|
|
end
|
|
end
|
|
|
|
return entries
|
|
end
|
|
'';
|
|
|
|
programs.walker = {
|
|
enable = true;
|
|
runAsService = true;
|
|
|
|
config.providers = {
|
|
default = walkerDefaults.providers.default ++ [ "menus:projects" ];
|
|
prefixes = walkerDefaults.providers.prefixes ++ [
|
|
{
|
|
provider = "bitwarden";
|
|
prefix = "?";
|
|
}
|
|
];
|
|
};
|
|
};
|
|
};
|
|
}
|