Nix-template v0.1.4 released!

Release a new version of nix-template, major changes:

- Add nixos module template
- Add nixos test template
- Add flake template
- Add -u,--from-url option
  - Github supported

Biggest improvement is the --from-url with github:

$ ./result/bin/nix-template stdenv -u github.com/openzfs/zfs example.nix
Determining latest release for zfs
Determining sha256 for zfs
Generated a stdenv nix expression at /home/jon/projects/nixpkgs/example.nix
[15:56:12] jon@jon-desktop /home/jon/projects/nixpkgs (bump-nix-template)
$ cat /home/jon/projects/nixpkgs/example.nix
{ lib, stdenv, fetchFromGitHub }:

stdenv.mkDerivation rec {
  pname = "zfs";
  version = "2.1.0";

  src = fetchFromGitHub {
    owner = "openzfs";
    repo = pname;
    rev = "zfs-${version}";
    sha256 = "16l7kva4i3xvzls7n8vi7gpjhxxsgxs37p81fi0n0r2p5d4kimk1";
  };

  buildInputs = [ ];

  meta = with lib; {
    description = "OpenZFS on Linux and FreeBSD";
    homepage = "https://github.com/openzfs/zfs/";
    license = licenses.CHANGE;
    maintainers = with maintainers; [ jonringer ];
  };
}

Old thread: https://discourse.nixos.org/t/nix-template-at-v0-1-0

12 Likes

Pypi support was added in 0.1.2:

nix-template python --stdout -u pypi.org/project/requests
Determining latest release for requests
{ lib, buildPythonPackage, fetchPypi }:

buildPythonPackage rec {
  pname = "requests";
  version = "2.26.0";

  src = fetchPypi {
    inherit pname version;
    sha256 = "b8aa58f8cf793ffd8782d3d8cb19e66ef36f7aba4353eec859e74678b01b07a7";
  };

  propagatedBuildInputs = [ ];

  pythonImportsCheck = [ "requests" ];

  meta = with lib; {
    description = "Python HTTP for Humans";
    homepage = "https://requests.readthedocs.io";
    license = licenses.asl20;
    maintainers = with maintainers; [  ];
  };
}
2 Likes

Can this tool be used to update version/sha256 to the latest version in an existing file for a python package? Or are there other tools for that?

You’re looking for nix-update. And for common expressions, it can.

I tried nix-update attribute with a working default.nix file containing a python package and it failed ("error: anonymous function at... called without required argument 'lib'", the derivation does have lib as the fist argument), so I assumed that it only works within nixpkgs infrastructure.

most likely you using stdenv.lib somewhere in your nix code. And somehow nix-update is referencing a newer version of nixpkgs.

But I’ve only used it with nixpkgs’ in-tree code. So it might not be the case. cc @Mic92

nix-update expected a package set (an attribute set of nix packages) rather than a single package.
So if you want to update a single package do the following:

# stored as default.nix
{ pkgs ? with import <nixpkgs> {} }:
{
  mypackage = pkgs.callPackage ./my-package {};
}

Than you can run nix-update mypackage in the same directory:

3 Likes

Thanks, I have about a hundred python packages which are either not in nixpkgs or are outdated there. Unfortunately they are not up to nixpkgs standards (disabled tests, never tested on many platforms, etc.) so it would not be easy for me to create PRs for them. They are loaded from overlays so I would need to create that file to list all of them. My current solution is to use this quick and dirty bash/curl/jq/sed script Update default.nix for a python package by querying Pypi · GitHub.

Are there plans to make nix-template also fetch the license? It seems trivial as you’d expect, at least GitHub’s API, to expose that information. And if not to read the file and match it against your own database

The --from-url already implements this. It’s just limited to what github is also able to recognize.

2 Likes
Hosted by Flying Circus.