百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
N

npins

> 编程语言
开源

Nix 依赖项锁定。与 Niv 非常相似,但具有一些我个人想要的功能。

556 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

Nix 依赖项锁定。与 Niv 非常相似,但具有一些我个人想要的功能。

npins

Simple and convenient dependency pinning for Nix

License Contributors Issues PRs Tests Matrix

About

npins is a simple tool for handling different types of dependencies in a Nix project. It is inspired by and comparable to Niv.

Features

  • Track git branches
  • Track git release tags
    • Tags must roughly follow SemVer
    • GitHub/GitLab releases are intentionally ignored
  • For git repositories hosted on GitHub or GitLab, fetchTarball is used instead of fetchGit
  • Track Nix channels
    • Unlike tracking a channel from its git branch, this gives you access to the programs.sqlite database
    • Can also track Nix channel artifacts like live isos
  • Track PyPi packages

Getting Started

Installation

npins should readily be available in all sufficiently new nixpkgs:

bash
nix-shell -p npins

You can easily get a nightly if you want to (requires newstyle Nix commands):

bash
nix shell -f https://github.com/andir/npins/archive/master.tar.gz

You could also install it to your profile using nix-env (not recommended, but might be useful for bootstrapping):

bash
nix-env -f https://github.com/andir/npins/archive/master.tar.gz -i

Quickstart

…

In Nix, you may then use it like this:

nix
let
  sources = import ./npins;
  pkgs = import sources.nixpkgs {};
in
  …

You may also use attributes from the JSON file, they are exposed 1:1. For example, sources.myPackage.version should work for many pin types (provided that that pin actually tracks some version). Note however that the available attribute may change over time; see npins upgrade below.

Usage

…

Initialization

In order to start using npins to track any dependencies you need to first initialize the project:

bash
npins init

This will create an npins folder with a default.nix and sources.json within. By default, the nixpkgs-unstable channel will be added as pin.

bash
$ npins help init
Initializes the npins directory. Running this multiple times will restore/upgrade the `default.nix` and never touch your sources.json

Usage: npins init [OPTIONS]

Options:
      --bare     Don't add an initial `nixpkgs` entry
  -v, --verbose  Print debug messages
  -h, --help     Print help

Migrate from Niv

You can import your pins from Niv:

bash
npins import-niv nix/sources.json
npins update

In your Nix configuration, simply replace import ./nix/sources.nix with import ./npins — it should be a drop-in replacement.

Note that the import functionality is minimal and only preserves the necessary information to identify the dependency, but not the actual pinned values themselves. Therefore, migrating must always come with an update (unless you do it manually).

bash
$ npins help import-niv
Try to import entries from Niv

Usage: npins import-niv [OPTIONS] [PATH]

Arguments:
  [PATH]  [default: nix/sources.json]

Options:
  -n, --name   Optionally import only one entry from Niv instead of all
  -v, --verbose      Print debug messages
  -h, --help         Print help

Adding dependencies

Some common usage examples:

…

Depending on what kind of dependency you are adding, different arguments must be provided. You always have the option to specify a version (or hash, depending on the type) you want to pin to. Otherwise, the latest available version will be fetched for you. Not all features are present on all pin types.

…

There are several options for tracking git branches, releases and tags:

…

Npins can track plain old links to URL resources. They will never update. Alternatively, you can also add the --mutable flag to make them behave similarly to the Lockable HTTP Tarball Protocol: Npins will follow any redirects and then pin that url as the actual version, while keeping the original url as "update" url.

…

Removing dependencies

bash
$ npins help remove
Removes one pin entry

Usage: npins remove [OPTIONS] ...

Arguments:
  ...  

Options:
  -v, --verbose  Print debug messages
  -h, --help     Print help

Show current entries

This will print the currently pinned dependencies in a human readable format. The machine readable sources.json may be accessed directly, but make sure to always check the format version (see below).

bash
$ npins help show
Lists the current pin entries

Usage: npins show [OPTIONS] [NAMES]...

Arguments:
  [NAMES]...  Names of the pins to show

Options:
  -p, --plain    Prints only pin names
  -e, --exclude  Invert [NAMES] to exclude specified pins
  -v, --verbose  Print debug messages
  -h, --help     Print help

Updating dependencies

You can decide to update only selected dependencies, or all at once. For some pin types, we distinguish between "find out the latest version" and "fetch the latest version". These can be controlled with the --full and --partial flags.

…

Upgrading the pins file

To ensure compatibility across releases, the npins/sources.json and npins/default.nix are versioned. Whenever the format changes (i.e. because new pin types are added), the version number is increased. Use npins upgrade to automatically apply the necessary changes to the sources.json and to replace the default.nix with one for the current version. No stability guarantees are made on the Nix side across versions.

bash
$ npins help upgrade
Upgrade the sources.json and default.nix to the latest format version. This may occasionally break Nix evaluation!

Usage: npins upgrade [OPTIONS]

Options:
  -v, --verbose  Print debug messages
  -h, --help     Print help

Using private GitLab repositories

There are two ways of specifying the access token (not deploy token!), either via an environment variable or via a parameter. The access token needs at least the read_api and read_repository scopes and the Reporter role. The read_api scope is not available for deploy tokens, hence they are not usable for npins.

Specifying the token via environment variable means that npins will use the token for adding/updating the pin but not write it to sources.json. To update the repository in the future, the variable needs to be set again and nix needs to be configured accordingly to be able to fetch it (see the netrc-file option). Environment example:

bash
$ GITLAB_TOKEN=H_BRqzV3NcaPvXcYs2Xf npins add gitlab my-org my-private-repo

When specifying the token via the --token parameter, the token is written to sources.json so future invocations of npins will use it as well. The token is also embedded into the URL that nix downloads, so no further nix configuration is necessary. As npins adds the token to your sources.json, this feature is not advised for publicly available repositories. When a pin has specified a token, the GITLAB_TOKEN environment variable is ignored. Parameter example:

bash
$ npins add gitlab my-org my-private-repo --token H_BRqzV3NcaPvXcYs2Xf

Using local sources during development

While npins allows you to pin dependencies in reproducible fashion, it is often desirable to allow fast impure iterations during development. Npins supports local overrides for this. If your sources.json contains a source named abc, you can e.g. develop from /abc by exposing the environment variable NPINS_OVERRIDE_abc=/abc. Please note, that only alphanumerical characters and _ are allow characters in overriden sources. All other characters are converted to _. Also check, that you are building impure, if you are wondering, why these overrides are maybe not becoming active.

Using the Nixpkgs fetchers

By default, all pins are fetched through builtins fetchers. These fetch at eval time and do not produce a derivation, like with IFD. This is necessary for bootstrapping purposes (the first Nixpkgs can only be fetched through a builtins), but may be undesirable for other pins. All pins optionally take a pkgs argument, which will use the Nixpkgs fetchers instead and produce a derivation.

nix
let
  sources = import ./npins;
  pkgs = import sources.nixpkgs { };
in
sources.mySource { inherit pkgs; }

Running the latest unreleased npins

The recommended way is to use our packaging in the repository by pinning npins itself with npins:

npins add github andir npins -b master
nix
let
  sources = import ./npins;
  npinsSources = import (sources.npins + "/npins");
  npinsPkgs = import npinsSources.nixpkgs { };
in
npinsPkgs.callPackage (sources.npins + "/npins.nix") {}

Alternatively, a good old package override can do the same:

nix
pkgs.npins.overrideAttrs (final: old: {
  version = …;
  src = (import ./npins).npins;

  cargoHash = null;
  cargoDeps = pkgs.rustPlatform.fetchCargoVendor {
    src = final.src;
    hash = …;
  };
})

Contributing

Contributions to this project are welcome in the form of GitHub Issues or PRs. Please consider the following before creating PRs:

  • This project has several commit hooks configured in the shell.nix, make sure you have these enabled and they are passing
  • This readme is templated, edit README.md.in instead (the commit hook will take care of the rest)
  • Consider discussing major features or changes in an issue first

AI Contributions

Getting LLMs to produce any reasonable output requires expertise with the codebase, which drive-by contributors typically lack. At the same time, making easy contributions by hand is the only way to gather such expertise in the first place. Therefore, LLM contributions are poisoning our own supply of domain experts and our interest in reviewing LLM code is accordingly low.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rust

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言