WIP #1

open
opened by isabelroses.com targeting main from fp
Changed files
+117 -103
+117 -103
fetcher.nix
··· 10 10 { 11 11 lib, 12 12 repoRevToNameMaybe, 13 + stdenvNoCC, 13 14 fetchgit, 14 15 fetchzip, 15 16 }: 16 17 17 18 lib.makeOverridable ( 18 - { 19 - domain ? "tangled.sh", 20 - owner, 21 - repo, 22 - rev ? null, 23 - tag ? null, 24 - name ? repoRevToNameMaybe repo (lib.revOrTag rev tag) "tangled", 25 - 26 - # fetchgit stuff 27 - fetchSubmodules ? false, 28 - leaveDotGit ? false, 29 - deepClone ? false, 30 - forceFetchGit ? false, 31 - fetchLFS ? false, 32 - sparseCheckout ? [ ], 33 - 34 - meta ? { }, 35 - ... 36 - }@args: 37 - 38 - assert lib.assertMsg (lib.xor (tag != null) ( 39 - rev != null 40 - )) "fetchFromTangled requires one of either `rev` or `tag` to be provided (not both)."; 41 - 42 - let 43 - 44 - position = ( 45 - if args.meta.description or null != null then 46 - builtins.unsafeGetAttrPos "description" args.meta 47 - else if tag != null then 48 - builtins.unsafeGetAttrPos "tag" args 49 - else 50 - builtins.unsafeGetAttrPos "rev" args 51 - ); 52 - 53 - baseUrl = "https://${domain}/${owner}/${repo}"; 54 - 55 - newMeta = 56 - meta 57 - // { 58 - homepage = meta.homepage or baseUrl; 59 - } 60 - // lib.optionalAttrs (position != null) { 61 - # to indicate where derivation originates, similar to make-derivation.nix's mkDerivation 62 - position = "${position.file}:${toString position.line}"; 63 - }; 19 + lib.extendMkDerivation { 20 + constructDrv = stdenvNoCC.mkDerivation; 21 + 22 + excludeDrvArgNames = [ 23 + # Additional stdenv.mkDerivation arguments from derived fetchers. 24 + "derivationArgs" 64 25 65 - passthruAttrs = removeAttrs args [ 66 - "domain" 67 - "owner" 68 - "repo" 69 - "tag" 70 - "rev" 71 - "fetchSubmodules" 72 - "forceFetchGit" 26 + "hash" 73 27 ]; 74 28 75 - useFetchGit = 76 - fetchSubmodules || leaveDotGit || deepClone || forceFetchGit || fetchLFS || (sparseCheckout != [ ]); 77 - 78 - # We prefer fetchzip in cases we don't need submodules as the hash 79 - # is more stable in that case. 80 - fetcher = 81 - if useFetchGit then 82 - fetchgit 83 - # fetchzip may not be overridable when using external tools, for example nix-prefetch 84 - else if fetchzip ? override then 85 - fetchzip.override { withUnzip = false; } 86 - else 87 - fetchzip; 88 - 89 - revWithTag = if tag != null then "refs%2Ftags%2F${tag}" else rev; 90 - 91 - fetcherArgs = 92 - ( 93 - if useFetchGit then 94 - { 95 - inherit 96 - tag 97 - rev 98 - deepClone 99 - fetchSubmodules 100 - sparseCheckout 101 - fetchLFS 102 - leaveDotGit 103 - ; 104 - url = baseUrl; 29 + extendDrvArgs = 30 + finalAttrs: 31 + { 32 + domain ? "tangled.sh", 33 + owner, 34 + repo, 35 + rev ? null, 36 + tag ? null, 37 + name ? repoRevToNameMaybe repo (lib.revOrTag rev tag) "tangled", 38 + 39 + # fetchgit stuff 40 + fetchSubmodules ? false, 41 + leaveDotGit ? false, 42 + deepClone ? false, 43 + forceFetchGit ? false, 44 + fetchLFS ? false, 45 + sparseCheckout ? [ ], 46 + 47 + meta ? { }, 48 + ... 49 + }@args: 50 + 51 + assert lib.assertMsg (lib.xor (tag != null) ( 52 + rev != null 53 + )) "fetchFromTangled requires one of either `rev` or `tag` to be provided (not both)."; 54 + 55 + let 56 + 57 + position = ( 58 + if args.meta.description or null != null then 59 + builtins.unsafeGetAttrPos "description" args.meta 60 + else if tag != null then 61 + builtins.unsafeGetAttrPos "tag" args 62 + else 63 + builtins.unsafeGetAttrPos "rev" args 64 + ); 65 + 66 + baseUrl = "https://${domain}/${owner}/${repo}"; 67 + 68 + newMeta = 69 + meta 70 + // { 71 + homepage = meta.homepage or baseUrl; 105 72 } 106 - else 107 - { 108 - url = "${baseUrl}/archive/${revWithTag}"; 109 - extension = "tar.gz"; 110 - 111 - passthru = { 112 - gitRepoUrl = baseUrl; 113 - }; 114 - } 115 - ) 116 - // passthruAttrs 73 + // lib.optionalAttrs (position != null) { 74 + # to indicate where derivation originates, similar to make-derivation.nix's mkDerivation 75 + position = "${position.file}:${toString position.line}"; 76 + }; 77 + 78 + passthruAttrs = removeAttrs args [ 79 + "domain" 80 + "owner" 81 + "repo" 82 + "tag" 83 + "rev" 84 + "fetchSubmodules" 85 + "forceFetchGit" 86 + ]; 87 + 88 + useFetchGit = 89 + fetchSubmodules || leaveDotGit || deepClone || forceFetchGit || fetchLFS || (sparseCheckout != [ ]); 90 + 91 + # We prefer fetchzip in cases we don't need submodules as the hash 92 + # is more stable in that case. 93 + fetcher = 94 + if useFetchGit then 95 + fetchgit 96 + # fetchzip may not be overridable when using external tools, for example nix-prefetch 97 + else if fetchzip ? override then 98 + fetchzip.override { withUnzip = false; } 99 + else 100 + fetchzip; 101 + 102 + revWithTag = if tag != null then "refs%2Ftags%2F${tag}" else rev; 103 + 104 + fetcherArgs = 105 + ( 106 + if useFetchGit then 107 + { 108 + inherit 109 + tag 110 + rev 111 + deepClone 112 + fetchSubmodules 113 + sparseCheckout 114 + fetchLFS 115 + leaveDotGit 116 + ; 117 + url = baseUrl; 118 + } 119 + else 120 + { 121 + url = "${baseUrl}/archive/${revWithTag}"; 122 + extension = "tar.gz"; 123 + 124 + passthru = { 125 + gitRepoUrl = baseUrl; 126 + }; 127 + } 128 + ) 129 + // passthruAttrs 130 + // { 131 + inherit name; 132 + }; 133 + in 134 + 135 + fetcher fetcherArgs 117 136 // { 118 - inherit name; 137 + meta = newMeta; 138 + inherit owner repo tag; 139 + rev = revWithTag; 119 140 }; 120 - in 121 - 122 - fetcher fetcherArgs 123 - // { 124 - meta = newMeta; 125 - inherit owner repo tag; 126 - rev = revWithTag; 127 141 } 128 142 )