home-manager icon indicating copy to clipboard operation
home-manager copied to clipboard

question: Home-manager and Flake usage

Open paddygoat opened this issue 4 years ago • 14 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Issue description

I'm not sure if this is the right place to ask this question as it's also a flake issue, but seems like running home-manager switch -f ./home.nix does not put my home.nix file into the store with my other DIY config scripts. After running nixos-rebuild build --flake .# in my DIY config directory, all my files are in /nix/store/ EXCEPT home.nix and I get this error:

[paddygoat@nixos:~/Paddy_Nix_Backup]$ home-manager switch -f ./home.nix /nix/store/wvxc8aaaxmvpprcp8c3sk12320rsx407-home-manager-generation Starting home manager activation Activating checkFilesChanged Activating checkLinkTargets Activating writeBoundary Activating installPackages replacing old 'home-manager-path' installing 'home-manager-path' Activating linkGeneration Cleaning up orphan links from /home/paddygoat No change so reusing latest profile generation 2 Creating home file links in /home/paddygoat Activating onFilesChange Activating reloadSystemd

There are 154 unread and relevant news items. Read them by running the command 'home-manager news'.

[paddygoat@nixos:~/Paddy_Nix_Backup]$ nixos-rebuild build --flake .# warning: Git tree '/home/paddygoat/Paddy_Nix_Backup' is dirty building the system configuration... warning: Git tree '/home/paddygoat/Paddy_Nix_Backup' is dirty error: getting status of '/nix/store/rsfrp307b6a26jsw6s3badmjgjvl2n5z-source/home.nix': No such file or directory (use '--show-trace' to show detailed location information)

[paddygoat@nixos:~/Paddy_Nix_Backup]$

Please advise ..... Thank you very much !!

Maintainer CC

No response

System information

[paddygoat@nixos:~/Paddy_Nix_Backup]$  nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 5.10.76, NixOS, 21.05.3896.b0274abf850 (Okapi)`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.4pre20211006_53e4794`
 - channels(paddy): `"home-manager-21.05"`
 - channels(paddygoat): `"home-manager-21.05"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

paddygoat avatar Nov 01 '21 10:11 paddygoat

home.nix:

{ config, pkgs, ... }:

{
  # Let Home Manager install and manage itself:
  programs.home-manager.enable = true;
  
  # Home Manager needs a bit of information about you and the paths it should manage:
  home.username = "paddygoat";
  home.homeDirectory = "/home/paddygoat";
  
  # This value determines the Home Manager release that your configuration is compatible with.
  # This helps avoid breakage when a new Home Manager release introduces backwards incompatible changes.
  #
  # You can update Home Manager without changing this value.
  # See the Home Manager release notes for a list of state version changes in each release.
  home.stateVersion = "21.05";
  
  # home.packages = [ pkgs.plasma5Packages.kdenlive ];
  
  # home.packages = with pkgs; [
  #  git
  #  git-crypt
  #  gnupg
  # ];
  
  home.packages = with pkgs; [
    plasma5Packages.kdenlive
    git
    git-crypt
    gnupg
    audacity
    gimp
    nano
    qtractor
    jack2
    lmms
  ];
    
}

paddygoat avatar Nov 01 '21 10:11 paddygoat

When you're using flakes, nothing really matters except the nixos-rebuild switch command, and home-manager switch doesn't exist. The home-manager switch command is intended more for using home-manager outside of NixOS.

Everything ends up as a big .nix expression in the end, as these files are either imported or are not imported. The way you choose to separate them is yours.

So is home.nix being imported by the Nix expression that you're executing when you run nixos-rebuild build --flake .# ?

Do you have something that looks like this?:

{ config, lib, ... }:
{
  imports = [ ./hardware-configuration.nix ./home.nix ];
}

If you are not importing home.nix in any nix expression, it will not be evaluated for any reason.

MatthewCroughan avatar Nov 01 '21 22:11 MatthewCroughan

The reason you have the home-manager command at all is your NixOS channel, if you intend to use Flakes you are not supposed to have any channels. You should remove the home-manager channel: nix-channel --remove home-manager

MatthewCroughan avatar Nov 01 '21 22:11 MatthewCroughan

Thanks @MatthewCroughan. I eventually sussed out that capitalisation in my username was causing an issue - bit of a newbie mistake. Then re-vamped another Flake.nix script which worked with a little bit of fine tuning:

{
  description = "My system config based on flake";

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

  outputs = { nixpkgs, home-manager, ... }:
  let
    system = "x86_64-linux";

    pkgs = import nixpkgs {
      inherit system;
      config = { allowUnfree = true; };
    };
    
    lib = nixpkgs.lib;

  in {
    homeManagerConfigurations = {
      paddygoat = home-manager.lib.homeManagerConfiguration {
        inherit system pkgs;
        username = "paddygoat";
        homeDirectory = "/home/paddygoat";
        configuration = {
          imports = [
          ./home.nix
          ];
        };      
      };
    };
  
  
    nixosConfigurations = {
      nixos = lib.nixosSystem {
        inherit system;
        
        modules = [
          ./system/configuration.nix
        ];
      };
    };
  };
} 

paddygoat avatar Nov 02 '21 11:11 paddygoat

I'm slightly confused by the "Everything ends up as a big .nix expression in the end" argument. Doesn't this preclude individual users from managing their homes independently of the system administrator? That is, I want to manage my home with home-manager without the sysadmin having to include my file, or having to rebuild the OS any time I change my config.

dominikh avatar Nov 16 '21 16:11 dominikh

I'm slightly confused by the "Everything ends up as a big .nix expression in the end" argument. Doesn't this preclude individual users from managing their homes independently of the system administrator? That is, I want to manage my home with home-manager without the sysadmin having to include my file, or having to rebuild the OS any time I change my config.

I just mean to say that if home.nix doesn't contain imports = [ ./something.nix ];, then something.nix will not end up being used for any reason. The code will not be automatically used or included for any reason relating to the home-manager command, or any nix command. The expression (the .nix file) is in control of the code the gets used, nothing else.

MatthewCroughan avatar Nov 16 '21 17:11 MatthewCroughan

So if you want to use flakes, you can't use home-manager to maintain your personal profile?

I'd like to use flakes and use my home-manager configuration on non-nixos systems too.

wmertens avatar Jan 14 '22 07:01 wmertens

I actually miserably failed when trying to use nixos-rebuild with home-manager (it does not find the needed output, which seems kind of logical since it looks under nixosConfigurations. and that's probably not where the homeConfigurations. hierarchy is, right? Right?), but home-manager switch --flake ... is working great for me. Wonder what I'm missing here!

EDIT, ah, I think I get it: my home config is separate from system config (for (theoretical at the moment) portability to non-NixOS), so it does make sense that nixos-rebuild does not pick it up. But the home-manager command exists because my NixOS config takes care to furnish my (otherwise bare) user with the home-manager package, no channels needed.

So I guess the question is rather why does the README sound like the home-manager command is not advisable for flakes, when it seems to work totally OK?

cmm avatar Jan 19 '22 16:01 cmm

Aha good to know, I'll just give it a try then.

wmertens avatar Jan 19 '22 20:01 wmertens

So I guess the question is rather why does the README sound like the home-manager command is not advisable for flakes, when it seems to work totally OK?

Indeed, this is a mistake in the README. home-manager switch --flake should be used for a standalone installation, while nixos-rebuild switch --flake should be used when Home Manager is integrated with the NixOS configuration with the NixOS module.

failed when trying to use nixos-rebuild with home-manager (it does not find the needed output, which seems kind of logical since it looks under nixosConfigurations. and that's probably not where the homeConfigurations.

The command home-manager switch --flake uses the homeConfigurations output whereas Nix uses nixosConfigurations.

berbiche avatar Jan 20 '22 05:01 berbiche

Slightly hijacking the thread: I have ~/.config/nixpkgs/config.nix to set some nixpkgs things, which worked fine before, but with the flake.nix that is proposed in the Readme it doesn't read that. How can I provide a nixpkgs with this config to home-manager?

EDIT: found the answer here https://nixos.wiki/wiki/Flakes#Enable_unfree_software_in_home-manager

wmertens avatar Jan 26 '22 13:01 wmertens

Thank you for your contribution! I marked this issue as stale due to inactivity. Please be considerate of people watching this issue and receiving notifications before commenting 'I have this issue too'. We welcome additional information that will help resolve this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

  • If this is resolved, please consider closing it so that the maintainers know not to focus on this.
  • If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough.
  • If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.
If you are not the original author of the issue

  • If you are also experiencing this issue, please add details of your situation to help with the debugging process.
  • If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.
Memorandum on closing issues

Don't be afraid to manually close an issue, even if it holds valuable information. Closed issues stay in the system for people to search, read, cross-reference, or even reopen – nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.

stale[bot] avatar May 01 '22 01:05 stale[bot]

The command home-manager switch --flake uses the homeConfigurations output whereas Nix uses nixosConfigurations.

That's the piece of info I needed, thanks! It's in the manpage of home-configuration but this should also be documented https://nix-community.github.io/home-manager/, wdyt?

autra avatar Mar 25 '24 09:03 autra

Thank you for your contribution! I marked this issue as stale due to inactivity. Please be considerate of people watching this issue and receiving notifications before commenting 'I have this issue too'. We welcome additional information that will help resolve this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

  • If this is resolved, please consider closing it so that the maintainers know not to focus on this.
  • If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough.
  • If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.
If you are not the original author of the issue

  • If you are also experiencing this issue, please add details of your situation to help with the debugging process.
  • If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.
Memorandum on closing issues

Don't be afraid to manually close an issue, even if it holds valuable information. Closed issues stay in the system for people to search, read, cross-reference, or even reopen – nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.

stale[bot] avatar Jun 26 '24 03:06 stale[bot]