srid / nixos-flake

A flake-parts module to manage NixOS and macOS machines, along with home-manager support, in a unified fashion.
https://community.flake.parts/nixos-flake
MIT License
175 stars 19 forks source link

`nix run .#activate` doesn't work with template on new creation due to missing attribute key #63

Closed bjeanes closed 1 month ago

bjeanes commented 1 month ago
❯ nix run .#activate
error:
       … while calling the 'derivationStrict' builtin
         at <nix/derivation-internal.nix>:9:12:
            8|
            9|   strict = derivationStrict drvAttrs;
             |            ^
           10|

       … while evaluating derivation 'activate'
         whose name attribute is located at /nix/store/iqxdbcjlg9wx8gdc8bdhy9nsd5imcbjp-source/pkgs/stdenv/generic/make-derivation.nix:334:7

       … while evaluating attribute 'buildCommand' of derivation 'activate'
         at /nix/store/iqxdbcjlg9wx8gdc8bdhy9nsd5imcbjp-source/pkgs/build-support/trivial-builders/default.nix:68:17:
           67|         enableParallelBuilding = true;
           68|         inherit buildCommand name;
             |                 ^
           69|         passAsFile = [ "buildCommand" ]

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: attribute 'config' missing
       at /nix/store/f49330az5gydh6ca7923c0q431hbzavg-source/activate/default.nix:11:56:
           10|       };
           11|       nixos-flake-configs = lib.mapAttrs (name: value: value.config.nixos-flake) (self.nixosConfigurations or { } // self.darwinConfigurations or { });
             |                                                        ^
           12|       data = {

https://github.com/srid/nixos-flake/blob/cab6539d198792f94fbac029e5a63523604fd172/activate/default.nix#L11

bjeanes commented 1 month ago

Ah I think this is because of the use of hostname instead of hostname -s as commented here: https://github.com/srid/nixos-flake/commit/b9f22bec6dee3b6f214974520a960d83d270dcfc#r144271657

I tried to work around this with both:

darwinConfigurations."Bandersnatch.local" = self.nixos-flake.lib.mkMacosSystem { ... };
# and
darwinConfigurations.Bandersnatch.local = self.nixos-flake.lib.mkMacosSystem { ... };

At least the latter variant was causing this issue of error: attribute 'config' missing when evaluating value.config.nixos-flake.

I forked nixos-flake and changed to hostname -s and nix run .#activate then started getting further.