From 98ba9e7d186193b3a26818a314a2fd09d2352820 Mon Sep 17 00:00:00 2001 From: Antoine Eiche Date: Mon, 15 Apr 2019 15:45:00 +0200 Subject: [PATCH] readme: introduce add subcommand `file` and `github` --- README.md | 71 +++++++++++++++++++++++++++++++++++++-------------- README.tpl.md | 22 ++++++++++++++-- default.nix | 4 +-- 3 files changed, 74 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 5ad6114..1cec8f5 100644 --- a/README.md +++ b/README.md @@ -170,14 +170,20 @@ The following data was added in `nix/sources.json` for `jq`: } ``` +Alternatively, the GitHub `add` sub-command could have been used: + +``` shell +$ niv add github stedolan/jq +``` + #### Using custom URLs It is possible to use niv to fetch packages from custom URLs. Run this command to add the Haskell compiler [GHC] to your `nix/sources.json`: ``` shell -$ niv add ghc \ - -v 8.4.3 \ +$ niv add file ghc \ + -v 8.4.3 \ -t 'https://downloads.haskell.org/~ghc//ghc--i386-deb8-linux.tar.xz' ``` @@ -213,25 +219,61 @@ Available commands: #### Add +``` +Usage: niv add (COMMAND | PACKAGE) + Add dependency + +Available options: + -h,--help Show this help text + +Available commands: + github Add GitHub dependency + file Add file dependency + / Add GitHub dependency + +``` + +#### Add a GitHub dependency + ``` Examples: - niv add stedolan/jq - niv add NixOS/nixpkgs-channels -n nixpkgs -b nixos-18.09 - niv add my-package -v alpha-0.1 -t http://example.com/archive/.zip + niv add github stedolan/jq + niv add github NixOS/nixpkgs-channels -n nixpkgs -b nixos-18.09 -Usage: niv add [-n|--name NAME] PACKAGE ([-a|--attribute KEY=VAL] | - [-b|--branch BRANCH] | [-o|--owner OWNER] | [-r|--repo REPO] | - [-v|--version VERSION] | [-t|--template URL] | [-T|--type TYPE]) - Add dependency +Usage: niv add github [-n|--name NAME] PACKAGE ([-a|--attribute KEY=VAL] | + [-t|--template URL]) ([-b|--branch BRANCH] | + [-o|--owner OWNER] | [-r|--repo REPO] | + [-v|--version VERSION]) + Add GitHub dependency Available options: -n,--name NAME Set the package name to -a,--attribute KEY=VAL Set the package spec attribute to + -t,--template URL Used during 'update' when building URL. Occurrences + of are replaced with attribute 'foo'. -b,--branch BRANCH Equivalent to --attribute branch= -o,--owner OWNER Equivalent to --attribute owner= -r,--repo REPO Equivalent to --attribute repo= -v,--version VERSION Equivalent to --attribute version= + -h,--help Show this help text + +``` + +#### Add a file dependency + +``` +Examples: + + niv add file my-package -v alpha-0.1 -t http://example.com/archive/.zip + +Usage: niv add file [-n|--name NAME] PACKAGE ([-a|--attribute KEY=VAL] | + [-t|--template URL]) [-T|--type TYPE] + Add file dependency + +Available options: + -n,--name NAME Set the package name to + -a,--attribute KEY=VAL Set the package spec attribute to -t,--template URL Used during 'update' when building URL. Occurrences of are replaced with attribute 'foo'. -T,--type TYPE The type of the URL target. The value can be either @@ -250,22 +292,13 @@ Examples: niv update nixpkgs niv update my-package -v beta-0.2 -Usage: niv update [PACKAGE] ([-a|--attribute KEY=VAL] | [-b|--branch BRANCH] | - [-o|--owner OWNER] | [-r|--repo REPO] | [-v|--version VERSION] - | [-t|--template URL] | [-T|--type TYPE]) +Usage: niv update [PACKAGE] ([-a|--attribute KEY=VAL] | [-t|--template URL]) Update dependencies Available options: -a,--attribute KEY=VAL Set the package spec attribute to - -b,--branch BRANCH Equivalent to --attribute branch= - -o,--owner OWNER Equivalent to --attribute owner= - -r,--repo REPO Equivalent to --attribute repo= - -v,--version VERSION Equivalent to --attribute version= -t,--template URL Used during 'update' when building URL. Occurrences of are replaced with attribute 'foo'. - -T,--type TYPE The type of the URL target. The value can be either - 'file' or 'tarball'. If not set, the value is - inferred from the suffix of the URL. -h,--help Show this help text ``` diff --git a/README.tpl.md b/README.tpl.md index dda90c5..ebb6d40 100644 --- a/README.tpl.md +++ b/README.tpl.md @@ -170,14 +170,20 @@ The following data was added in `nix/sources.json` for `jq`: } ``` +Alternatively, the GitHub `add` sub-command could have been used: + +``` shell +$ niv add github stedolan/jq +``` + #### Using custom URLs It is possible to use niv to fetch packages from custom URLs. Run this command to add the Haskell compiler [GHC] to your `nix/sources.json`: ``` shell -$ niv add ghc \ - -v 8.4.3 \ +$ niv add file ghc \ + -v 8.4.3 \ -t 'https://downloads.haskell.org/~ghc//ghc--i386-deb8-linux.tar.xz' ``` @@ -203,6 +209,18 @@ replace_niv_help replace_niv_add_help ``` +#### Add a GitHub dependency + +``` +replace_niv_add_github_help +``` + +#### Add a file dependency + +``` +replace_niv_add_file_help +``` + #### Update ``` diff --git a/default.nix b/default.nix index e15158c..539522f 100644 --- a/default.nix +++ b/default.nix @@ -38,9 +38,9 @@ rec ); niv_cmd_help = cmd: builtins.readFile (pkgs.runCommand "niv_${cmd}_help" { buildInputs = [ niv ]; } - "niv ${cmd} --help > $out" + "niv ${pkgs.lib.replaceStrings ["_"] [" "] cmd} --help > $out" ); - cmds = [ "add" "update" "drop" "init" "show" ]; + cmds = [ "add" "add_github" "add_file" "update" "drop" "init" "show" ]; }; pkgs.lib.replaceStrings ([ "replace_niv_help" ] ++ (map (cmd: "replace_niv_${cmd}_help") cmds))