Flakes input inside home.nix how to import it / how to use it

I am trying to switch to flakes with home manager but I don’t know how to use the inputs inside the home.nix.

When searching for this problem i always just see the flake.nix online but not how to use the input inside home.nix. I want to do this so i can use the unstable version of vscodium inside the home.nix
flake.nix:

{
  description = "My nixos config";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05";
    nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
    home-manager.url = "github:nix-community/home-manager/release-24.05";
    home-manager.inputs.nixpkgs.follows = "nixpkgs";
  };

  outputs = { nixpkgs, home-manager, nixpkgs-unstable, ... } @ inputs: {
    nixosConfigurations.nixos = nixpkgs.lib.nixosSystem {
      specialArgs = {
        inherit inputs;
      };
      modules = [
        ./configuration.nix
        home-manager.nixosModules.home-manager
        {
          home-manager.useGlobalPkgs = true;
          home-manager.useUserPackages = true;
          home-manager.backupFileExtension = "backup";
          home-manager.users.myname = import ./home.nix;
          home-manager.extraSpecialArgs = { inherit nixpkgs-unstable; };
        }
      ];
    };
  };
}

home.nix (partial)

{ pkgs, nixpkgs-unstable, ... }:
{

  home.username = "myname";
  home.packages = [
    nixpkgs-unstable.nixpkgs-fmt
  ];
...
[myname@nixos:~/nixos-config]$ sudo nixos-rebuild switch
building the system configuration...
evaluating derivation 'path:/home/myname/nixos-config#nixosConfigurations."nixos".config.system.build.toplevel'
error:
       … while calling the 'head' builtin

         at /nix/store/114462g9fhfa5ck1ssribfdh7wlk9m1s-source/lib/attrsets.nix:1575:11:

         1574|         || pred here (elemAt values 1) (head values) then
         1575|           head values
             |           ^
         1576|         else

       … while evaluating the attribute 'value'

         at /nix/store/114462g9fhfa5ck1ssribfdh7wlk9m1s-source/lib/modules.nix:809:9:

          808|     in warnDeprecation opt //
          809|       { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
             |         ^
          810|         inherit (res.defsFinal') highestPrio;

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

       error: attribute 'nixpkgs-fmt' missing

       at /nix/store/3k0sy2482k94pb8fcr7vqq5ipxgbfzbh-source/home.nix:6:5:

            5|   home.packages = [
            6|     nixpkgs-unstable.nixpkgs-fmt
             |     ^
            7|   ];

nixpkgs-unstable.legacyPackages.${pkgs.system}.nixpkgs-fmt is how you access that package.

1 Like

thanks i will try that when i get to back to work