lovesegfault/nix-config

Using this config without changing to `legacyPackages`

Closed this issue · 4 comments

Thanks for publishing your awesome config! When trying to adapt it to my own needs, I noticed that nix flake check always fails with the message

error: flake attribute 'packages.x86_64-linux.darwin' is not a derivation

The reason seems to be that the packages attribute set always requires to have derivations as the values, which somehow is not the case here. Renaming packages to legacyPackages fixes this, but this seems like a workaround to me. Judging by your activity you are using this config regularly, so I wonder what I am missing to make it work without using legacyPackages. I hope you can shed some light onto this.

Should have been fixed by d7ce724, can you confirm?

There was an issue with the weird recursive structure I was creating in hosts.nix, I ended up refactoring that whole thing to make it simpler.

nix flake check now passes.

Thanks the issue is fixed now. Although the newly introduced structure seems to break when you don't define any hosts with homeManager as the type (as it will then not emit the homeManager attribute at all)

error: attribute 'homeManager' missing

       at /nix/store/xqfybkdsi4vsg3arr5v5jcgnl3m8210k-source/nix/home-manager.nix:9:11:

            8|   inherit (nixpkgs) lib;
            9|   hosts = (import ./hosts.nix).homeManager;
             |           ^
           10|

Easy to fix by defining a dummy host of that type, but in that regard the old structure was more flexible.

Not sure if this is the best solution, but I settled for this:

diff --git a/nix/home-manager.nix b/nix/home-manager.nix
index cfa9812..cfb2852 100644
--- a/nix/home-manager.nix
+++ b/nix/home-manager.nix
@@ -6,7 +6,12 @@
   ...
 }: let
   inherit (nixpkgs) lib;
-  hosts = (import ./hosts.nix).homeManager;
+  hosts = let
+    hostsNix = import ./hosts.nix;
+  in
+    if builtins.hasAttr "homeManager" hostsNix
+    then hostsNix.homeManager
+    else {};

   genModules = hostName: {homeDirectory, ...}: {
     config,

Fixed by:
0d528ae
c720068