Using extraSpecialArgs from flake to carry variable over to home manager, syntax error

Hello, trying to clean up my config with variables and consolidating module .nix files and dotfiles. In any case… I think I’m close. Here is a tree dump, flake.nix, home.nix and error output :

tree dump… :

.
├── flake.nix
├── homeManagerModules
│   └── dotfiles
│   │   └── config
│   │       └── hypr
│   └── tmux.nix
├── hosts
│   └── tbnix
│       ├── default.nix
│       ├── hardware.nix
│       ├── home.nix
│       └── network.nix
├── nixosModules
     └── hyprland.nix
## flake.nix

...
  let

    homeManager = {
         df = ./homeManagerModules/dotfiles;
         cfg = ./homeManagerModules/dotfiles/config;
    };

    system = "x86_64-linux";

  in
...
  {
    # NixOS configuration entrypoint
    nixosConfigurations = {
      tbnix = nixpkgs.lib.nixosSystem {
        specialArgs = { 
          inherit system; inherit inputs;
        };
        modules = [
          home-manager.nixosModules.home-manager {
            home-manager.extraSpecialArgs = { inherit homeManager; };
            home-manager.useGlobalPkgs = true;
            home-manager.useUserPackages = true;
            home-manager.users.fez = import ./hosts/tbnix/home.nix;
          }
          # nixos-cosmic.nixosModules.default
          ./hosts/tbnix
        ];
      };
...
# ./hosts/tbnix/home.nix
{ inputs, config, lib, pkgs, modulesPath, homeManager, ... }:

{
  imports = [
    ../common/home.nix 
  ];

  home.file = {
    ".config/hypr/common.conf" = {
      source = {homeManager.cfg}/hypr/common.conf;
    };
    ".config/hypr/keybind" = {
      source = {homeManager.cfg}/hypr/keybind;
    };
...

# ERROR

...
      error: syntax error, unexpected '}', expecting '.' or '='
       at /nix/store/5mj2gnkzi1qzdpl806rfsn7mbra8imqv-source/hosts/tbnix/home.nix:10:32:
            9|     ".config/hypr/common.conf" = {
           10|       source = {homeManager.cfg}/hypr/common.conf;
             |                                ^
           11|     };

Thank you

Paths support string interpolation, but you still need the $ and you need at least one leading /. See: Data Types - Nix Reference Manual

This should (hopefully) fix it, you may need to change the definition of your variable though - no idea if interpolation correctly resolves path separators in the substituted string part:

  home.file = {
    ".config/hypr/common.conf" = {
      source = ./${homeManager.cfg}/hypr/common.conf;
    };
    ".config/hypr/keybind" = {
      source = ./${homeManager.cfg}/hypr/keybind;
    };

OTOH, simple concatenation may just be better:

  home.file = {
    ".config/hypr/common.conf" = {
      source = homeManager.cfg + ./hypr/common.conf;
    };
    ".config/hypr/keybind" = {
      source = homeManager.cfg + ./hypr/keybind;
    };
2 Likes

Nice! yeah that seems to have fixed the home.file section. However, now the error moved to the imports section of my ./common/home.nix.

Here is the common home.nix section that has the error:

# common home.nix
{ inputs, config, lib, pkgs, modulesPath, homeManager, ... }:

{
  imports = [
    homeManager.df + ./tmux.nix
    homeManager.df + ./lf.nix
    homeManager.df + ./lsp.nix
    homeManager.df + ./zsh.nix
    homeManager.df + ./vscode.nix
  ];

...
# ERROR
       error: syntax error, unexpected '+'
       at /nix/store/594b6wcrd61jfb3p0xzq5q2vvaxlyaks-source/hosts/common/home.nix:12:20:
           11|
           12|     homeManager.df + ./tmux.nix
             |                    ^
           13|     homeManager.df + ./lf.nix

TY!

You need to wrap that into () So that it becomes (home manager.df + "/tmux.nix") and so on

4 Likes

That did it, I had some other path issues, removed periods and carried over the extraSpecialArgs to other home.nix files and nix flake check is happy. TY!

1 Like