buildNimPackage: load lockfiles and overrides

+361 -111
+83 -53
doc/languages-frameworks/nim.section.md
··· 1 1 # Nim {#nim} 2 2 3 - ## Overview {#nim-overview} 4 - 5 - The Nim compiler, a builder function, and some packaged libraries are available 6 - in Nixpkgs. Until now each compiler release has been effectively backwards 7 - compatible so only the latest version is available. 8 - 9 - ## Nim program packages in Nixpkgs {#nim-program-packages-in-nixpkgs} 10 - 11 - Nim programs can be built using `nimPackages.buildNimPackage`. In the 12 - case of packages not containing exported library code the attribute 13 - `nimBinOnly` should be set to `true`. 3 + The Nim compiler and a builder function is available. 4 + Nim programs are built using `buildNimPackage` and a lockfile containing Nim dependencies. 14 5 15 6 The following example shows a Nim program that depends only on Nim libraries: 16 - 17 7 ```nix 18 - { lib, nimPackages, fetchFromGitHub }: 8 + { lib, buildNimPackage, fetchFromGitHub }: 19 9 20 - nimPackages.buildNimPackage (finalAttrs: { 10 + buildNimPackage { } (finalAttrs: { 21 11 pname = "ttop"; 22 - version = "1.0.1"; 23 - nimBinOnly = true; 12 + version = "1.2.7"; 24 13 25 14 src = fetchFromGitHub { 26 15 owner = "inv2004"; 27 16 repo = "ttop"; 28 17 rev = "v${finalAttrs.version}"; 29 - hash = "sha256-x4Uczksh6p3XX/IMrOFtBxIleVHdAPX9e8n32VAUTC4="; 18 + hash = "sha256-oPdaUqh6eN1X5kAYVvevOndkB/xnQng9QVLX9bu5P5E="; 30 19 }; 31 20 32 - buildInputs = with nimPackages; [ asciigraph illwill parsetoml zippy ]; 33 - 34 - }) 35 - ``` 36 - 37 - ## Nim library packages in Nixpkgs {#nim-library-packages-in-nixpkgs} 38 - 39 - 40 - Nim libraries can also be built using `nimPackages.buildNimPackage`, but 41 - often the product of a fetcher is sufficient to satisfy a dependency. 42 - The `fetchgit`, `fetchFromGitHub`, and `fetchNimble` functions yield an 43 - output that can be discovered during the `configurePhase` of `buildNimPackage`. 21 + lockFile = ./lock.json; 44 22 45 - Nim library packages are listed in 46 - [pkgs/top-level/nim-packages.nix](https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/nim-packages.nix) and implemented at 47 - [pkgs/development/nim-packages](https://github.com/NixOS/nixpkgs/tree/master/pkgs/development/nim-packages). 48 - 49 - The following example shows a Nim library that propagates a dependency on a 50 - non-Nim package: 51 - ```nix 52 - { lib, buildNimPackage, fetchNimble, SDL2 }: 53 - 54 - buildNimPackage (finalAttrs: { 55 - pname = "sdl2"; 56 - version = "2.0.4"; 57 - src = fetchNimble { 58 - inherit (finalAttrs) pname version; 59 - hash = "sha256-Vtcj8goI4zZPQs2TbFoBFlcR5UqDtOldaXSH/+/xULk="; 60 - }; 61 - propagatedBuildInputs = [ SDL2 ]; 23 + nimFlags = [ 24 + "-d:NimblePkgVersion=${finalAttrs.version}" 25 + ]; 62 26 }) 63 27 ``` 64 28 65 29 ## `buildNimPackage` parameters {#buildnimpackage-parameters} 66 30 67 - All parameters from `stdenv.mkDerivation` function are still supported. The 68 - following are specific to `buildNimPackage`: 31 + The `buildNimPackage` function takes an attrset of parameters that are passed on to `stdenv.mkDerivation`. 32 + 33 + The following parameters are specific to `buildNimPackage`: 69 34 70 - * `nimBinOnly ? false`: If `true` then build only the programs listed in 71 - the Nimble file in the packages sources. 35 + * `lockFile`: JSON formatted lockfile. 72 36 * `nimbleFile`: Specify the Nimble file location of the package being built 73 37 rather than discover the file at build-time. 74 38 * `nimRelease ? true`: Build the package in *release* mode. ··· 77 41 Use this to specify defines with arguments in the form of `-d:${name}=${value}`. 78 42 * `nimDoc` ? false`: Build and install HTML documentation. 79 43 80 - * `buildInputs` ? []: The packages listed here will be searched for `*.nimble` 81 - files which are used to populate the Nim library path. Otherwise the standard 82 - behavior is in effect. 44 + ## Lockfiles {#nim-lockfiles} 45 + Nim lockfiles are created with the `nim_lk` utility. 46 + Run `nim_lk` with the source directory as an argument and it will print a lockfile to stdout. 47 + ```sh 48 + $ cd nixpkgs 49 + $ nix build -f . ttop.src 50 + $ nix run -f . nim_lk ./result | jq --sort-keys > pkgs/by-name/tt/ttop/lock.json 51 + ``` 52 + 53 + ## Lockfile dependency overrides {#nimoverrides} 54 + 55 + The `buildNimPackage` function matches the libraries specified by `lockFile` to attrset of override functions that are then applied to the package derivation. 56 + The default overrides are maintained as the top-level `nimOverrides` attrset at `pkgs/top-level/nim-overrides.nix`. 57 + 58 + For example, to propagate a dependency on SDL2 for lockfiles that select the Nim `sdl2` library, an overlay is added to the set in the `nim-overrides.nix` file: 59 + ```nix 60 + { lib 61 + /* … */ 62 + , SDL2 63 + /* … */ 64 + }: 65 + 66 + { 67 + /* … */ 68 + sdl2 = 69 + lockAttrs: 70 + finalAttrs: 71 + { buildInputs ? [ ], ... }: 72 + { 73 + buildInputs = buildInputs ++ [ SDL2 ]; 74 + }; 75 + /* … */ 76 + } 77 + ``` 78 + 79 + The annotations in the `nim-overrides.nix` set are functions that take three arguments and return a new attrset to be overlayed on the package being built. 80 + - lockAttrs: the attrset for this library from within a lockfile. This can be used to implement library version constraints, such as marking libraries as broken or insecure. 81 + - finalAttrs: the final attrset passed by `buildNimPackage` to `stdenv.mkDerivation`. 82 + - prevAttrs: the attrset produced by initial arguments to `buildNimPackage` and any preceding lockfile overlays. 83 + 84 + ### Overriding an Nim library override {#nimoverrides-overrides} 85 + 86 + The `nimOverrides` attrset makes it possible to modify overrides in a few different ways. 87 + 88 + Override a package internal to its definition: 89 + ```nix 90 + { lib, buildNimPackage, nimOverrides, libressl }: 91 + 92 + let 93 + buildNimPackage' = buildNimPackage.override { 94 + nimOverrides = nimOverrides.override { openssl = libressl; }; 95 + }; 96 + in buildNimPackage' (finalAttrs: { 97 + pname = "foo"; 98 + # … 99 + }) 100 + 101 + ``` 102 + 103 + Override a package externally: 104 + ```nix 105 + { pkgs }: { 106 + foo = pkgs.foo.override { 107 + buildNimPackage = pkgs.buildNimPackage.override { 108 + nimOverrides = pkgs.nimOverrides.override { openssl = libressl; }; 109 + }; 110 + }; 111 + } 112 + ```
+136 -1
pkgs/by-name/ho/hottext/lock.json
··· 1 - {"depends":[{"method":"fetchzip","path":"/nix/store/vx0a8hw7hs5an0dnbrn6l16bd6is7hdr-source","rev":"07f6ba8ab96238e5bd1264cf0cea1d1746abb00c","sha256":"005nrldaasfl09zdsni1vi8s7dk0y85ijv6rm2wpj94435x66s36","url":"https://github.com/treeform/flatty/archive/07f6ba8ab96238e5bd1264cf0cea1d1746abb00c.tar.gz","ref":"0.3.4","packages":["flatty"],"srcDir":"src"},{"method":"fetchzip","path":"/nix/store/lk4hcmvwvliliyyidx7k3fk9yfijddc5-source","rev":"b2e71179174e040884ebf6a16cbac711c84620b9","sha256":"0pi6cq43ysm1wy5vva3i2dqvyh4dqppjjjl04yj9wfq7mngpqaa1","url":"https://github.com/treeform/chroma/archive/b2e71179174e040884ebf6a16cbac711c84620b9.tar.gz","ref":"0.2.7","packages":["chroma"],"srcDir":"src"},{"method":"fetchzip","path":"/nix/store/bah1zq369ikykm6dz3r0hzhcq4s88sxq-source","rev":"a2a5165c36e0098dea526712890fb7e988ba27f2","sha256":"0n42hlvh0d9wkjr01p04jnkyn7y4y62pwjdcqw52absapbpsr1lb","url":"https://github.com/treeform/typography/archive/a2a5165c36e0098dea526712890fb7e988ba27f2.tar.gz","ref":"0.7.14","packages":["typography"],"srcDir":"src"},{"method":"fetchzip","path":"/nix/store/9hfg3703m28w76ics7rn0hw1qymz0jrh-source","rev":"156e424306756a106442aca985eed61a8d12097b","sha256":"0hg9iq509rjsgd33cp3452v7whgbc30b5lnajifkls0z66rc2ndh","url":"https://github.com/guzba/nimsimd/archive/156e424306756a106442aca985eed61a8d12097b.tar.gz","ref":"1.2.6","packages":["nimsimd"],"srcDir":"src"},{"method":"fetchzip","path":"/nix/store/xjk8cg4dmja48rcswy0nphy3xhmf7nsz-source","rev":"f3e73f722fbb0e5d496fbc59ee860a9fd49983de","sha256":"12mqlczckhxcrg6il213fn7mcnqz3khwkh7i4bn57l55nzrhfvrh","url":"https://github.com/treeform/pixie/archive/f3e73f722fbb0e5d496fbc59ee860a9fd49983de.tar.gz","ref":"5.0.6","packages":["pixie"],"srcDir":"src"},{"method":"fetchzip","path":"/nix/store/f9dp6njaay5rf32f6l9gkw0dm25gim47-source","rev":"7282ae1247f2f384ebeaec3826d7fa38fd0e1df1","sha256":"1plw9lfrm42qar01rnjhm0d9mkzsc7c3b8kz43w5pb8j8drx1lyn","url":"https://github.com/treeform/vmath/archive/7282ae1247f2f384ebeaec3826d7fa38fd0e1df1.tar.gz","ref":"2.0.0","packages":["vmath"],"srcDir":"src"},{"method":"fetchzip","path":"/nix/store/16h19n8ndv42v8gn2vfdisdszv2wrln1-source","rev":"fb09637d6ebd6416b322a2b9bb95dd513040dea7","sha256":"1lyfnirwpy12lq9gr0sbnkf7ih7ayfvb1acjxk2z5gzlgxm1azp1","url":"https://github.com/treeform/print/archive/fb09637d6ebd6416b322a2b9bb95dd513040dea7.tar.gz","ref":"1.0.2","packages":["print"],"srcDir":"src"},{"method":"fetchzip","path":"/nix/store/zrm3y895iwn057y5c4374bviih962w0v-source","rev":"d0c9ad33ae72aece49093d7688fc78a7101aa4b0","sha256":"14qgxcnyznjc180kdbilqzzya589rqaznfpp75yp37n47zdknfw0","url":"https://github.com/guzba/crunchy/archive/d0c9ad33ae72aece49093d7688fc78a7101aa4b0.tar.gz","ref":"0.1.9","packages":["crunchy"],"srcDir":"src"},{"method":"fetchzip","path":"/nix/store/da49jl6rhz6jlix6mds0alhlbq1qlkfy-source","rev":"84d4702e838d684b7304882ffe796f57ef422fb6","sha256":"1vilid9xx5mp2yvssa3wf6g9svqdan87090klis891k9w1dd8i51","url":"https://github.com/nim-lang/sdl2/archive/84d4702e838d684b7304882ffe796f57ef422fb6.tar.gz","ref":"v2.0.5","packages":["sdl2"],"srcDir":"src"},{"method":"fetchzip","path":"/nix/store/rpa0bv740i3yagp0ldkb68jp6scw4i5l-source","rev":"d7eaf00c24820ad0317c9926737402e62431e931","sha256":"0wrvdpvbwv4ysjsqc6hhvd97vql4k0m5l0zdrsrjlljd1n5g2haq","url":"https://github.com/treeform/bumpy/archive/d7eaf00c24820ad0317c9926737402e62431e931.tar.gz","ref":"1.1.2","packages":["bumpy"],"srcDir":"src"},{"method":"fetchzip","path":"/nix/store/b98qlpki45417ws4pmjq052q1s7333wc-source","rev":"a3fd6f0458ffdd7cbbd416be99f2ca80a7852d82","sha256":"0zmavr2jnyyqkvvi6hlg2kh6qv6lzakwvsqjy0sjm3qdsna0aldg","url":"https://github.com/guzba/zippy/archive/a3fd6f0458ffdd7cbbd416be99f2ca80a7852d82.tar.gz","ref":"0.10.10","packages":["zippy"],"srcDir":"src"}]} 1 + { 2 + "depends": [ 3 + { 4 + "method": "fetchzip", 5 + "packages": [ 6 + "flatty" 7 + ], 8 + "path": "/nix/store/vx0a8hw7hs5an0dnbrn6l16bd6is7hdr-source", 9 + "ref": "0.3.4", 10 + "rev": "07f6ba8ab96238e5bd1264cf0cea1d1746abb00c", 11 + "sha256": "005nrldaasfl09zdsni1vi8s7dk0y85ijv6rm2wpj94435x66s36", 12 + "srcDir": "src", 13 + "url": "https://github.com/treeform/flatty/archive/07f6ba8ab96238e5bd1264cf0cea1d1746abb00c.tar.gz" 14 + }, 15 + { 16 + "method": "fetchzip", 17 + "packages": [ 18 + "chroma" 19 + ], 20 + "path": "/nix/store/lk4hcmvwvliliyyidx7k3fk9yfijddc5-source", 21 + "ref": "0.2.7", 22 + "rev": "b2e71179174e040884ebf6a16cbac711c84620b9", 23 + "sha256": "0pi6cq43ysm1wy5vva3i2dqvyh4dqppjjjl04yj9wfq7mngpqaa1", 24 + "srcDir": "src", 25 + "url": "https://github.com/treeform/chroma/archive/b2e71179174e040884ebf6a16cbac711c84620b9.tar.gz" 26 + }, 27 + { 28 + "method": "fetchzip", 29 + "packages": [ 30 + "typography" 31 + ], 32 + "path": "/nix/store/bah1zq369ikykm6dz3r0hzhcq4s88sxq-source", 33 + "ref": "0.7.14", 34 + "rev": "a2a5165c36e0098dea526712890fb7e988ba27f2", 35 + "sha256": "0n42hlvh0d9wkjr01p04jnkyn7y4y62pwjdcqw52absapbpsr1lb", 36 + "srcDir": "src", 37 + "url": "https://github.com/treeform/typography/archive/a2a5165c36e0098dea526712890fb7e988ba27f2.tar.gz" 38 + }, 39 + { 40 + "method": "fetchzip", 41 + "packages": [ 42 + "nimsimd" 43 + ], 44 + "path": "/nix/store/9hfg3703m28w76ics7rn0hw1qymz0jrh-source", 45 + "ref": "1.2.6", 46 + "rev": "156e424306756a106442aca985eed61a8d12097b", 47 + "sha256": "0hg9iq509rjsgd33cp3452v7whgbc30b5lnajifkls0z66rc2ndh", 48 + "srcDir": "src", 49 + "url": "https://github.com/guzba/nimsimd/archive/156e424306756a106442aca985eed61a8d12097b.tar.gz" 50 + }, 51 + { 52 + "method": "fetchzip", 53 + "packages": [ 54 + "pixie" 55 + ], 56 + "path": "/nix/store/xjk8cg4dmja48rcswy0nphy3xhmf7nsz-source", 57 + "ref": "5.0.6", 58 + "rev": "f3e73f722fbb0e5d496fbc59ee860a9fd49983de", 59 + "sha256": "12mqlczckhxcrg6il213fn7mcnqz3khwkh7i4bn57l55nzrhfvrh", 60 + "srcDir": "src", 61 + "url": "https://github.com/treeform/pixie/archive/f3e73f722fbb0e5d496fbc59ee860a9fd49983de.tar.gz" 62 + }, 63 + { 64 + "method": "fetchzip", 65 + "packages": [ 66 + "vmath" 67 + ], 68 + "path": "/nix/store/f9dp6njaay5rf32f6l9gkw0dm25gim47-source", 69 + "ref": "2.0.0", 70 + "rev": "7282ae1247f2f384ebeaec3826d7fa38fd0e1df1", 71 + "sha256": "1plw9lfrm42qar01rnjhm0d9mkzsc7c3b8kz43w5pb8j8drx1lyn", 72 + "srcDir": "src", 73 + "url": "https://github.com/treeform/vmath/archive/7282ae1247f2f384ebeaec3826d7fa38fd0e1df1.tar.gz" 74 + }, 75 + { 76 + "method": "fetchzip", 77 + "packages": [ 78 + "print" 79 + ], 80 + "path": "/nix/store/16h19n8ndv42v8gn2vfdisdszv2wrln1-source", 81 + "ref": "1.0.2", 82 + "rev": "fb09637d6ebd6416b322a2b9bb95dd513040dea7", 83 + "sha256": "1lyfnirwpy12lq9gr0sbnkf7ih7ayfvb1acjxk2z5gzlgxm1azp1", 84 + "srcDir": "src", 85 + "url": "https://github.com/treeform/print/archive/fb09637d6ebd6416b322a2b9bb95dd513040dea7.tar.gz" 86 + }, 87 + { 88 + "method": "fetchzip", 89 + "packages": [ 90 + "crunchy" 91 + ], 92 + "path": "/nix/store/zrm3y895iwn057y5c4374bviih962w0v-source", 93 + "ref": "0.1.9", 94 + "rev": "d0c9ad33ae72aece49093d7688fc78a7101aa4b0", 95 + "sha256": "14qgxcnyznjc180kdbilqzzya589rqaznfpp75yp37n47zdknfw0", 96 + "srcDir": "src", 97 + "url": "https://github.com/guzba/crunchy/archive/d0c9ad33ae72aece49093d7688fc78a7101aa4b0.tar.gz" 98 + }, 99 + { 100 + "method": "fetchzip", 101 + "packages": [ 102 + "sdl2" 103 + ], 104 + "path": "/nix/store/da49jl6rhz6jlix6mds0alhlbq1qlkfy-source", 105 + "ref": "v2.0.5", 106 + "rev": "84d4702e838d684b7304882ffe796f57ef422fb6", 107 + "sha256": "1vilid9xx5mp2yvssa3wf6g9svqdan87090klis891k9w1dd8i51", 108 + "srcDir": "src", 109 + "url": "https://github.com/nim-lang/sdl2/archive/84d4702e838d684b7304882ffe796f57ef422fb6.tar.gz" 110 + }, 111 + { 112 + "method": "fetchzip", 113 + "packages": [ 114 + "bumpy" 115 + ], 116 + "path": "/nix/store/rpa0bv740i3yagp0ldkb68jp6scw4i5l-source", 117 + "ref": "1.1.2", 118 + "rev": "d7eaf00c24820ad0317c9926737402e62431e931", 119 + "sha256": "0wrvdpvbwv4ysjsqc6hhvd97vql4k0m5l0zdrsrjlljd1n5g2haq", 120 + "srcDir": "src", 121 + "url": "https://github.com/treeform/bumpy/archive/d7eaf00c24820ad0317c9926737402e62431e931.tar.gz" 122 + }, 123 + { 124 + "method": "fetchzip", 125 + "packages": [ 126 + "zippy" 127 + ], 128 + "path": "/nix/store/b98qlpki45417ws4pmjq052q1s7333wc-source", 129 + "ref": "0.10.10", 130 + "rev": "a3fd6f0458ffdd7cbbd416be99f2ca80a7852d82", 131 + "sha256": "0zmavr2jnyyqkvvi6hlg2kh6qv6lzakwvsqjy0sjm3qdsna0aldg", 132 + "srcDir": "src", 133 + "url": "https://github.com/guzba/zippy/archive/a3fd6f0458ffdd7cbbd416be99f2ca80a7852d82.tar.gz" 134 + } 135 + ] 136 + }
+3 -7
pkgs/by-name/ho/hottext/package.nix
··· 1 - { lib, nim2Packages, fetchFromSourcehut, gentium, makeDesktopItem, nim_lk, SDL2 }: 1 + { lib, buildNimPackage, fetchFromSourcehut, gentium, makeDesktopItem }: 2 2 3 - nim2Packages.buildNimPackage (finalAttrs: { 3 + buildNimPackage (finalAttrs: { 4 4 pname = "hottext"; 5 5 version = "20231003"; 6 6 7 - nimBinOnly = true; 8 - 9 7 src = fetchFromSourcehut { 10 8 owner = "~ehmry"; 11 9 repo = "hottext"; ··· 13 11 hash = "sha256-ncH/1PV4vZY7JCUJ87FPz5bdrQsNlYxzGdc5BQNfQeA="; 14 12 }; 15 13 16 - buildInputs = [ SDL2 ]; 17 - 18 - nimFlags = nim_lk.passthru.nimFlagsFromLockFile ./lock.json; 14 + lockFile = ./lock.json; 19 15 20 16 HOTTEXT_FONT_PATH = "${gentium}/share/fonts/truetype/GentiumPlus-Regular.ttf"; 21 17
+2 -2
pkgs/by-name/ni/nim_builder/nim_builder.nim
··· 133 133 if err != 0: quit("build phase failed", err) 134 134 135 135 proc installPhase*() = 136 - ## Install the Nim sources if ``nimBinOnly`` is not 136 + ## Install the Nim sources if ``nimCopySources`` is 137 137 ## set in the environment. 138 - if not getEnvBool"nimBinOnly": 138 + if getEnvBool"nimCopySources": 139 139 let 140 140 nf = getNimbleFilePath() 141 141 srcDir = nf.getNimbleValue("srcDir", ".")
+28 -1
pkgs/by-name/ni/nim_lk/lock.json
··· 1 - {"depends":[{"method":"fetchzip","packages":["npeg"],"path":"/nix/store/ffkxmjmigfs7zhhiiqm0iw2c34smyciy-source","ref":"1.2.1","rev":"26d62fdc40feb84c6533956dc11d5ee9ea9b6c09","sha256":"0xpzifjkfp49w76qmaylan8q181bs45anmp46l4bwr3lkrr7bpwh","srcDir":"src","url":"https://github.com/zevv/npeg/archive/26d62fdc40feb84c6533956dc11d5ee9ea9b6c09.tar.gz"},{"method":"fetchzip","packages":["preserves"],"path":"/nix/store/nrcpzf9hx70kry3gwhrdzcs3qicjncjh-source","ref":"20231021","rev":"edece399be70818208bf2263c30cb2bcf435bbff","sha256":"0xmw35wmw3a4lja9q4qvlvpxv3xk0hnkjg4fwfw6f3inh6zfiqki","srcDir":"src","url":"https://git.syndicate-lang.org/ehmry/preserves-nim/archive/edece399be70818208bf2263c30cb2bcf435bbff.tar.gz"}]} 1 + { 2 + "depends": [ 3 + { 4 + "method": "fetchzip", 5 + "packages": [ 6 + "npeg" 7 + ], 8 + "path": "/nix/store/ffkxmjmigfs7zhhiiqm0iw2c34smyciy-source", 9 + "ref": "1.2.1", 10 + "rev": "26d62fdc40feb84c6533956dc11d5ee9ea9b6c09", 11 + "sha256": "0xpzifjkfp49w76qmaylan8q181bs45anmp46l4bwr3lkrr7bpwh", 12 + "srcDir": "src", 13 + "url": "https://github.com/zevv/npeg/archive/26d62fdc40feb84c6533956dc11d5ee9ea9b6c09.tar.gz" 14 + }, 15 + { 16 + "method": "fetchzip", 17 + "packages": [ 18 + "preserves" 19 + ], 20 + "path": "/nix/store/nrcpzf9hx70kry3gwhrdzcs3qicjncjh-source", 21 + "ref": "20231021", 22 + "rev": "edece399be70818208bf2263c30cb2bcf435bbff", 23 + "sha256": "0xmw35wmw3a4lja9q4qvlvpxv3xk0hnkjg4fwfw6f3inh6zfiqki", 24 + "srcDir": "src", 25 + "url": "https://git.syndicate-lang.org/ehmry/preserves-nim/archive/edece399be70818208bf2263c30cb2bcf435bbff.tar.gz" 26 + } 27 + ] 28 + }
+9 -29
pkgs/by-name/ni/nim_lk/package.nix
··· 1 - { lib, buildPackages, nim2Packages, fetchFromSourcehut, openssl }: 1 + { lib, buildNimPackage, fetchFromSourcehut, nim, openssl, makeWrapper }: 2 2 3 - nim2Packages.buildNimPackage (finalAttrs: { 3 + buildNimPackage (finalAttrs: { 4 4 pname = "nim_lk"; 5 5 version = "20231031"; 6 - nimBinOnly = true; 7 6 8 7 src = fetchFromSourcehut { 9 8 owner = "~ehmry"; ··· 13 12 }; 14 13 15 14 buildInputs = [ openssl ]; 15 + nativeBuildInputs = [ makeWrapper ]; 16 16 17 - nimFlags = finalAttrs.passthru.nimFlagsFromLockFile ./lock.json; 17 + lockFile = ./lock.json; 18 + 19 + postFixup = '' 20 + wrapProgram $out/bin/nim_lk \ 21 + --suffix PATH : ${lib.makeBinPath [ nim ]} 22 + ''; 18 23 19 24 meta = finalAttrs.src.meta // { 20 25 description = "Generate Nix specific lock files for Nim packages"; ··· 24 29 platforms = lib.platforms.unix; 25 30 maintainers = with lib.maintainers; [ ehmry ]; 26 31 }; 27 - 28 - passthru.nimFlagsFromLockFile = let 29 - fetchDependency = let 30 - methods = { 31 - fetchzip = { url, sha256, ... }: 32 - buildPackages.fetchzip { 33 - name = "source"; 34 - inherit url sha256; 35 - }; 36 - git = { fetchSubmodules, leaveDotGit, rev, sha256, url, ... }: 37 - buildPackages.fetchgit { 38 - inherit fetchSubmodules leaveDotGit rev sha256 url; 39 - }; 40 - }; 41 - in attrs@{ method, ... }: methods.${method} attrs // attrs; 42 - in lockFile: 43 - with builtins; 44 - lib.pipe lockFile [ 45 - readFile 46 - fromJSON 47 - (getAttr "depends") 48 - (map fetchDependency) 49 - (map ({ outPath, srcDir, ... }: ''--path:"${outPath}/${srcDir}"'')) 50 - ]; 51 - 52 32 })
+82 -17
pkgs/development/compilers/nim/build-nim-package.nix
··· 1 - { lib, stdenv, nim1, nim2, nim_builder, defaultNimVersion ? 2 }: 2 - pkgArgs: 1 + { lib 2 + , buildPackages 3 + , callPackage 4 + , stdenv 5 + , nim1 6 + , nim2 7 + , nim_builder 8 + , defaultNimVersion ? 2 9 + , nimOverrides 10 + }: 3 11 4 12 let 5 13 baseAttrs = { ··· 30 38 meta = { inherit (nim2.meta) maintainers platforms; }; 31 39 }; 32 40 33 - inputsOverride = { depsBuildBuild ? [ ], nativeBuildInputs ? [ ] 34 - , requiredNimVersion ? defaultNimVersion, ... }: 35 - (if requiredNimVersion == 1 then { 36 - nativeBuildInputs = [ nim1 ] ++ nativeBuildInputs; 37 - } else if requiredNimVersion == 2 then { 38 - nativeBuildInputs = [ nim2 ] ++ nativeBuildInputs; 39 - } else 40 - throw "requiredNimVersion ${toString requiredNimVersion} is not valid") 41 - // { 42 - depsBuildBuild = [ nim_builder ] ++ depsBuildBuild; 43 - }; 41 + fodFromLockEntry = 42 + let 43 + methods = { 44 + fetchzip = { url, sha256, ... }: 45 + buildPackages.fetchzip { 46 + name = "source"; 47 + inherit url sha256; 48 + }; 49 + git = { fetchSubmodules, leaveDotGit, rev, sha256, url, ... }: 50 + buildPackages.fetchgit { 51 + inherit fetchSubmodules leaveDotGit rev sha256 url; 52 + }; 53 + }; 54 + in 55 + attrs@{ method, ... }: 56 + let fod = methods.${method} attrs; 57 + in ''--path:"${fod.outPath}/${attrs.srcDir}"''; 58 + 59 + callAnnotations = { packages, ... }@lockAttrs: 60 + map (packageName: nimOverrides.${packageName} or (_: [ ]) lockAttrs) 61 + packages; 44 62 63 + asFunc = x: if builtins.isFunction x then x else (_: x); 64 + 65 + in 66 + buildNimPackageArgs: 67 + let 45 68 composition = finalAttrs: 46 69 let 47 - asFunc = x: if builtins.isFunction x then x else (_: x); 48 - prev = baseAttrs // (asFunc ((asFunc pkgArgs) finalAttrs)) baseAttrs; 49 - in prev // inputsOverride prev; 70 + postPkg = baseAttrs 71 + // (asFunc ((asFunc buildNimPackageArgs) finalAttrs)) baseAttrs; 72 + 73 + lockAttrs = 74 + lib.attrsets.optionalAttrs (builtins.hasAttr "lockFile" postPkg) 75 + (builtins.fromJSON (builtins.readFile postPkg.lockFile)); 76 + 77 + lockDepends = lockAttrs.depends or [ ]; 78 + 79 + lockFileNimFlags = map fodFromLockEntry lockDepends; 80 + 81 + annotationOverlays = lib.lists.flatten (map callAnnotations lockDepends); 82 + 83 + postLock = builtins.foldl' 84 + (prevAttrs: overlay: prevAttrs // (overlay finalAttrs prevAttrs)) 85 + postPkg 86 + annotationOverlays; 87 + 88 + finalOverride = 89 + { depsBuildBuild ? [ ] 90 + , nativeBuildInputs ? [ ] 91 + , nimFlags ? [ ] 92 + , requiredNimVersion ? defaultNimVersion 93 + , nimCopySources ? (lockAttrs == {}) # TODO: remove when nimPackages is gone 94 + , ... 95 + }: 96 + (if requiredNimVersion == 1 then { 97 + depsBuildBuild = [ nim_builder ] ++ depsBuildBuild; 98 + nativeBuildInputs = [ nim1 ] ++ nativeBuildInputs; 99 + } else if requiredNimVersion == 2 then { 100 + depsBuildBuild = [ nim_builder ] ++ depsBuildBuild; 101 + nativeBuildInputs = [ nim2 ] ++ nativeBuildInputs; 102 + } else 103 + throw 104 + "requiredNimVersion ${toString requiredNimVersion} is not valid") // { 105 + nimFlags = lockFileNimFlags ++ nimFlags; 106 + inherit nimCopySources; 107 + }; 50 108 51 - in stdenv.mkDerivation composition 109 + attrs = postLock // finalOverride postLock; 110 + in 111 + lib.trivial.warnIf (builtins.hasAttr "nimBinOnly" attrs) 112 + "the nimBinOnly attribute is deprecated for buildNimPackage" 113 + attrs; 114 + 115 + in 116 + stdenv.mkDerivation composition
+1
pkgs/top-level/all-packages.nix
··· 16811 16811 nimPackages = recurseIntoAttrs nim1.pkgs; 16812 16812 nim2Packages = recurseIntoAttrs nim2.pkgs; 16813 16813 buildNimPackage = callPackage ../development/compilers/nim/build-nim-package.nix { }; 16814 + nimOverrides = callPackage ./nim-overrides.nix { }; 16814 16815 16815 16816 nrpl = callPackage ../development/tools/nrpl { }; 16816 16817
+16
pkgs/top-level/nim-overrides.nix
··· 1 + { lib 2 + , SDL2 3 + }: 4 + 5 + # The following is list of overrides that take three arguments each: 6 + # - lockAttrs: - an attrset from a Nim lockfile, use this for making constraints on the locked library 7 + # - finalAttrs: - final arguments to the depender package 8 + # - prevAttrs: - preceding arguments to the depender package 9 + { 10 + 11 + sdl2 = lockAttrs: finalAttrs: 12 + { buildInputs ? [ ], ... }: { 13 + buildInputs = buildInputs ++ [ SDL2 ]; 14 + }; 15 + 16 + }
+1 -1
pkgs/top-level/nim-packages.nix
··· 7 7 buildNimPackage = buildNimPackage.override { 8 8 defaultNimVersion = 9 9 if lib.versionAtLeast nim.version "2.0.0" then 2 else 1; 10 - }; 10 + } { }; 11 11 12 12 asciigraph = callPackage ../development/nim-packages/asciigraph { }; 13 13