Hey @yunfachi, this looks great!
Can you please help me use umport?
I’m currently trying to use it in a flake.nix
(nix-darwin) > home.nix
(home manager) > modules
context and really strugging to get past issues ( similar to that I’ve encountered since migrating from just a home manager flake.nix
> modules setup) because I no longer have a modules block as per your examples in my home manager config (home.nix
, no longer flake.nix
) other than in nix-darwin’s flake.nix
, and I want my home manager modules loaded via home.nix
). I have tried in the home manager module in nix-darwin’s flake but failed.
My goal is to later use umport too in the nix-darwin flake for any modules eventually installed via it system-wide, so if that is something you can advise on too while helping me understand how to use umport in home manager, that would be much appreciated!
PS Thank you for such a great tool and one that I’m surprised didn’t exist until you built it and it appears for upgrading it to use lib.fileset (another great addition to nix I’m grateful for as I will hopefully learn properly after resolving this issue).
Abbreviated flake.nix
(nix-darwin):
{
description = "xxx's nix-darwin flake";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-23.11-darwin";
nixpkgs-unstable.url = "github:NixOs/nixpkgs/nixpkgs-unstable";
home-manager.url = "github:nix-community/home-manager/release-23.11";
home-manager.inputs.nixpkgs.follows = "nixpkgs";
nix-darwin.url = "github:LnL7/nix-darwin";
nix-darwin.inputs.nixpkgs.follows = "nixpkgs";
nur.url = "github:nix-community/NUR";
nypkgs.url = "github:yunfachi/nypkgs";
nypkgs.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = inputs@{ self, nixpkgs, nixpkgs-unstable, nix-darwin, nur, home-manager, nypkgs, ... }:
let
unstableOverlay = final: prev: {
unstable = import nixpkgs-unstable {
system = "aarch64-darwin";
};
};
ylib = nypkgs.lib.aarch64-darwin; <---##### Added because otherwise ylib was unknown
configuration = { pkgs, ... }: {
environment.systemPackages = [ ];
services.nix-daemon.enable = true;
nix = {
extraOptions = ''
extra-platforms = x86_64-darwin aarch64-darwin
'';
settings = {
experimental-features = "nix-command flakes";
};
};
programs.zsh.enable = true; # default shell on catalina
system = {
configurationRevision = self.rev or self.dirtyRev or null;
stateVersion = 4;
};
nixpkgs = {
hostPlatform = "aarch64-darwin";
config = { allowUnfree = true; };
overlays = [
nur.overlay
unstableOverlay
];
};
imports = [ ./options-nix-darwin/options-nix-darwin.nix ];
# eg settings to change dock location etc.
};
in
{
darwinConfigurations."myhostname" = nix-darwin.lib.darwinSystem {
specialArgs = { inherit inputs; inherit ylib; };
modules = [
configuration
home-manager.darwinModules.home-manager {
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
users.xxx = import ./nixpkgs/home.nix;
extraSpecialArgs = { inherit inputs; };
};
users.users.xxx.home = "/Users/xxx";
}
];
};
darwinPackages = self.darwinConfigurations."myhostname".pkgs;
# Expose the package set, including overlays, for convenience.
};
}
Abbreviated home.nix
{ pkgs, inputs, ... }:
let
unstable = import inputs.nixpkgs-unstable {
system = pkgs.system;
};
ylib = import inputs.nypkgs.lib.aarch64-darwin;
in
{
home = {
enableNixpkgsReleaseCheck = true;
stateVersion = "23.11";
packages = with pkgs; [
pkgs.unstable.mise
lunarvim
];
};
};
fonts.fontconfig.enable = true;
programs.home-manager.enable = true;
programs.home-manager.path = "$HOME/.config/nix-darwin/nixpkgs/";
### How I am trying and knowingly failing to use umport:
imports = [
ylib.umport {
paths = [ ./pkgs-home-manager/modules-macos-active ./options-home-manager];
recursive = true;
}
];
### How I currently am importing home manager modules/programs into home.nix, which works but is very annoying at the actual list of imports is much longer with different paths:
#imports = [
# ./home_manager/modules/cli/git.nix
# ## Home Manager Options
# ./home-manager-options.nix
#];
}
defaults.nix
{ylib, ...}: {
imports = ylib.umport {
paths = [./modules-macos-active];
recursive = true;
};
}
All files above:
~/.config/nix-darwin/flake.nix
~/.config/nix-darwin/nixpkgs/home.nix
~/.config/nix-darwin/nixpkgs/pkgs-home-manager/default.nix
~/.config/nix-darwin/nixpkgs/pkgs-home-manager/modules-macos-active/cli, gui, ...
each containing home manager modules (programs).
I have tried the way you present in the example, but for example ++ ylib.umport { ...
gives a concat error.
As you’ll see in my home.nix
, I previously imported every module (program) as path/module.nix
, and now am wanting to use the method you describe for a restructred fileset (more organised directories), which allows automatic importing once a default.nix
file in the root of the fileset. Mine is similar to yours, but all files are under . ./pkgs-home-manager/modules-macos-active
and subdirectores eg /cli, /gui…
As predicted I get error: cannot coerce a set to a string
, because I’m using imports = [ … that gets a fileset (or just because I’m using {}
), and I don’t know how to remove/replace the import
to bring the fileset’s modules (programes eg path/git.nix
) into home.nix
.
Thanks