nix-community/nixos-anywhere

error: attribute 'diskNoDeps' missing ?

Closed this issue · 10 comments

I am trying to follow https://nix-community.github.io/nixos-anywhere/howtos/use-without-flakes.html
but I am facing this error (on nixos 23.05 x86_64).

[tru@nuc-nixos:~/nixos-anywhere]$ nix-build -I nixos-config=/etc/nixos/configuration.nix -E '(import <nixpkgs/nixos> {}).config.system.build.diskNoDeps'
        error: attribute 'diskNoDeps' missing
         
               at «string»:1:1:
         
                    1| (import <nixpkgs/nixos> {}).config.system.build.diskNoDeps
                     | ^
         

OTOH, nix-build -I nixos-config=/etc/nixos/configuration.nix -E '(import <nixpkgs/nixos> {}).config.system.build' runs fine (but that is not what is listed on the page).

Ah there is a typo in the manual. It should be diskoNoDeps

[tru@nuc-nixos:~/nixos-anywhere]$ nix-build -I nixos-config=/etc/nixos/configuration.nix -E '(import <nixpkgs/nixos> {}).config.system.build.diskoNoDeps'
error: attribute 'diskoNoDeps' missing

       at «string»:1:1:

            1| (import <nixpkgs/nixos> {}).config.system.build.diskoNoDeps
             | ^

Mic92 commented

Looks like you are not importing disko into your nixos configuration: #233

I am still new to nixos, have I missed anything?
Here are the files I am working with and the disko module is imported from the flake.nix file, no?

flake.nix:

{
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
  inputs.disko.url = "github:nix-community/disko";
  inputs.disko.inputs.nixpkgs.follows = "nixpkgs";

  outputs = { self, nixpkgs, disko, ... }:
    {
      nixosConfigurations.nixos-efi-toy = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        modules = [
          ./configuration.nix
          disko.nixosModules.disko
        ];
      };
    };
}

configuration.nix:

{ config, pkgs, ... }:
{
  imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
    ];
  # Use the systemd-boot EFI boot loader.
  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;
  time.timeZone = "Europe/Paris";
  i18n.defaultLocale = "en_US.UTF-8";
  console = {
    font = "Lat2-Terminus16";
  };
  environment.systemPackages = with pkgs; [
    wget curl lftp elinks sudo tmux screen parted vim
  ];
  programs.mtr.enable = true;
  programs.gnupg.agent = {
    enable = true;
    enableSSHSupport = true;
  };
  services.openssh.enable = true;
  system.copySystemConfiguration = true;
  system.stateVersion = "23.05"; # Did you read the comment?
}

disk-config.nix:

# Example to create a bios compatible gpt partition
{ lib, ... }:
{
  disko.devices = {
    disk.disk1 = {
      device = lib.mkDefault "/dev/sda";
      type = "disk";
      content = {
        type = "gpt";
        partitions = {
          boot = {
            name = "boot";
            size = "1M";
            type = "EF02";
          };
          esp = {
            name = "ESP";
            size = "500M";
            type = "EF00";
            content = {
              type = "filesystem";
              format = "vfat";
              mountpoint = "/boot";
            };
          };
          root = {
            name = "root";
            size = "40G%";
            content = {
              type = "lvm_pv";
              vg = "pool";
            };
          };
        };
      };
    };
    lvm_vg = {
      pool = {
        type = "lvm_vg";
        lvs = {
          root = {
            size = "100%FREE";
            content = {
              type = "filesystem";
              format = "xfs";
              mountpoint = "/";
              mountOptions = [
                "defaults"
              ];
            };
          };
        };
      };
    };
  };
}

hardware-configuration.nix:

{ config, lib, pkgs, modulesPath, ... }:
{
  imports = [ ];
  boot.initrd.availableKernelModules = [ "ata_piix" "ohci_pci" "ehci_pci" "ahci" "sd_mod" "sr_mod" ];
  boot.initrd.kernelModules = [ ];
  boot.kernelModules = [ ];
  boot.extraModulePackages = [ ];
  fileSystems."/" =
    { device = "/dev/disk/by-uuid/4c77d324-90dc-4053-a4ce-2953649f6517";
      fsType = "xfs";
    };
  fileSystems."/boot" =
    { device = "/dev/disk/by-uuid/12F7-9A82";
      fsType = "vfat";
    };
  swapDevices = [ ];
  # Enables DHCP on each ethernet and wireless interface. In case of scripted networking
  # (the default) this is the recommended approach. When using systemd-networkd it's
  # still possible to use this option, but it's recommended to use it in conjunction
  # with explicit per-interface declarations with `networking.interfaces.<interface>.useDHCP`.
  networking.useDHCP = lib.mkDefault true;
  # networking.interfaces.enp0s3.useDHCP = lib.mkDefault true;
  nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
  virtualisation.virtualbox.guest.enable = true;
}

[tru@nixos:~/nixos-anywhere]$ nix flake lock
warning: creating lock file '/home/tru/nixos-anywhere/flake.lock'
[tru@nixos:~/nixos-anywhere]$ nix-build -I nixos-config=./configuration.nix -E '(import <nixpkgs/nixos> {}).config.system.build.toplevel'
/nix/store/g97zqhisfnar8hh14m70hsj57azqpnx7-nixos-system-nixos-23.05.3976.32dcb45f66c0
[tru@nixos:~/nixos-anywhere]$ nix-build -I nixos-config=./configuration.nix -E '(import <nixpkgs/nixos> {}).config.system.build.diskoNoDeps'
error: attribute 'diskoNoDeps' missing

       at «string»:1:1:

            1| (import <nixpkgs/nixos> {}).config.system.build.diskoNoDeps
             | ^

phaer commented

Here are the files I am working with and the disko module is imported from the flake.nix file, no?

It's imported in your flake.nix, but

[tru@nuc-nixos:~/nixos-anywhere]$ nix-build -I nixos-config=/etc/nixos/configuration.nix -E '(import <nixpkgs/nixos> {}).config.system.build.diskoNoDeps'` 

doesn't use the flake, but uses configuration.nix only, where it isn't imported.

Something like

nix build .#nixosConfigurations.nixos-efi-toy.config.system.build.diskoNoDeps

Should work?

I was using -I nixos-config=./configuration.nix in #231 (comment) and no longer the /etc/nixos/configuration.nix file, but that did not help.

Here is what you have requested:

[tru@nixos:~/nixos-anywhere]$ nix build .#nixosConfigurations.nixos-efi-toy.config.system.build.diskoNoDeps
error: flake 'path:/home/tru/nixos-anywhere' does not provide attribute 'packages.x86_64-linux.nixosConfigurations.nixos-efi-toy.config.system.build.diskoNoDeps', 'legacyPackages.x86_64-linux.nixosConfigurations.nixos-efi-toy.config.system.build.diskoNoDeps' or 'nixosConfigurations.nixos-efi-toy.config.system.build.diskoNoDeps'
phaer commented

You need to run that from your flakes directory, the flake where you've defined the nixos-efi-toy nixosConfiguration or replace the first '.' with the path to said directory.

If you then still get same error, check with nix flake show whether that nixosConfiguration is defined in your flake - your flake.nix above suggests it does

Also, replace the deprecated .diskoNoDeps with .diskoScriptNoDeps (otherwise you'll get a warning telling you the same.

I think I am doing it right, but still failing:

[tru@nixos:~/nixos-anywhere]$ nix flake show
path:/home/tru/nixos-anywhere?lastModified=1697471440&narHash=sha256-o3TYGCRdyBuzX4LBR0DKq2Au+RMPyKarZ+wlRmFsUqI=
└───nixosConfigurations
    └───nixos-efi-toy: NixOS configuration

[tru@nixos:~/nixos-anywhere]$ pwd
/home/tru/nixos-anywhere

[tru@nixos:~/nixos-anywhere]$ ls -l *.nix *.lock
-rw-r--r-- 1 tru users  738 Oct 16 16:41 configuration.nix
-rw-r--r-- 1 tru users 1184 Oct 16 16:23 disk-config.nix
-rw-r--r-- 1 tru users 1087 Oct 16 16:52 flake.lock
-rw-r--r-- 1 tru users  433 Oct 16 16:37 flake.nix
-rw-r--r-- 1 tru users 1263 Oct 16 16:42 hardware-configuration.nix

[tru@nixos:~/nixos-anywhere]$ nix build .#nixosConfigurations.nixos-efi-toy.config.system.build.diskoScriptNoDeps
error: flake 'path:/home/tru/nixos-anywhere' does not provide attribute 'packages.x86_64-linux.nixosConfigurations.nixos-efi-toy.config.system.build.diskoScriptNoDeps', 'legacyPackages.x86_64-linux.nixosConfigurations.nixos-efi-toy.config.system.build.diskoScriptNoDeps' or 'nixosConfigurations.nixos-efi-toy.config.system.build.diskoScriptNoDeps'
[tru@nixos:~/nixos-anywhere]$ nix build /home/tru/nixos-anywhere/configuration.nix#os-efi-toy.config.system.build.diskoScriptNoDeps
path '/home/tru/nixos-anywhere/configuration.nix' does not contain a 'flake.nix', searching up
error: flake 'path:/home/tru/nixos-anywhere' does not provide attribute 'packages.x86_64-linux.os-efi-toy.config.system.build.diskoScriptNoDeps', 'legacyPackages.x86_64-linux.os-efi-toy.config.system.build.diskoScriptNoDeps' or 'os-efi-toy.config.system.build.diskoScriptNoDeps'
phaer commented

I think I am doing it right, but still failing:

I took the time to reproduce your example with the files you've posted: The issue is that you don't include your disk-config.nix, if you add it to your modules as in

        modules = [
          ./configuration.nix
          disko.nixosModules.disko
          ./disk-config.nix
        ];

You'll get a warning and an actual error, if you then use the non-deprecated attribute as I've suggested above i.e.

nix build .#nixosConfigurations.nixos-efi-toy.config.system.build.diskoScriptNoDeps

It works as such, you just have a small error in your config left:

error: A definition for option `disko.devices.disk.disk1.content.partitions.root.size' is not of type `value "100%" (singular enum) or string matching the pattern [0-9]+[KMGTP]?'. Definition values:
       - In `/nix/store/a0lvzj5x9qgpph4730bqqh0xn3x6mgd5-source/disk-config.nix': "40G%"

So remove the "%" here.

thanks! that was it... disk-config.nix missing from flake.nix.
I had just adapted the https://github.com/numtide/nixos-anywhere-examples/blob/main/flake.nix file which is also missing the ./disk-config.nix line...

The "40G%" is my typo, changing the "100%" initial value to "40G".
I really appreciate your kind help on the matter.