From c38353c33c00bb4e3d3ac2b3f4c3e7843661d46e Mon Sep 17 00:00:00 2001 From: isabel Date: Wed, 19 Nov 2025 17:25:49 +0000 Subject: [PATCH] fp --- fetcher.nix | 182 +++++++++++++++++----------------------------------- flake.nix | 2 +- 2 files changed, 60 insertions(+), 124 deletions(-) diff --git a/fetcher.nix b/fetcher.nix index afb670d..dc0b8b1 100644 --- a/fetcher.nix +++ b/fetcher.nix @@ -4,146 +4,82 @@ { lib, - repoRevToNameMaybe, - fetchgit, - fetchzip, + fetchFromGitProvider, }: lib.makeOverridable ( - { - domain ? "tangled.org", - owner, - repo, - rev ? null, - tag ? null, - - # TODO: add back when doing FP - # name ? repoRevToNameMaybe repo (lib.revOrTag rev tag) "tangled", - - # fetchgit stuff - fetchSubmodules ? false, - leaveDotGit ? false, - deepClone ? false, - forceFetchGit ? false, - fetchLFS ? false, - sparseCheckout ? [ ], - - passthru ? { }, - meta ? { }, - ... - }@args: - - assert lib.assertMsg (lib.xor (tag != null) ( - rev != null - )) "fetchFromTangled requires one of either `rev` or `tag` to be provided (not both)."; - - let - - position = ( - if args.meta.description or null != null then - builtins.unsafeGetAttrPos "description" args.meta - else if tag != null then - builtins.unsafeGetAttrPos "tag" args - else - builtins.unsafeGetAttrPos "rev" args - ); - - baseUrl = "https://${domain}/${owner}/${repo}"; - - newMeta = - meta - // { - homepage = meta.homepage or baseUrl; - } - // lib.optionalAttrs (position != null) { - # to indicate where derivation originates, similar to make-derivation.nix's mkDerivation - position = "${position.file}:${toString position.line}"; - }; + lib.extendMkDerivation { + constructDrv = fetchFromGitProvider; - passthruAttrs = removeAttrs args [ + excludeDrvArgNames = [ "domain" "owner" - "repo" - "tag" - "rev" - "fetchSubmodules" - "forceFetchGit" + + "useFetchGit" ]; - useFetchGit = - fetchSubmodules || leaveDotGit || deepClone || forceFetchGit || fetchLFS || (sparseCheckout != [ ]); - - # We prefer fetchzip in cases we don't need submodules as the hash - # is more stable in that case. - fetcher = - if useFetchGit then - fetchgit - # fetchzip may not be overridable when using external tools, for example nix-prefetch - else if fetchzip ? override then - fetchzip.override { withUnzip = false; } - else - fetchzip; - - fetcherArgs = + extendDrvArgs = finalAttrs: - passthruAttrs - // ( - if useFetchGit then - { - inherit - tag - rev - deepClone - fetchSubmodules - sparseCheckout - fetchLFS - leaveDotGit - ; - url = baseUrl; - inherit passthru; - derivationArgs = { - inherit - domain - owner - repo - ; - }; + { + domain ? "tangled.org", + owner, + repo, + rev ? null, + tag ? null, + passthru ? { }, + meta ? { }, + ... + }@args: + + let + + position = ( + if args.meta.description or null != null then + builtins.unsafeGetAttrPos "description" args.meta + else if tag != null then + builtins.unsafeGetAttrPos "tag" args + else + builtins.unsafeGetAttrPos "rev" args + ); + + baseUrl = "https://${domain}/${owner}/${repo}"; + + newMeta = + meta + // { + homepage = meta.homepage or baseUrl; } - else + // lib.optionalAttrs (position != null) { + # to indicate where derivation originates, similar to make-derivation.nix's mkDerivation + position = "${position.file}:${toString position.line}"; + }; + + in + + { + providerName = "tangled"; + + derivationArgs = { + inherit + domain + owner + ; + }; + + inherit repo; + + gitRepoUrl = baseUrl; + + fetchZipArgs = let revWithTag = finalAttrs.rev; in { url = "${baseUrl}/archive/${revWithTag}"; extension = "tar.gz"; + }; - derivationArgs = { - inherit - domain - owner - repo - tag - ; - rev = fetchgit.getRevWithTag { - inherit (finalAttrs) tag; - rev = finalAttrs.revCustom; - }; - revCustom = rev; - }; - - passthru = { - gitRepoUrl = baseUrl; - } - // passthru; - } - ) - // { - name = - args.name - or (repoRevToNameMaybe finalAttrs.repo (lib.revOrTag finalAttrs.revCustom finalAttrs.tag) "github"); meta = newMeta; }; - in - - fetcher fetcherArgs + } ) diff --git a/flake.nix b/flake.nix index ed6a2df..b2561ec 100644 --- a/flake.nix +++ b/flake.nix @@ -1,6 +1,6 @@ { inputs = { - nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + nixpkgs.url = "github:nixos/nixpkgs/pull/462034/head"; }; outputs = -- 2.51.2