Including local packages in home manager configuration

Hi,
I’m quite new to Nix. I’m now using NixPkgs via home manager on my Ubuntu systems for 6 months or so. I’ve recently learned about the possibility of including local packages that are not yet available in the nix store. So I made a start of defining my local package (bsync) in my case. Which I can build and run from the resulr/bin/ but I just can’t figure out what is missing in my config so that it will be made available via my home manager flake.

I’ve created a minimal example repository with configs based on the nice GitHub - Misterio77/nix-starter-configs: Simple and documented config templates to help you get started with NixOS + home-manager + flakes. All the boilerplate you need! which you can find here:

I must be missing something very obvious that causes home-manager switch to fail with the error message at the end. Maybe people with more experience can point out where I went wrong?

error:
       … while calling the 'derivationStrict' builtin

         at /builtin/derivation.nix:9:12: (source not available)

       … while evaluating derivation 'home-manager-generation'
         whose name attribute is located at /nix/store/b0l3v8509hrl3qbv6fj2zl0mjb2rwhdy-source/pkgs/stdenv/generic/make-derivation.nix:351:7

       … while evaluating attribute 'buildCommand' of derivation 'home-manager-generation'

         at /nix/store/b0l3v8509hrl3qbv6fj2zl0mjb2rwhdy-source/pkgs/build-support/trivial-builders/default.nix:98:16:

           97|         enableParallelBuilding = true;
           98|         inherit buildCommand name;
             |                ^
           99|         passAsFile = [ "buildCommand" ]

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

       error: getting status of '/nix/store/1z500r8mam81nlbyz5v5xp5wr639j1pv-source/default.nix': No such file or directory

Rather than trying to get your flake via import-ing the current directory, you should be getting it through the self flake input.

Here’s a blog post covering how: Getting inputs to modules in a nix-flake | NobbZ' Blog

The specific error just says that there is no default.nix file, import ./. expands to import ./default.nix because the default “entrypoint” file for a directory is default.nix, and you specified a directory to import. Since there is no such file, nix errors out - the correct solution isn’t to add a default.nix, though.

Thanks for the pointer and explanation. Having read the blog post, I thought to try the variant with extraSpecialArgs and adding my local packages to the inputs.

So I added

inputs = {
...
 localpkgs.url = "./pkgs";
}

and

extraSpecialArgs = {inherit inputs;};

which then causes the build to complain that it can not find a pkgs/flake.nix file. Changing the URL to:

localpkgs.url = "./pkgs/default.nix";

then causes build to complain that that URL is no directory.

So I am still a bit lost I’m afraid.

Yeah, you’re still a bit confused. This should do the trick:

diff --git a/flake.nix b/flake.nix
index be51167..aba6923 100644
--- a/flake.nix
+++ b/flake.nix
@@ -10,7 +10,7 @@
     };
   };
 
-  outputs = { nixpkgs, home-manager, ... }:
+  outputs = { nixpkgs, home-manager, ... } @ inputs:
     let
       system = "x86_64-linux";
       pkgs = nixpkgs.legacyPackages.${system};
@@ -34,6 +34,9 @@
 
         # Optionally use extraSpecialArgs
         # to pass through arguments to home.nix
+        extraSpecialArgs = {
+          inherit inputs;
+        };
       };
       # Custom packages, that can be defined similarly to ones from nixpkgs
       # Build them using 'nix build .#example'
diff --git a/home.nix b/home.nix
index 689c61e..aaed848 100644
--- a/home.nix
+++ b/home.nix
@@ -1,4 +1,4 @@
-{ config, pkgs, ... }:
+{ inputs, config, pkgs, ... }:
 
 let
   # import the local flake so we can use the packages defined in it
@@ -30,7 +30,7 @@ in
     pkgs.hello
 
     # local packages
-    myFlake.packages.${system}.bsync
+    inputs.self.packages.${system}.bsync
   ];
 
   home.shellAliases = {

self is just an input on flakes, no need to declare it or anything.

2 Likes

Thanks @TLATER That did it. I appreciate the help very much.