You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For testing, introspection and migration purposes, I would like to be able to build a home directory from an existing nixosConfiguration.HOST.home-manager.users.USER in a flake.
Most guides assume a cleanly separated project structure, where a single home.nix is the entry module bundling everything around home-manager.users.USER. With that, a simple homeConfiguration.USER with a modules import like modules = [ ./home.nix ]; is sufficient to build a result home directory via home-manager build –flake .#USER but this approach has two drawbacks.
Logically, your home configuration is likely tied to the underlying system configuration, forcefully splitting these can create unnecessary headache.
In my most recent case, I was building a nas_client.nix that was defining system mounts as well as thunar bookmarks to them via home-manager. I broke out of a clean home.nix.
It kind of contradicts the spirit of the nixos module system. Order (location) of modules should not matter when evaluated by tools.
For tinkering, or maybe better understanding, there is a full demo flake below.
Attempt 2 seems to be promising to become a hacky way to achieve the goal of a homeConfiguraion.USER definition in a flake that can be build with home-manager build –flake .#USER but I am lacking the knowledge to get past the weird error.
I am sorry if i missed a spelled out solution to this. Otherwise, if a hacky solution is possible, maybe update the docs with it.
{inputs={nixpkgs.url="github:nixos/nixpkgs?ref=nixos-unstable";home-manager={url="github:nix-community/home-manager";inputs.nixpkgs.follows="nixpkgs";};};outputs={self,nixpkgs,home-manager,}:
letsystem="x86_64-linux";pkgs=nixpkgs.legacyPackages.${system};username="USER";hostname="HOST";inrec{# Attempt 1# Define regular nixosConfiguration and reach into it to build home selectivelynixosConfigurations.${hostname}=nixpkgs.lib.nixosSystem{modules=[# home-manager modulehome-manager.nixosModules.home-manager{home-manager.users.${username}.home={inheritusername;stateVersion="24.11";homeDirectory="/home/${username}";};}(# regular nixos module{ ... }:
{nixpkgs.hostPlatform=system;boot.isContainer=true;users.users.${username}.isNormalUser=true;})];};# Attempt 2# Wrap the HM part of the existing nixosConfiguraion into a homeConfigurationhomeConfigurations.${username}=home-manager.lib.homeManagerConfiguration{inheritpkgs;modules=[nixosConfigurations.${hostname}.config.home-manager.users.${username}];};devShells.${system}.default=pkgs.mkShell{buildInputs=[pkgs.nixos-generatorspkgs.home-manager];shellHook='' set -x alias ATTEMP_1="nix build .#nixosConfigurations.${hostname}.config.system.build.toplevel" # or something alias ATTEMP_2="home-manager build --flake .#${username}" set +x '';};};}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
For testing, introspection and migration purposes, I would like to be able to build a home directory from an existing
nixosConfiguration.HOST.home-manager.users.USERin a flake.Most guides assume a cleanly separated project structure, where a single
home.nixis the entry module bundling everything aroundhome-manager.users.USER. With that, a simplehomeConfiguration.USERwith a modules import likemodules = [ ./home.nix ];is sufficient to build a result home directory viahome-manager build –flake .#USERbut this approach has two drawbacks.In my most recent case, I was building a
nas_client.nixthat was defining system mounts as well as thunar bookmarks to them via home-manager. I broke out of a clean home.nix.For tinkering, or maybe better understanding, there is a full demo flake below.
Attempt 2 seems to be promising to become a hacky way to achieve the goal of a
homeConfiguraion.USERdefinition in a flake that can be build withhome-manager build –flake .#USERbut I am lacking the knowledge to get past the weird error.I am sorry if i missed a spelled out solution to this. Otherwise, if a hacky solution is possible, maybe update the docs with it.
Beta Was this translation helpful? Give feedback.
All reactions