Go to file
Ehmry - 222aea9e79 Accept short git revs
Short revisions are fine, SHA1 is broken anyway.
2023-10-31 15:36:57 +00:00
src Accept short git revs 2023-10-31 15:36:57 +00:00
.envrc Initial commit 2023-10-01 20:53:13 +01:00
.gitignore Cannonicalize output 2023-10-21 17:04:01 +01:00
README.md README: link to FOD definition 2023-10-11 11:18:18 +01:00
Tuprules.tup Cannonicalize output 2023-10-21 17:04:01 +01:00
lock.json Update lockfile 2023-10-31 15:36:17 +00:00
nim_lk.nimble Take package path as an optional argument 2023-10-31 15:36:41 +00:00
shell.nix Initial commit 2023-10-01 20:53:13 +01:00

README.md

Nim lockfile generator

Generates Nix specific lock files for Nim packages.

It puts your dependencies in the Nix store where they belong.

cd «Nim project with a Nimble file»
nim_lk > lock.json

These lock files contain Nix FOD store paths that can be converted to nim.cfg files.

{ pkgs ? import <nixpkgs> { }, lockPath, excludes ? [ ] }:

let inherit (pkgs) lib;
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}"''))
  lib.strings.concatLines
  (pkgs.writeText "nim.cfg")
]

I manage all this with Tup.

# Tuprules.tup above my Nim projects
!nim_lk = |> nim_lk | jq --compact-output --sort-keys > %o |> lock.json

NIXEXPRS_DIR = $(TUP_CWD)/nixexprs
!nim_cfg = |> nix build --file $(NIXEXPRS_DIR)/configure.nix --out-link %o  --arg lockPath `pwd`/%f --arg excludes '[$(NIM_LOCK_EXCLUDES)]' |> nim.cfg
# Tupfile in a Nim project
include_rules
# Omit the foobar library from nim.cfg.
NIM_LOCK_EXCLUDES += "foobar"
: |> !nim_lk |> | ./<lock>
: lock.json |> !nim_cfg |> | ./<lock>