Hello, Nix Community,
I’m currently in the process of modularizing my NixOS config, moving it to flakes, and finally using home-manager (as a module). Still pretty noob so, sorry in advance.
Goal: I want to enable a service (in my case, onedrive) that is not among builtin home-manager options, and I would like to configure it declaratively with home-manager (by setting home.file.".config/onedrive/sync_list".text = ''# some config''
). Pretty standard I guess?
Problem: I would like all this (enable+config) to be in a single onedrive.nix file that I can import. But I’m having a fundamental doubt on how / whether this is possible. Take this module for onedrive
located in /modules/onedrive.nix
as an example:
{ user, pkgs, config, ... }:
let
onePkg = pkgs.onedrive;
in
{
config = {
services.onedrive = {
enable = true;
package = onePkg;
};
systemd.services.onedrive.serviceConfig = {
ExecStart = "${onePkg}/bin/onedrive --monitor --confdir ${config.users.users.${user}.home}/.config/onedrive";
};
home.file.".config/onedrive/sync_list".text = ''
# onedrive config file content
'';
};
}
which can be imported either as a Nix module or a HM module (sorry if the terms are not precise) from my current main flake.nix config:
# ...
nixosConfigurations = {
"nixos" = nixpkgs.lib.nixosSystem {
modules = [
./modules # --> OPTION 1: default.nix imports onedrive.nix as a Nix module
home-manager.nixosModules.home-manager {
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users.${user} = import ./modules/home.nix; # --> OPTION 2: home.nix imports onedrive.nix as a HM module
}
];
};
};
My dilemma is this: If I import this module as a typical system module, it doesn’t recognize home
. Conversely, importing it as a Home Manager module means it doesn’t recognize services
since it’s expecting a home-manager.users.user.services.onedrive
option, which doesn’t exist. I’m striving for a solution where a single module can be loaded to both enable the service and configure it, avoiding the need to separately import service and configuration modules.
Does anyone have insights or advice on achieving this? Is there a way to bridge or integrate these configurations more seamlessly, possibly by defining a system service and its user-level configuration within the same modular structure?
A less elegant solution would be to have some kind of mirror folder structure for modules and their configurations, but I would like to know what are the best practices in cases like this.
Any guidance or examples would be greatly appreciated. And forgive me for my noobness.
Thank you for your time and help!