worktrunk icon indicating copy to clipboard operation
worktrunk copied to clipboard

Can not run "wt config shell install" in home-manager

Open meicale opened this issue 9 months ago • 8 comments

Great Job! The nix/home-manager generates the bashrc or other config file for the shell, which is read-only. So, it is not possible to change it after home-manager switch. Maybe, it needs to be installed by home-manager. Would you like to provide the related stuff in the readme or doc? Thx!

meicale avatar Mar 04 '26 11:03 meicale

Thanks for reaching out! This looks like a usage question rather than a bug report.

On NixOS with home-manager, shell config files (.bashrc, .zshrc, etc.) are read-only since they're generated by Nix — so wt config shell install can't append to them. Instead, you can add the integration line directly in your home-manager configuration.

Run wt config shell init --help to see the exact line for each shell. For example:

  • Bash — add to your home-manager programs.bash.initExtra:
    eval "$(wt config shell init bash)"
    
  • Zsh — add to programs.zsh.initExtra:
    eval "$(wt config shell init zsh)"
    
  • Fish — add to programs.fish.interactiveShellInit:
    wt config shell init fish | source
    

This is equivalent to what wt config shell install would write automatically.

A maintainer can provide more detail if needed.

worktrunk-bot avatar Mar 04 '26 11:03 worktrunk-bot

I just use nix run github:max-sixty/worktrunk/v0.28.2 to test, which means I have not installed this on my home-manager so the comman wt doesn't work. Maybe, you need provide more info about how to integrate this to home-manager. Thx!

meicale avatar Mar 04 '26 11:03 meicale

Thanks for the clarification! Since you're using nix run rather than a persistent install, the shell integration isn't active — that's expected.

To set up worktrunk with home-manager, you'd add it as a flake input and wire up both the package and shell integration. Something like:

# flake.nix
{
  inputs.worktrunk.url = "github:max-sixty/worktrunk";
  # ...
}
# home.nix (or wherever your home-manager config lives)
{ inputs, pkgs, ... }:
{
  home.packages = [ inputs.worktrunk.packages.${pkgs.system}.default ];

  programs.bash.initExtra = ''
    eval "$(wt config shell init bash)"
  '';

  # or for zsh:
  # programs.zsh.initExtra = ''
  #   eval "$(wt config shell init zsh)"
  # '';
}

That said, providing an official home-manager module or more detailed Nix documentation is a decision for the maintainer — tagging @max-sixty for visibility.

worktrunk-bot avatar Mar 04 '26 11:03 worktrunk-bot

it is ok to install this using home-manager, but, it seems your config doesn't work on my configs. I have flake version home-manager. Here are the related parts:

# flake.nix
......
  inputs.worktrunk = {
        url = "github:max-sixty/worktrunk";
        inputs.nixpkgs.follows = "nixpkgs";
  };
......
 outputs = { self, nixpkgs, home-manager, worktrunk, }: {
    homeConfigurations = {
      "YOUR_NAME" = home-manager.lib.homeManagerConfiguration ({
        modules = [ 
          ({ pkgs, ... }: {
            nixpkgs.overlays = [
              (final: prev: {
                worktrunk = worktrunk.packages."x86_64-linux".default;
              })
            ];
          })
          (import ./home.nix)
        ]
........
# home.nix (or wherever your home-manager config lives)
{ inputs, pkgs, ... }:
{
  home.packages = with pkgs; ([  
                               worktrunk ......]);
  programs.bash.initExtra = ''
    eval "$(wt config shell init bash)"
  '';

  # or for zsh:
  # programs.zsh.initExtra = ''
  #   eval "$(wt config shell init zsh)"
  # '';
}

As AI-bot, you've done great job. Thank you!

meicale avatar Mar 04 '26 13:03 meicale

Glad you got it working! Your overlay approach is the right pattern when using a standalone (non-NixOS-module) flake with home-manager — it makes the package available through pkgs without needing to pass inputs into every module. Thanks for sharing the working config; it'll be helpful for others who find this issue.

worktrunk-bot avatar Mar 04 '26 13:03 worktrunk-bot

ha, happy this worked out, thanks for your patience @meicale

I admittedly don't know that much about Home Manager.

would anyone have ideas for how we could make this easier for folks?

@worktrunk-bot maybe you could link to some of the old issues, write down a few options from here, and tag the folks who have been involved in the past, and then we could all come to a decision?

max-sixty avatar Mar 04 '26 17:03 max-sixty

Here's a summary of the Nix/home-manager history and some options going forward.

Related issues & PRs

  • #338 — @Kabilan108 proposed adding an official Nix flake + home-manager module. Discussion with @soyboi and @cdepillabout about in-repo flake vs nixpkgs upstream. Led to #502.
  • #502 — @marktoda added the in-repo flake.nix (merged). @craigdallimore and @Lewenhaupt raised the shell integration question — wt config shell install fails with "Permission denied" on NixOS since shell configs are read-only. @Lewenhaupt pointed to kitty's home-manager module as a reference.
  • #525 — @MattiasMTS fixed nix-darwin build (apple_sdk removal).

The recurring pain point across all of these is shell integration on NixOS — wt config shell install can't write to read-only shell configs.

Options

1. Add a home-manager module to the flake — The flake would export a module that auto-injects the shell init line (like kitty, starship, etc. do). Users would add programs.worktrunk.enable = true and it handles the rest. This is the most polished experience but needs someone who knows Nix to write and maintain it.

2. Document the manual workaround — Add a "NixOS / Home Manager" section to the docs explaining how to add the eval "$(wt config shell init <shell>)" line via programs.bash.initExtra / programs.zsh.initExtra / etc. Low effort, immediately helpful, and doesn't require Nix expertise to maintain.

3. Submit to nixpkgs — As @cdepillabout suggested, getting worktrunk into nixpkgs would make it available as pkgs.worktrunk without adding a flake input. This is complementary to options 1 and 2 (not mutually exclusive). The in-repo flake would still be useful for users who want to track latest.

4. Detect read-only shell configs in wt config shell install — Instead of failing with a generic "Permission denied", detect the read-only case and print a helpful message with the manual init line. This helps NixOS users (and anyone with immutable configs like GNU Stow) without requiring Nix-specific infrastructure.

Options 2 and 4 are the lowest-effort improvements that would help right away. Option 1 is the gold standard for NixOS UX but needs a Nix-knowledgeable contributor. Option 3 is independent and could happen in parallel.

cc @Kabilan108 @marktoda @MattiasMTS @craigdallimore @Lewenhaupt @cdepillabout @meicale — thoughts on what would be most useful?

worktrunk-bot avatar Mar 04 '26 17:03 worktrunk-bot

I think this is a matter of taste tbh. Flakes are starting to feel more idiomatic, and I'd expect faster updates if the nix part lives closer to the source, rather than porting it to nixpkgs. Albeit, having it in nixpkgs will be better long term for portability.

How I do it today is mainly:

  1. add worktrunk via nix flake to build it
  2. allow opt-out of nix store symlink and have a standard config.toml file that I can add and iterate on myself (haven't found the iteration-loop of changing nix -> switch to be nice rather than just modifying config file)

Small home-manager setup would look something like this (assuming you've it installed via flake already)

# home/default.nix
{
  config,
  pkgs,
  inputs,
  ...
}:
let
  inherit (config.lib.file) mkOutOfStoreSymlink;
  dotfilesPath = "<path-added>";
in
{
  xdg.enable = true;

  # packages managed outside of home-manager
  xdg.configFile.worktrunk.source = mkOutOfStoreSymlink "${dotfilesPath}/.config/worktrunk";

 # install home pkgs
  home.packages = with pkgs; [
    inputs.worktrunk.packages.${pkgs.system}.worktrunk
  ];
}

the main benefit is that you can now use wt config commands, because it is still just interacting with the toml file.

MattiasMTS avatar Mar 05 '26 22:03 MattiasMTS