Nix Shell Custom Packages

OK, so the package you want isn’t in nixpkgs and you only know how to sudo apt install [package-name].

This is an example for Ubuntu/Debian .deb files, but it should apply to other platforms.

mssql-tools.nix

{ stdenv, fetchurl, dpkg }:

stdenv.mkDerivation rec {
  pname = "mssql-tools";
  version = "17.6.1.1-1";

  src = fetchurl {
    url = "https://packages.microsoft.com/ubuntu/20.04/prod/pool/main/m/mssql-tools/${pname}_${version}_amd64.deb";
    sha256 = "9e68a0f83ba7e770449e399b1513edc9826aa0c3a58e3d911ea982a362c6c41d";
  };

  nativeBuildInputs = [ dpkg ];

  dontUnpack = true;

  installPhase = ''
    runHook preInstall

    mkdir -p $out
    dpkg -x $src $out
    cp -av $out/opt/mssql-tools/* $out
    rm -rf $out/opt

    runHook postInstall
  '';

  meta = {
    platforms = [ "x86_64-linux" ];
  };
}

shell.nix

with import <nixpkgs> { };

mkShell {
  buildInputs = [
    dotnet-sdk_6
    openssl_1_1
    (callPackage ./mssql-tools.nix { })
  ];
}

Note that mssql-tools.nix should also be publishable to nixpkgs in a directory like pkgs/servers/sql/mssql/mssql-tools

Also, thank you to nix-tutorial for some good examples on how to get here.

·