Skip to content

Instantly share code, notes, and snippets.

@mausch
Created August 8, 2021 22:38
Show Gist options
  • Save mausch/2a68fb9814853e6b802b75fa876d9b0d to your computer and use it in GitHub Desktop.
Save mausch/2a68fb9814853e6b802b75fa876d9b0d to your computer and use it in GitHub Desktop.
WIP get nuget packages from packages.lock.json for nix
{ lockFile }:
let
pkgs = import <nixpkgs> {};
lib = pkgs.lib;
procLockFile =
lockFile:
let
# https://github.com/NuGet/NuGet.Client/blob/f24bad0668193ce21a1db8cabd1ce95ba509c7f0/src/NuGet.Core/NuGet.Packaging/PackageArchiveReader.cs#L431
# https://github.com/NuGet/NuGet.Client/blob/f24bad0668193ce21a1db8cabd1ce95ba509c7f0/src/NuGet.Core/NuGet.Packaging/PackageExtractor.cs#L487
# https://globalcdn.nuget.org/packages/newtonsoft.json.13.0.1.nupkg
procPackage = packageName: packageDef:
pkgs.fetchurl {
name = "${packageName}-${packageDef.resolved}";
url = "https://globalcdn.nuget.org/packages/${lib.toLower packageName}.${packageDef.resolved}.nupkg";
hash = "sha512-${packageDef.contentHash}";
};
procTargetFramework = targetFramework: frameworkPackages:
let
packages = lib.filterAttrs (_: (lib.hasAttr "contentHash")) frameworkPackages;
in lib.mapAttrsToList procPackage packages;
dependencies = (lib.importJSON lockFile).dependencies;
in
lib.mapAttrsToList procTargetFramework dependencies;
in
pkgs.writeText "TODO" (procLockFile lockFile)
@mausch
Copy link
Author

mausch commented Aug 8, 2021

nix build --verbose -L -f ~/prg/nixnuget.nix --arg lockFile ./packages.lock.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment