Home-manager flake not updating dotfiles

I have home-manager setup using flakes but cannot get it to write dotfiles consistently. For example, enabling starship via home-manager and using ‘programs.starship.settings = {…}’, it wrote starship.toml once, but did not update it when the configuration changed. Additionally, I tried manually deleting the file, and home-manager has not re-created it. I have been using ‘nixos-rebuild switch’, but is there some special command I need for home-manager? I don’t have the home-manager cli, is it necessary?

Are you using HM standalone or HM as a NixOS module?

1 Like

You’ll need to give some more details about your config here.

Only if you run a “standalone” setup. The home-manager manual is quite confusing at times, since it puts the docs for all three “installation modes” (standalone, NixOS, darwin) in sequence, and then only gives post-installation usage instructions for the standalone mode. It doesn’t explain the differences between the modes well either.

So to help out, we need to know:

  1. How did you install home-manager
  2. What mode did you intend to use (presumably the NixOS module if you want to use nixos-rebuild)
  3. What actually ended up in your configuration
1 Like
  1. I installed home-manager while following a nixos flake guide.
  2. I think it is NixOS module as I want it tied to nixos-rebuild.
  3. I’ll put my flake.nix below, I think it has everything pertaining to how I installed home-manager.
{
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/master"; # I should change this back to unstable eventually

    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = {
    self,
    nixpkgs,
    home-manager,
    nixos-wsl,
    ...
  } @ inputs: let
    inherit (self) outputs;
    systems = [
      "x86_64-linux"
    ];
    forAllSystems = nixpkgs.lib.genAttrs systems;
  in {
    packages = forAllSystems (system: import ./pkgs nixpkgs.legacyPackages.${system});
    formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.alejandra);

    overlays = import ./overlays {inherit inputs;};
    nixosModules = import ./modules/nixos;
    homeManagerModules = import ./modules/home-manager;

    nixosConfigurations = {
      my-hostname = nixpkgs.lib.nixosSystem {
        specialArgs = {inherit inputs outputs;};
        modules = [
          ./nixos/shared.nix
          ./nixos/desktop/configuration.nix
          home-manager.nixosModules.home-manager
          {
            home-manager = {
              users.my-username = import ./home-manager/home.nix;
            };
          }
        ];
      };

Those two don’t seem to align, can you share those files too? I also assume you’re not actually using literally my-username, right?

1 Like

Thanks for helping out! Im using a personal username and hostname. (not actually my-username)

And here are the files.

./modules/home-manager only has default.nix which is empty except for some comments from the tutorial:

# Add your reusable home-manager modules to this directory, on their own file (https://nixos.wiki/wiki/Module).
# These should be stuff you would like to share with others, not your personal configurations.
{
  # List your module files here
  # my-module = import ./my-module.nix;
}

home.nix

{
inputs,
outputs,
# lib,
# config,
pkgs,
...
}:
{
  imports = [
    ./starship/starship.nix
  ];

  nixpkgs = {
    overlays = [
      outputs.overlays.additions
      outputs.overlays.modifications
      outputs.overlays.unstable-packages
    ];

    config = {
      allowUnfree = true;
    };
  };

  home = {
    username = "my-username";
    homeDirectory = "/home/my-username";
  };

  home.packages = with pkgs; [
    (pkgs.nerdfonts.override { fonts = [ "FiraCode" "DroidSansMono" ]; })
    floorp
    chezmoi
    nushell
    atuin
    starship
    kitty
    yazi
    asciiquarium-transparent
    cmatrix
    cbonsai
    sl
    pipes-rs
    figlet
    aalib
    fastfetch
    inetutils
    android-tools
    p7zip
    zip
    unzip
    xz
    mattermost-desktop
    pmbootstrap
    noto-fonts
    noto-fonts-cjk
    noto-fonts-emoji
    liberation_ttf
    source-han-sans-japanese
    source-han-serif-japanese # font stuff is broken but thats for another day
  ];

  i18n.inputMethod = {
    enabled = "fcitx5";
    fcitx5.addons = with pkgs; [
        fcitx5-mozc
        fcitx5-gtk
    ];
  };

  programs.home-manager.enable = true;

  systemd.user.startServices = "sd-switch";

  # https://nixos.wiki/wiki/FAQ/When_do_I_update_stateVersion
  home.stateVersion = "24.05";
}

starship.nix

{
  programs.starship = {
    enable = true;
    enableBashIntegration = true;
    enableNushellIntegration = true;
    settings = {
      format = ''
        $os
      ''; # there are other things set too but its long
    };
  }
}

overlays/default.nix

{inputs, ...}: {
  additions = final: _prev: import ../pkgs final.pkgs;

  modifications = final: prev: {
  };

  unstable-packages = final: _prev: {
    unstable = import inputs.nixpkgs-unstable {
      system = final.system;
      config.allowUnfree = true;
    };
  };
}

That’s fine if they know what they’re doing.
Though I’m 99% sure that OP copied their homework from misterio.

My suggestion would be:

1 Like

I think you’re right, I believe I started off from their nix-starter-configs repo.

Did you get any errors during activation? There should be an HM systemd service that tries to deploy the user config, does that show anything?

1 Like

The configuration looks fine at a glance. My guess is that the issue is how you’re invoking nixos-rebuild switch. What’s the exact command you’re running?

Yeah, there’s a bit of a pattern of blind copies from template/framework etc. thingies resulting in not quite enough understanding to know how to fix your problems. Still, I don’t think that helps when people are at the stage of trying to find out what’s wrong.

1 Like

During the first activation I had an error due to already having the files there from chezmoi (im trying to move away from it since its a separate manual step). However, deleting the files in .config cleared up that error and home-manager generated a set of dotfiles fine.

I use a bash file with the following to switch:

# Get the hostname
hostname=$(hostname)

# Run the nixos-rebuild command with the correct flake path
sudo nixos-rebuild switch --flake ~/.local/share/chezmoi/nixos/#"$hostname"

I was moreso referring to the most recent activation. Is there currently an error, or even a warning, on switching?

2 Likes

There don’t seem to be any errors from what I can tell:

building the system configuration...
updating GRUB 2 menu...
Warning: os-prober will be executed to detect other bootable partitions.
Its output will be used to detect bootable binaries on them and create new boot entries.
lsblk: /dev/mapper/no*[0-9]: not a block device
lsblk: /dev/mapper/raid*[0-9]: not a block device
lsblk: /dev/mapper/disks*[0-9]: not a block device
activating the configuration...
setting up /etc...
reloading user units for my-username...
restarting sysinit-reactivation.target

That doesn’t look like it’s running the home-manager switch service… Odd.

Anything in journalctl -f when you run that?

1 Like

I have systemd[1]: nixos-rebuild-switch-to-configuration.service: Failed to open /run/systemd/transient/nixos-rebuild-switch-to-configuration.service: No such file or directory popping up pretty early when switching, but nothing else seems out of the ordinary. It’s hard to copy and past this much through ssh so I’ll try and get the rest of the journal when I have physical access again.