Skip to content

bug: ssh.matchBlocks with dag.entryBefore or dag.entryAfter ignore order when glob is in name(s) #7781

Description

@S0AndS0

Are you following the right branch?

  • My Nixpkgs and Home Manager versions are in sync

Is there an existing issue for this?

  • I have searched the existing issues

Issue description

modules/programs/ssh.nix provides example/docs of;

      example = literalExpression ''
        {
          "john.example.com" = {
            hostname = "example.com";
            user = "john";
          };
          foo = lib.hm.dag.entryBefore ["john.example.com"] {
            hostname = "example.com";
            identityFile = "/home/john/.ssh/foo_rsa";
          };
        };
      '';

... but attempting to use lib.hm.dag.entryBefore, or the entryAfter, with globs results in ordering intent being ignored, ex.

  programs.ssh = {
    enable = true;

    enableDefaultConfig = false;
    matchBlocks = {
      "*" = {
        forwardAgent = false;
        serverAliveInterval = 0;
        serverAliveCountMax = 3;
        compression = false;
        addKeysToAgent = "no";
        hashKnownHosts = false;
        userKnownHostsFile = "~/.ssh/known_hosts";
        controlMaster = "no";
        controlPath = "~/.ssh/master-%r@%n:%p";
        controlPersist = "no";
      };

      "tor-*" = lib.hm.dag.entryAfter ["*"] {
        proxyCommand = "${pkgs.socat} STDIO SOCKS4A:127.0.0.1:%h:%p,socksport=9050";
        addressFamily = "inet";
        compression = true;
      };
    };
  };

Which results in configurations that are not correctly ordered, ex.

Host tor-*
  AddressFamily inet
  Compression yes
  ProxyCommand /nix/store/yix90k1p75kd7id215ljfbz2j1zqbcsh-socat-1.8.0.3 STDIO SOCKS4A:127.0.0.1:%h:%p,socksport=9050

Host *
  ForwardAgent no
  ServerAliveInterval 0
  ServerAliveCountMax 3
  Compression no
  AddKeysToAgent no
  HashKnownHosts no
  UserKnownHostsFile ~/.ssh/known_hosts
  ControlMaster no
  ControlPath ~/.ssh/master-%r@%n:%p
  ControlPersist no

I've also tried defining entryBefore on the top-level glob, and a combo of the two too;

   programs.ssh = {
     enable = true;
 
     enableDefaultConfig = false;
     matchBlocks = {
-      "*" = {
+      "*" = lib.hm.dag.entryBefore ["tor-*"] {
         # ...
       };
 
-      "tor-*" = lib.hm.dag.entryAfter ["*"] {
+      "tor-*" = {
         # ...
       };
     };
   };

... but no joy with that either.

Maintainer CC

@rycee

System information

- system: `"x86_64-linux"`
 - host os: `Linux 6.16.1, NixOS, 25.11 (Xantusia), 25.11.20250902.d0fc308`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.28.4`
 - channels(root): `"home-manager-25.05.tar.gz, nixos-25.05, nixos-hardware"`
 - nixpkgs: `/nix/store/8vfhnwmmzqqzy97q9c5m4bzyaqqf63zy-source`

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugtriageIssues or feature request that have not been triaged yet

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions