Help a noob importing a flake to configuration.nix

hello, im trying to add :slight_smile:

to mi configuration.nix file.

if i type this in console:

[root@Predator:/nix/store]# nix build  --no-link --print-out-paths --eval-store auto github:niksingh710/nsearch
warning: $HOME ('/home/fher') is not owned by you, falling back to the one defined in the 'passwd' file ('/root')
/nix/store/nzkccqglq6q95vmqckvf7ncfd4fvidgf-nsearch

[root@Predator:/nix/store]# /nix/store/nzkccqglq6q95vmqckvf7ncfd4fvidgf-nsearch/bin/nsearch

all is right and run with no problem with absolute path

my questions are:

a) how can I add this to the path of the system from console (from nix build)

b) how can I add this to my configuration.nix so it works system wide as a environment.systemPackages and is reproducible (installs automatically with nixos-switch rebuild)

Thanks in advance

So I assume you donā€™t use a flake.nix to manage your system configurationā€¦ Iā€™d recommend you to do that, since people rely on it nowadays although it isnā€™t yet considered a ā€œstableā€ feature. If youā€™d insist on staying with the current non flake setup, Iā€™d try something like this:

  nixpkgs.overlays = let
    nsearchFlake= import (builtins.fetchTarball "https://github.com/niksingh710/nsearch/archive/master.tar.gz");
  in [
    (
      final: prev: {
        nsearch = nsearchFlake.packages.${self.pkgs.system}.default;
        # Your own overlays...
      }
    )
  ];

However, Iā€™m not sure about ${self.pkgs.system} so you might want to hard-code x86_64-linux instead.

Alternatively, since that is jusf a jq and fzf script, if you have both of these installed, you can simply ā€œinstallā€ it imperatively by cloning the repo and adding that nsearch script to your $PATH. Thatā€™s what I would do for such a simple script, as itā€™d allow me better control when Iā€™ll want to debug issues with it by myself.

1 Like

tryed to add what you said and gave me this error:

  at /etc/nixos/configuration.nix:29:43:

           28|       final: prev: {
           29|         nsearch = nsearchFlake.packages.${self.pkgs.system}.default;
             |                                           ^
           30|         # Your own overlays...

I donā€™t how to do the x86_64-linux part

Im less than a couple of months using nixos so be gentle with the explanation (im reading the documentation, but Its difficultā€¦).
And also thanks for the speedy answer.

edited:

with:

nixpkgs.overlays = let
		nsearchFlake= import (builtins.fetchTarball "https://github.com/niksingh710/nsearch/archive/master.tar.gz");
		in [
				(
			final: prev: {
				nsearch = nsearchFlake.packages.${pkgs.x86_64-linux.system}.default;
			# Your own overlays...
			}			)
			];
  

it doesnt gives error when nixos-rebuild switch, but i dont see the command in path and it doesnt have a path in store

I meant:

nixpkgs.overlays = let
    nsearchFlake= import (builtins.fetchTarball "https://github.com/niksingh710/nsearch/archive/master.tar.gz");
  in [
    (
      final: prev: {
        nsearch = nsearchFlake.packages.x86_64-linux.default;
        # Your own overlays...
      }
    )
  ];
1 Like

Thanks for the help, I found another way to do it , after messing with chatgpt for an hour i arrived to this.

created file nsearch.nix in /etc/nixos

{ config, pkgs, ... }:
	let
		myFlake = builtins.getFlake "github:niksingh710/nsearch";
	in
	{
	environment.systemPackages = with pkgs; [
(myFlake.packages.${system}.default or (throw "Package 'default' not found in the flake"))
	];
		}

got package name with :

[root@Predator:/etc/nixos]# nix flake show github:niksingh710/nsearch
github:niksingh710/nsearch/6661b4e24f30345ab307964e4fc253ea807ea6f9
#	ā””ā”€ā”€ā”€packages
#	    ā”œā”€ā”€ā”€aarch64-linux
#	    ā”‚   ā””ā”€ā”€ā”€default omitted (use '--all-systems' to show)
#	    ā”œā”€ā”€ā”€x86_64-darwin
#	    ā”‚   ā””ā”€ā”€ā”€default omitted (use '--all-systems' to show)
#	    ā””ā”€ā”€ā”€x86_64-linux 
#	        ā””ā”€ā”€ā”€**default**: package 'nsearch' 
#	

default is the name to put in (myFlake.packages.${system}.name or (throw ā€œPackage ā€˜nameā€™ not found in the flakeā€))
and imported it in configuration.nix:


imports =
			[ # Include the results of the hardware scan.
				./hardware-configuration.nix
				./nsearch.nix
		
			];

it works !!!

thanks for your help and sorry for your time.

THANKS :joy:

Haha thatā€™s interesting - it seems that you have flake enabled if you can run this command - if that is the case, then definitely using a complete /etc/nixos/flake.nix setup is the way to go.

But anyway itā€™s OK to start out like this. Get used to Nix in general, and at some point I assume youā€™d feel confident to switch your setupā€¦ Good luck !