niv 0.2.21 → 0.2.22
raw patch · 8 files changed
+115/−96 lines, 8 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Niv.Sources: V28 :: SourcesNixVersion
Files
- README.md +8/−1
- niv.cabal +2/−2
- nix/sources.nix +59/−55
- src/Niv/Cli.hs +7/−7
- src/Niv/Git/Cmd.hs +7/−4
- src/Niv/GitHub/API.hs +12/−12
- src/Niv/GitHub/Cmd.hs +1/−1
- src/Niv/Sources.hs +19/−14
README.md view
@@ -81,6 +81,8 @@ ### Getting started +Nix is a very powerful tool for building code and setting up environments. `niv` complements it by making it easy to describe and update remote dependencies (URLs, GitHub repos, etc). It is a simple, practical alternative to [Nix flakes](https://nixos.wiki/wiki/Flakes).+ This section covers common use cases: * [Bootstrapping a Nix project](#bootstrapping-a-nix-project).@@ -210,7 +212,7 @@ ``` niv - dependency manager for Nix projects -version: 0.2.21+version: 0.2.22 Usage: niv [-s|--sources-file FILE] [--no-colors] COMMAND @@ -245,6 +247,7 @@ (-b|--branch BRANCH) | (-o|--owner OWNER) | (-r|--rev REV) | (-v|--version VERSION) | (-t|--template URL) | (-T|--type TYPE)]+ Add a GitHub dependency Available options:@@ -285,6 +288,7 @@ (-o|--owner OWNER) | (-r|--rev REV) | (-v|--version VERSION) | (-t|--template URL) | (-T|--type TYPE)]]+ Update dependencies Available options:@@ -317,6 +321,7 @@ (-b|--branch BRANCH) | (-o|--owner OWNER) | (-r|--rev REV) | (-v|--version VERSION) | (-t|--template URL) | (-T|--type TYPE)]+ Modify dependency attributes without performing an update Available options:@@ -346,6 +351,7 @@ niv drop my-package version Usage: niv drop PACKAGE [ATTRIBUTE]+ Drop dependency Available options:@@ -358,6 +364,7 @@ Usage: niv init [--fast | --latest | --nixpkgs OWNER/REPO (-b|--nixpkgs-branch ARG) | --no-nixpkgs]+ Initialize a Nix project. Existing files won't be modified. Available options:
niv.cabal view
@@ -1,11 +1,11 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.34.6.+-- This file has been generated from package.yaml by hpack version 0.35.2. -- -- see: https://github.com/sol/hpack name: niv-version: 0.2.21+version: 0.2.22 synopsis: Easy dependency management for Nix projects description: Easy dependency management for Nix projects. category: Development
nix/sources.nix view
@@ -10,33 +10,34 @@ let name' = sanitizeName name + "-src"; in- if spec.builtin or true then- builtins_fetchurl { inherit (spec) url sha256; name = name'; }- else- pkgs.fetchurl { inherit (spec) url sha256; name = name'; };+ if spec.builtin or true then+ builtins_fetchurl { inherit (spec) url sha256; name = name'; }+ else+ pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; fetch_tarball = pkgs: name: spec: let name' = sanitizeName name + "-src"; in- if spec.builtin or true then- builtins_fetchTarball { name = name'; inherit (spec) url sha256; }- else- pkgs.fetchzip { name = name'; inherit (spec) url sha256; };+ if spec.builtin or true then+ builtins_fetchTarball { name = name'; inherit (spec) url sha256; }+ else+ pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; fetch_git = name: spec: let ref =- if spec ? ref then spec.ref else+ spec.ref or ( if spec ? branch then "refs/heads/${spec.branch}" else- if spec ? tag then "refs/tags/${spec.tag}" else- abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!";- submodules = if spec ? submodules then spec.submodules else false;+ if spec ? tag then "refs/tags/${spec.tag}" else+ abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!"+ );+ submodules = spec.submodules or false; submoduleArg = let nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0; emptyArgWithWarning =- if submodules == true+ if submodules then builtins.trace (@@ -44,15 +45,15 @@ + "but your nix's (${builtins.nixVersion}) builtins.fetchGit " + "does not support them" )- {}- else {};+ { }+ else { }; in- if nixSupportsSubmodules- then { inherit submodules; }- else emptyArgWithWarning;+ if nixSupportsSubmodules+ then { inherit submodules; }+ else emptyArgWithWarning; in- builtins.fetchGit- ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg);+ builtins.fetchGit+ ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); fetch_local = spec: spec.path; @@ -86,16 +87,16 @@ hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; hasThisAsNixpkgsPath = <nixpkgs> == ./.; in- if builtins.hasAttr "nixpkgs" sources- then sourcesNixpkgs- else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then- import <nixpkgs> {}- else- abort- ''- Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or- add a package called "nixpkgs" to your sources.json.- '';+ if builtins.hasAttr "nixpkgs" sources+ then sourcesNixpkgs+ else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then+ import <nixpkgs> { }+ else+ abort+ ''+ Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or+ add a package called "nixpkgs" to your sources.json.+ ''; # The actual fetching function. fetch = pkgs: name: spec:@@ -115,13 +116,13 @@ # the path directly as opposed to the fetched source. replace = name: drv: let- saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name;+ saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; in- if ersatz == "" then drv else- # this turns the string into an actual Nix path (for both absolute and- # relative paths)- if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}";+ if ersatz == "" then drv else+ # this turns the string into an actual Nix path (for both absolute and+ # relative paths)+ if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; # Ports of functions for older nix versions @@ -132,7 +133,7 @@ ); # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295- range = first: last: if first > last then [] else builtins.genList (n: first + n) (last - first + 1);+ range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1));@@ -143,43 +144,46 @@ concatStrings = builtins.concatStringsSep ""; # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331- optionalAttrs = cond: as: if cond then as else {};+ optionalAttrs = cond: as: if cond then as else { }; # fetchTarball version that is compatible between all the versions of Nix builtins_fetchTarball = { url, name ? null, sha256 }@attrs: let inherit (builtins) lessThan nixVersion fetchTarball; in- if lessThan nixVersion "1.12" then- fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))- else- fetchTarball attrs;+ if lessThan nixVersion "1.12" then+ fetchTarball ({ inherit url; } // (optionalAttrs (name != null) { inherit name; }))+ else+ fetchTarball attrs; # fetchurl version that is compatible between all the versions of Nix builtins_fetchurl = { url, name ? null, sha256 }@attrs: let inherit (builtins) lessThan nixVersion fetchurl; in- if lessThan nixVersion "1.12" then- fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))- else- fetchurl attrs;+ if lessThan nixVersion "1.12" then+ fetchurl ({ inherit url; } // (optionalAttrs (name != null) { inherit name; }))+ else+ fetchurl attrs; # Create the final "sources" from the config mkSources = config:- mapAttrs (- name: spec:- if builtins.hasAttr "outPath" spec- then abort- "The values in sources.json should not have an 'outPath' attribute"- else- spec // { outPath = replace name (fetch config.pkgs name spec); }- ) config.sources;+ mapAttrs+ (+ name: spec:+ if builtins.hasAttr "outPath" spec+ then+ abort+ "The values in sources.json should not have an 'outPath' attribute"+ else+ spec // { outPath = replace name (fetch config.pkgs name spec); }+ )+ config.sources; # The "config" used by the fetchers mkConfig = { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null- , sources ? if isNull sourcesFile then {} else builtins.fromJSON (builtins.readFile sourcesFile)+ , sources ? if sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile) , system ? builtins.currentSystem , pkgs ? mkPkgs sources system }: rec {@@ -191,4 +195,4 @@ }; in-mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); }+mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); }
src/Niv/Cli.hs view
@@ -164,13 +164,13 @@ <> Opts.metavar "OWNER/REPO" ) )- <*> ( Opts.strOption- ( Opts.long "nixpkgs-branch"- <> Opts.short 'b'- <> Opts.help "The nixpkgs branch when using --nixpkgs ...."- <> Opts.showDefault- )- )+ <*> ( Opts.strOption+ ( Opts.long "nixpkgs-branch"+ <> Opts.short 'b'+ <> Opts.help "The nixpkgs branch when using --nixpkgs ...."+ <> Opts.showDefault+ )+ ) parseNoNixpkgs = Opts.flag' NoNixpkgs
src/Niv/Git/Cmd.hs view
@@ -67,9 +67,12 @@ else Nothing where isGitURL =- ".git" `T.isSuffixOf` txt- || "git@" `T.isPrefixOf` txt- || "ssh://" `T.isPrefixOf` txt+ ".git"+ `T.isSuffixOf` txt+ || "git@"+ `T.isPrefixOf` txt+ || "ssh://"+ `T.isPrefixOf` txt parseGitPackageSpec :: Opts.Parser PackageSpec parseGitPackageSpec =@@ -115,7 +118,7 @@ fromMaybe (Aeson.toJSON x) (Aeson.decodeStrict (B8.pack x)) -- Parse "key=val" into ("key", val) parseKeyVal ::- -- | how to convert to JSON+ -- how to convert to JSON (String -> Aeson.Value) -> String -> Maybe (K.Key, Aeson.Value)
src/Niv/GitHub/API.hs view
@@ -80,17 +80,17 @@ defaultRequest (map T.encodeUtf8 -> parts) = do let path = T.encodeUtf8 githubPath <> BS8.intercalate "/" (parts) mtoken <- lookupEnv' "GITHUB_TOKEN"- pure $- ( flip (maybe id) mtoken $ \token ->- HTTP.addRequestHeader "authorization" ("token " <> BS8.pack token)- )- $ HTTP.setRequestPath path $- HTTP.addRequestHeader "user-agent" "niv" $- HTTP.addRequestHeader "accept" "application/vnd.github.v3+json" $- HTTP.setRequestSecure githubSecure $- HTTP.setRequestHost (T.encodeUtf8 githubApiHost) $- HTTP.setRequestPort githubApiPort $- HTTP.defaultRequest+ pure+ $ ( flip (maybe id) mtoken $ \token ->+ HTTP.addRequestHeader "authorization" ("token " <> BS8.pack token)+ )+ $ HTTP.setRequestPath path+ $ HTTP.addRequestHeader "user-agent" "niv"+ $ HTTP.addRequestHeader "accept" "application/vnd.github.v3+json"+ $ HTTP.setRequestSecure githubSecure+ $ HTTP.setRequestHost (T.encodeUtf8 githubApiHost)+ $ HTTP.setRequestPort githubApiPort+ $ HTTP.defaultRequest -- | Get the latest revision for owner, repo and branch. -- TODO: explain no error handling@@ -129,7 +129,7 @@ For more information on rate-limiting, see - https://developer.github.com/v3/#rate-limiting+ https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting |]
src/Niv/GitHub/Cmd.hs view
@@ -86,7 +86,7 @@ fromMaybe (Aeson.toJSON x) (Aeson.decodeStrict (B8.pack x)) -- Parse "key=val" into ("key", val) parseKeyVal ::- -- | how to convert to JSON+ -- how to convert to JSON (String -> Aeson.Value) -> String -> Maybe (K.Key, Aeson.Value)
src/Niv/Sources.hs view
@@ -178,6 +178,9 @@ V26 | -- Support submodules for git repos V27+ | -- formatting fix+ -- Apply statix suggestions+ V28 deriving stock (Bounded, Enum, Eq) -- | A user friendly version@@ -210,6 +213,7 @@ V25 -> "25" V26 -> "26" V27 -> "27"+ V28 -> "28" latestVersionMD5 :: T.Text latestVersionMD5 = sourcesVersionToMD5 maxBound@@ -249,6 +253,7 @@ V25 -> "6612caee5814670e5e4d9dd1b71b5f70" V26 -> "937bff93370a064c9000f13cec5867f9" V27 -> "8031ba9d8fbbc7401c800d0b84278ec8"+ V28 -> "26ed55356db7673935329210a4f8c4a5" -- | The MD5 sum of ./nix/sources.nix sourcesNixMD5 :: IO T.Text@@ -276,20 +281,20 @@ | v == maxBound -> pure () -- The file is older than than latest | otherwise -> do- tsay $- T.unlines- [ T.unwords- [ tbold $ tblue "INFO:",- "new sources.nix available:",- sourcesVersionToText v,- "->",- sourcesVersionToText maxBound- ],- " Please run 'niv init' or add the following line in the "- <> T.pack pathNixSourcesNix- <> " file:",- " # niv: no_update"- ]+ tsay $+ T.unlines+ [ T.unwords+ [ tbold $ tblue "INFO:",+ "new sources.nix available:",+ sourcesVersionToText v,+ "->",+ sourcesVersionToText maxBound+ ],+ " Please run 'niv init' or add the following line in the "+ <> T.pack pathNixSourcesNix+ <> " file:",+ " # niv: no_update"+ ] -- | Glue code between nix and sources.json initNixSourcesNixContent :: B.ByteString