Created
August 8, 2021 22:38
-
-
Save mausch/2a68fb9814853e6b802b75fa876d9b0d to your computer and use it in GitHub Desktop.
WIP get nuget packages from packages.lock.json for nix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ 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) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nix build --verbose -L -f ~/prg/nixnuget.nix --arg lockFile ./packages.lock.json