Make creating nix expressions easy

Overview

Nix-template

NOTE: This is still WIP, but should be useful in most situations

Make creating nix expressions easy. Provide a nice way to create largely boilerplate nix-expressions.

Roadmap

  • Finalize cli semantics
  • Ease usage with nixpkgs repo
    • Write to correct location using path
      • Improve logic around directories vs files
      • Improve template-specific items
        • generate buildGoModule's depsSha256
        • generate buildRustPackages's cargoSha256
    • Print top-level addition statement
  • Support Language/frameworks/usage templates:
    • Stdenv
    • Python
    • mkShell
    • Qt
    • Go
    • Rust
    • Flakes
    • NixOS Module
    • NixOS Test
    • Haskell
    • and many more...
  • Add option (--comments?) to embed noob-friendly comments and explanations about common usage patterns
  • Allow contributor information to be set locally (similar to git settings)
    • Set maintainer name through $XDG_CONFIG_HOME
    • Set nixpkgs-root path through $XDG_CONFIG_HOME
  • Better integration with fetchers
    • Automatically determine version and sha256
      • Github (need a way to pass owner and repo)
      • Pypi (will need a way to pass pypi pname, as it may differ from installable path)
  • Implement shell completion (nix-template completions )

Current Usage (github and pypi only)

$ nix-template rust -n --from-url github.com/jonringer/nix-template
Creating directory: /home/jon/projects/nixpkgs/pkgs/applications/misc/nix-template
Generating python expression at /home/jon/projects/nixpkgs/pkgs/applications/misc/nix-template/default.nix
Please add the following line to the approriate file in top-level:

  nix-template = callPackage ../applications/misc/nix-template { };

The resulting file:

# $NIXPKGS_ROOT/pkgs/applications/misc/nix-template/default.nix
{ lib, rustPlatform, fetchFromGitHub }:

rustPlatform.buildRustPackage rec {
  pname = "nix-template";
  version = "0.1.0";

  src = fetchFromGitHub {
    owner = "jonringer";
    repo = pname;
    rev = "v${version}";
    sha256 = "1h6xdvhzg7nb0s82b3r5bsh8bfdb1l5sm7fa24lfwd396xp9yyig";
  };

  cargoSha256 = "0000000000000000000000000000000000000000000000000000";

  buildInputs = [ ];

  meta = with lib; {
    description = "Make creating nix expressions easy";
    homepage = "https://github.com/jonringer/nix-template/";
    license = licenses.cc0;
    maintainers = with maintainers; [ jonringer ];
  };
}

Current Usage (Generically)

# only need to config once per user
$ nix-template config name jonringer
$ nix-template config nixpkgs-root /home/jon/projects/nixpkgs

# add a package
$ nix-template python --pname requests -f pypi -l asl20
Creating directory: /home/jon/projects/nixpkgs/pkgs/development/python-modules/requests/
Generating python expression at /home/jon/projects/nixpkgs/pkgs/development/python-modules/requests/default.nix
Please add the following line to the approriate file in top-level:

  requests = callPackage ../development/python-modules/requests { };
# pkgs/development/python-modules/requests/default.nix
{ lib, buildPythonPackage, fetchPypi }:

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

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

  propagatedBuildInputs = [ ];

  pythonImportsCheck = [ "requests" ];

  meta = with lib; {
    description = "CHANGEME";
    homepage = "https://github.com/CHANGEME/requests/";
    license = licenses.asl20;
    maintainer = with maintainers; [ jonringer ];
  };
}

Installation

from nixpkgs (unstable, not available in 20.03):

$ nixenv -iA nix-template

with nix-cli (from this repository):

$ nix-env -f default.nix -iA ""

with cargo

$ cargo install --path .

Development

Installing depedencies on nixpkgs:

nix-shell

Other platforms, you'll need the following dependencies:

  • cargo
  • rustc
  • rust-clippy

End Goal

# only need to config once per user
$ nix-template config name jonringer
$ nix-template config nixpkgs-root /home/jon/projects/nixpkgs

# add a package
$ nix-template python --pname requests -f pypi -l asl20
Found latest stable release to be 2.24.0 on pypi.com
Creating directory: /home/jon/projects/nixpkgs/pkgs/development/python-modules/requests/
Generating python expression at /home/jon/projects/nixpkgs/pkgs/development/python-modules/requests/default.nix
For an addition to nixpkgs as a python package, please add the following to pkgs/top-level/python-packages.nix:

  requests = callPackage ../development/python-modules/<PNAME> { };

For an addition to nixpkgs as a python application, please add the following to pkgs/top-level/all-packages.nix:

  requests = python3Packages.callPackage <PATH_FROM_CLI> { };
# pkgs/development/python-modules/requests/default.nix
{ lib, buildPythonPackage, fetchPypi }:

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

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

  propagatedBuildInputs = [ ];

  pythonImportsCheck = [ "requests" ];

  meta = with lib; {
    description = "CHANGEME";
    homepage = "https://github.com/CHANGEME/requests/";
    license = licenses.asl20;
    maintainer = with maintainers; [ jonringer ];
  };
}
Issues
  • completions fail to load

    completions fail to load

    i put

    eval "$(nix-template completions zsh)"
    

    in my zshrc

    i get _arguments: command not found when i start a new shell

    happens without a config too

    env -i zsh -d -f -i
    eval "$(nix-template completions zsh)"
    
    opened by Artturin 5
  • Add noob-friendly `--documentation-links` option

    Add noob-friendly `--documentation-links` option

    Hi @jonringer!

    I got to see your chat with @zimbatm on Nix friday, where you mentioned working on this project. Loved the idea, and reading through the README.md, I got inspired by the --comments item you left on your Roadmap.

    Not sure you accept contributions to this project, but I tried out something and figured you might be interested: This PR adds a --documentation-links (or -d) option to add links to relevant sections of the Nixpkgs contributor guide.

    And whether you want it or not: Thanks for nix-template!

    opened by Pamplemousse 3
  • Query Pypi for version, description, website and license

    Query Pypi for version, description, website and license

    It would be really useful for packaging python things if the tool would query pypi for the latest released version, description, website and license.

    opened by SuperSandro2000 3
  • add https:// to homepage github link

    add https:// to homepage github link

    before

    nix-template --stdout stdenv --from-url=https://github.com/varlink/libvarlink
    Determining latest release for libvarlink
    Determining sha256 for libvarlink
    { lib, stdenv, fetchFromGitHub }:
    
    stdenv.mkDerivation rec {
      pname = "libvarlink";
      version = "22";
    
      src = fetchFromGitHub {
        owner = "varlink";
        repo = pname;
        rev = "version";
        sha256 = "1i15227vlc9k4276r833ndhxrcys9305pf6dga1j0alx2vj85yz2";
      };
    
      buildInputs = [ ];
    
      meta = with lib; {
        description = "C implementation of the Varlink protocol and command line tool";
        homepage = "github.com/varlink/libvarlink";
        license = licenses.CHANGE;
        maintainers = with maintainers; [ artturin ];
      };
    }
    

    after

    ./result/bin/nix-template --stdout stdenv --from-url=https://github.com/varlink/libvarlink
    Determining latest release for libvarlink
    Determining sha256 for libvarlink
    { lib, stdenv, fetchFromGitHub }:
    
    stdenv.mkDerivation rec {
      pname = "libvarlink";
      version = "22";
    
      src = fetchFromGitHub {
        owner = "varlink";
        repo = pname;
        rev = "version";
        sha256 = "1i15227vlc9k4276r833ndhxrcys9305pf6dga1j0alx2vj85yz2";
      };
    
      buildInputs = [ ];
    
      meta = with lib; {
        description = "C implementation of the Varlink protocol and command line tool";
        homepage = "https://github.com/varlink/libvarlink";
        license = licenses.CHANGE;
        maintainers = with maintainers; [ artturin ];
      };
    }
    
    opened by Artturin 2
  • Add

    Add "--from-url" option

    would be nice to determine pname, fetcher, homepage, license, and src from an url option:

    nix-template rust --from-url https://github.com/jonringer/nix-template/
    
    opened by jonringer 1
  • Add support for generating a nixos module

    Add support for generating a nixos module

    Would be nice to have a template for that as well

    opened by jonringer 1
  • Add flake template

    Add flake template

    Would be nice to have an opinionated flake layout template

    {
      description = "CHANGEME";
    
      inputs = {
        utils.url = "github:numtide/flake-utils";
      };
    
      outputs = { self, nixpkgs, utils }:
        let
          # put devShell and any other required packages into local overlay
          localOverlay = import ./nix/overlay.nix;
          
          pkgsForSystem = system: import nixpkgs {
            overlays = [
              localOverlay
            ];
            inherit system;
          };
        in utils.lib.eachSystem [ "x86_64-linux" ] (system: rec {
          legacyPackages = pkgsForSystem system;
          packages = utils.lib.flattenTree {
            inherit (pkgs) devShell myPkg;
          };
          defaultPackage = packages.myPkg;
          apps.<mypkg> = utils.lib.mkApp { drv = packages.myPkg; }
      });
    }
    
    opened by jonringer 1
  • --from-url github.com/YoyPa/isw fails

    --from-url github.com/YoyPa/isw fails

    nix-template Python --from-url github.com/YoyPa/isw
    Determining latest release for isw
    Determining sha256 for isw
    [2021-07-12T04:24:27Z ERROR nix_template::url] Unable to parse response from github to json: Error("invalid type: null, expected a string", line: 1, column: 4000)
    
    opened by Artturin 1
  • Print filepaths when adding to nixpkgs

    Print filepaths when adding to nixpkgs

    testing PR process

    opened by jonringer 0
  • pythonImportsCheck should change

    pythonImportsCheck should change "-" to "."

    most packages that have "name-something" are namespaced, and it's more likely that the import path was meant to be "name.something"

    opened by jonringer 0
  • Can't parse pypi response

    Can't parse pypi response

    [2021-11-11T06:32:03Z ERROR nix_template::url] Unable to parse response from pypi.io to json: Error("invalid type: null, expected struct ProjectUrls", line: 1, column: 6924)
    
    nix-template python -p jinja2-ansible-filters -n -u https://pypi.org/project/jinja2-ansible-filters
    
    opened by jonringer 0
  • Can't parse github response

    Can't parse github response

    $ nix-template go --nixpkgs --pname mdr --from-url https://github.com/MichaelMure/mdr
    [2021-08-17T10:56:29Z ERROR nix_template::url] Unable to parse response from github to json: Error("invalid type: null, expected a string", line: 1, column: 1421)
    
    $ nix-template --version
    nix-template 0.1.4
    
    opened by SuperSandro2000 0
  • Make overlays a attr set

    Make overlays a attr set

    apparently overlays should be an attr set of overlays

    opened by jonringer 0
  • suggestion:  style

    suggestion: style

    use

    { lib
    , stdenv
    , fetchFromGitHub 
    }:
    

    instead of { lib, stdenv, fetchFromGitHub }:

    btw what is the name of this i still haven't found out

    opened by Artturin 2
  • `-p` shouldn't be required for `-n`, when `--from-url` is given

    `-p` shouldn't be required for `-n`, when `--from-url` is given

    Currently fails:

    $ ./result/bin/nix-template stdenv -n -u github.com/openzfs/zfs example.nix
    '-p,--pname' is required when using the -n,--nixpkgs flag
    
    opened by jonringer 0
  • Make `--nixpkgs` the default, or add configuration option to make it the default

    Make `--nixpkgs` the default, or add configuration option to make it the default

    Allow users to set whether they want --nixpkgs to be true by default

    opened by jonringer 0
  • Implement --comments, including helpful suggestions for creating nix expressions

    Implement --comments, including helpful suggestions for creating nix expressions

    Instead of just having the "default" attrs. Also include helpful comments

    opened by jonringer 0
  • Find appropriate location to place addition in top-level attr set

    Find appropriate location to place addition in top-level attr set

    Would be nice that instead of just printing the attr addition line, that nix-template will just add the attr name at an appropriate location within the file.

    The steps would roughly be:

    • remove all comments,
    • split file on paragraphs,
    • then find location
    • insert new package reference
    opened by jonringer 0
  • Don't panic, less readable

    Don't panic, less readable

    [13:15:15] [email protected] /home/jon/projects/nixpkgs (master)
    $ nix-template python -l mit -p azure-mgmt-synapse
    thread 'main' panicked at 'Cannot write to file 'default.nix', already exists', src/main.rs:87:17
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    [13:15:56] [email protected] /home/jon/projects/nixpkgs (master)
    $ nix-template python -l mit -p azure-mgmt-synapse -n
    No [PATH] provided, defaulting to "pkgs/development/python-modules/"
    Creating directory: /home/jon/projects/nixpkgs/pkgs/development/python-modules/azure-mgmt-synapse
    Generated a python nix expression at /home/jon/projects/nixpkgs/pkgs/development/python-modules/azure-mgmt-synapse/default.nix
    Please add the following line to the approriate file in top-level:
    
      azure-mgmt-synapse = callPackage ../development/python-modules/azure-mgmt-synapse { };
    

    would be nicer to have a sys::process::exit(1) with a helpful message instead of default panic message

    opened by jonringer 0
Releases(v0.1.4)
Owner
Jonathan Ringer
A release manager for NixOS 20.09, 21.05, and 21.11. Functional Programming fan including Haskell and NixOS
Jonathan Ringer
Text Expression Runner – Readable and easy to use text expressions

ter - Text Expression Runner ter is a cli to run text expressions and perform basic text operations such as filtering, ignoring and replacing on the c

Maximilian Schulke 70 Nov 9, 2021
A Modern Real-Time Data Processing & Analytics DBMS with Cloud-Native Architecture, built to make the Data Cloud easy

A Modern Real-Time Data Processing & Analytics DBMS with Cloud-Native Architecture, built to make the Data Cloud easy

Datafuse Labs 2.5k Nov 23, 2021
A Modern Real-Time Data Processing & Analytics DBMS with Cloud-Native Architecture, built to make the Data Cloud easy

A Modern Real-Time Data Processing & Analytics DBMS with Cloud-Native Architecture, built to make the Data Cloud easy

Datafuse Labs 2.6k Dec 1, 2021
Victorem - easy UDP game server and client framework for creating simple 2D and 3D online game prototype in Rust.

Victorem Easy UDP game server and client framework for creating simple 2D and 3D online game prototype in Rust. Example Cargo.toml [dependencies] vict

Victor Winbringer 18 Nov 8, 2021
A command-line tool and library for generating regular expressions from user-provided test cases

Table of Contents What does this tool do? Do I still need to learn to write regexes then? Current features How to install? 4.1 The command-line tool 4

Peter M. Stahl 4.7k Nov 21, 2021
hado-rshado β€” A little macro for writing haskell-like do expressions without too much ceremony

hado Monadic haskell-like expressions brought to rust via the hado! macro What? A little macro for writing haskell-like do expressions without too muc

Lucas David Traverso 43 Jul 3, 2021
Rust friendly bindings to *nix APIs

Rust bindings to *nix APIs Documentation (Releases) Nix seeks to provide friendly bindings to various *nix platform APIs (Linux, Darwin, ...). The goa

null 1.6k Nov 22, 2021
An implementation of regular expressions for Rust. This implementation uses finite automata and guarantees linear time matching on all inputs.

regex A Rust library for parsing, compiling, and executing regular expressions. Its syntax is similar to Perl-style regular expressions, but lacks a f

The Rust Programming Language 2.1k Nov 24, 2021
Your project’s nix-env [[email protected]]

lorri https://github.com/nix-community/lorri lorri is a nix-shell replacement for project development. lorri is based around fast direnv integration f

Nix community projects 180 Nov 18, 2021
Nix language server that evaluates code

nix-eval-lsp Still use nix-community/rnix-lsp. This repo is a work in progress. nix-eval-lsp is an experimental language server for Nix

Aaron Janse 43 Nov 18, 2021
A Rust macro for writing nested loop expressions

loop_chain A Rust macro for writing nested loop expressions Usage | Examples | Docs Dependencies [dependencies] loop_chain = "0.1.1" Usage For express

Takayuki Maeda 5 Jul 30, 2021
Dog command for *nix systems, Rust port of dog.

dog-rs Dog command for *nix systems, Rust port of dog. Because there is a cat command, should be a dog command too. It was written completely using VS

Juanjo Salvador 2 Sep 29, 2021
lints and suggestions for the nix programming language

statix Lints and suggestions for the Nix programming language. statix highlights antipatterns in Nix code. statix --fix can fix several such occurrenc

Akshay 146 Nov 28, 2021
βš‘πŸ¦€ 🧨 make your rust types fit DynamoDB and visa versa

?? ?? dynomite dynomite makes DynamoDB fit your types (and visa versa) Overview Goals ⚑ make writing dynamodb applications in rust a productive experi

Doug Tangren 173 Nov 27, 2021
πŸ˜‹ Make your own blog!

Leven Leven is a lightweight Markdown-based static site generator for blogs. It's a lot like Jekyll or Hugo, but it's much simpler, much faster, and m

null 49 Apr 23, 2021
Make and use playgrounds locally.

cargo playground Cargo playground opens a local playground in the editor of your choice. Install You can install it directly using cargo $ cargo insta

null 17 Aug 5, 2021
A fast and small Rust library to make Electron apps more secure.

electron-hardener A Rust library and command line tool to harden Electron binaries against runtime behavior modifications. This provides a way to hard

1Password 316 Nov 24, 2021
Make ELF formatted apps configurable

elfredo `elfredo` is a library that allows you to patch executables after they were compiled. It utilize an extra embedded section to store data/confi

Asaf Fisher 7 Sep 5, 2021
Tool to make Solus packaging even easier.

A small tool to make packaging for Solus even easier. Features Remove all packages from the local solbuild repo.

null 3 Aug 25, 2021
cargo, make me a project

cargo-generate cargo, make me a project cargo-generate is a developer tool to help you get up and running quickly with a new Rust project by leveragin

null 833 Nov 17, 2021
eJNI is a Rust crate to make working with Java's JNI less painful by providing abstractions.

eJNI provides abstractions for often-used classes from the Java standard library, like Map and List. Besides this eJNI also provides easy ways to work with Java's primitives and their object counterparts (e.g int and Integer).

Tobias de Bruijn 9 Nov 17, 2021
Make any NixOS system netbootable with 10s cycle times.

nix-netboot-serve Dynamically generate netboot images for arbitrary NixOS system closures, profiles, or configurations with 10s iteration times. Usage

Determinate Systems 107 Nov 29, 2021
The tool to make svg with triangles by length from two points.

The tool to make svg with triangles by length from two points.

null 2 Sep 27, 2021
A lite tool to make systemd work in any container(Windows Subsystem for Linux 2, Docker, Podman, etc.)

Angea Naming from hydrangea(γ‚’γ‚Έγ‚΅γ‚€) A lite tool to make systemd work in any container(Windows Subsystem for Linux 2, Docker, Podman, etc.) WSL1 is not s

いんしさくら 18 Nov 20, 2021
A lite tool to make systemd work in any container(Windows Subsystem for Linux 2, Docker, Podman, etc.)

Angea Naming from hydrangea(γ‚’γ‚Έγ‚΅γ‚€) A lite tool to make systemd work in any container(Windows Subsystem for Linux 2, Docker, Podman, etc.) WSL1 is not s

いんしさくら 18 Nov 20, 2021
Using the powers of Rust, Go and Dragonfly to make a vanilla-like world generation.

df-rs-gen β€” Dragonfly Rust Generator Using the powers of Rust, Go and Dragonfly to make a vanilla-like world generation. How to use Clone the repo. gi

Sculas 0 Nov 9, 2021
a simple program to make i3 open windows in alternating orientations

i3-alternating 1 use i3ipc::{reply::NodeLayout, I3Connection, I3EventListener, Subscription, event::{Event, WindowEventInfo}, event::inner::Windo

null 4 Oct 18, 2021
flow-rust-sdk utilizes the Flow gRPC AccessAPI to make requests on the flow blockchain.

Welcome to the Flow-Rust-SDK! We're glad to have you here. There are a few important items that we should cover real quick before you dive in. Version

null 5 Nov 7, 2021
Command line tool to make conventional commit messages

Commit This project is a copy of cz-cli with some minor changes. I made this project for my own use, because I don't want to mess with the original cz

Pedro Mendes 2 Nov 28, 2021