nim_lk/README.md

48 lines
1.3 KiB
Markdown
Raw Permalink Normal View History

2023-10-05 17:30:56 +02:00
# Nim lockfile generator
Generates Nix specific lock files for Nim packages.
It puts your dependencies in the Nix store where they belong.
```sh
cd «Nim project with a Nimble file»
nim_lk > lock.json
```
2023-10-11 12:18:18 +02:00
These lock files contain Nix [FOD](https://nixos.org/manual/nix/stable/glossary#gloss-fixed-output-derivation) store paths that can be converted to `nim.cfg` files.
2023-10-05 17:30:56 +02:00
```nix
2023-10-08 15:26:58 +02:00
{ pkgs ? import <nixpkgs> { }, lockPath, excludes ? [ ] }:
2023-10-05 17:30:56 +02:00
let inherit (pkgs) lib;
2023-10-08 15:26:58 +02:00
in with builtins;
lib.pipe lockPath [
readFile
fromJSON
(getAttr "depends")
(filter ({ packages, ... }: !(any (pkg: elem pkg excludes) packages)))
(map ({ path, srcDir, ... }: ''path:"${storePath path}/${srcDir}"''))
2023-10-05 17:30:56 +02:00
lib.strings.concatLines
(pkgs.writeText "nim.cfg")
]
```
I manage all this with [Tup](https://gittup.org/tup).
```
# Tuprules.tup above my Nim projects
2023-10-08 15:26:58 +02:00
!nim_lk = |> nim_lk | jq --compact-output --sort-keys > %o |> lock.json
2023-10-05 17:30:56 +02:00
NIXEXPRS_DIR = $(TUP_CWD)/nixexprs
2023-10-08 15:26:58 +02:00
!nim_cfg = |> nix build --file $(NIXEXPRS_DIR)/configure.nix --out-link %o --arg lockPath `pwd`/%f --arg excludes '[$(NIM_LOCK_EXCLUDES)]' |> nim.cfg
2023-10-05 17:30:56 +02:00
```
```
# Tupfile in a Nim project
include_rules
2023-10-08 15:26:58 +02:00
# Omit the foobar library from nim.cfg.
NIM_LOCK_EXCLUDES += "foobar"
2023-10-05 17:30:56 +02:00
: |> !nim_lk |> | ./<lock>
: lock.json |> !nim_cfg |> | ./<lock>
```