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
Hi,
I'm trying to declare multiple users using home-manager as a NixOS Module (using Flakes) and a custom function that creates the users.
Excerpts from configuration - flake.nix:
# Home Managerinputs.home={url="github:nix-community/home-manager?ref=release-21.11";inputs.nixpkgs.follows="nixpkgs";};outputs={self, ... } @ inputs:
let# System Libraries
inherit (inputs.nixpkgs)lib;# Custom Functionsutil=import./lib{inheritsystemversionfileslibinputspkgs;};inherit(util)buildmap;in{## Device Configuration ##nixosConfigurations.Vortex=build.device{name="Vortex";users=[# User V7{username="v7";description="V 7";groups=["wheel"];uid=1000;shell="zsh";}# User NixOS{username="nixos";description="nix";groups=["wheel"];uid=1000;shell="zsh";}];};
lib/build.nix:
{build,system,version,lib,inputs,pkgs,files, ... }:
{## Device Configuration Function ##device={name,timezone,locale,kernel,kernelModules,hardware,desktop,apps,user}:
let# User Creationdevice_user=(map(u: build.useru)user);inlib.nixosSystem{inheritsystem;specialArgs={inheritsysteminputsfiles;};modules=[{# Modulated Configuration Importsimports=device_modules++device_user++[inputs.home.nixosModules.home-manager];}];};## User Configuration Function ##user={username,description?"",groups?[],uid?1000,shell,password?"",autologin?false}:
{# User Creation_module.args={inheritusername;};users.users."${username}"={# Profilename=username;};};
and an example module modules/user/home.nix which uses the home-manager option in conjunction with system configuration options (all my modules are freely mixed):
{config,username,files, ... }:
letversion=config.system.stateVersion;homeDir=config.home-manager.users."${username}".home.homeDirectory;inrec{## Home Manager Settings ##config={environment.systemPackages=[pkgs.neofetch];home-manager={useGlobalPkgs=true;useUserPackages=true;backupFileExtension="bak";users."${username}"={programs.home-manager.enable=true;systemd.user.startServices=true;home={username=username;homeDirectory="/home/${username}";stateVersion=version;};};};};}
Now when I try running nixos-rebuild switch, I get this error:
error: The option `home-manager.users' in `/nix/store/ifvia9687n60as6ym9nhwffs0p7sxjh9-source/lib/build.nix' is already declared in `/nix/store/ifvia9687n60as6ym9nhwffs0p7sxjh9-source/lib/build.nix'.
Can you please tell why it is showing such an error (since I have defined users separately using home-manager.users.USER instead of home-manager.users = { USER = import ./home.nix };), and also help correct my configuration if something is wrong
Okay, after importing the nixosModule in the system configuration, it seems to work, but I'm facing another error:
error: The option `home-manager.users.nixosv7.home.homeDirectory' has conflicting definition values:
- In `/nix/store/7ih387iyca3i13q6s37kk8fciyyk3p66-source/lib/build.nix': "/var/empty"
- In `/nix/store/7ih387iyca3i13q6s37kk8fciyyk3p66-source/modules/user/home.nix': "/home/nixosv7"
And, for some reason, it seems to be concatenating both the usernames, instead of applying the function separately
EDIT: The problem seems to be the way username is passed as an argument. But there seems to be no proper way to pass the username to the system configuration modules (I have also tried making an option user.name but if there are multiple users then it will produce a conflict). Is there any way to properly pass the usernames of all the users as arguments?
When using HM as a module, the username and homeDirectory are automatically set.
Otherwise, you could create an option in the Home Manager configuration that has the username since it wouldn't work in the system configuration.
From the system configuration you can then set the username using home-manager.users.${username}.my-username-option = username.
Is there an existing issue for this?
Issue description
Hi,
I'm trying to declare multiple users using
home-manager
as a NixOS Module (using Flakes) and a custom function that creates the users.Excerpts from configuration -
flake.nix
:lib/build.nix
:and an example module
modules/user/home.nix
which uses thehome-manager
option in conjunction with system configuration options (all my modules are freely mixed):(My full configuration is here)
Now when I try running
nixos-rebuild switch
, I get this error:Can you please tell why it is showing such an error (since I have defined users separately using
home-manager.users.USER
instead ofhome-manager.users = { USER = import ./home.nix };
), and also help correct my configuration if something is wrongMaintainer CC
@rycee
System information
The text was updated successfully, but these errors were encountered: