1
1
mirror of https://github.com/nmattia/niv.git synced 2024-11-22 03:27:10 +03:00

Update devshell (#367)

* Update devshell

Update nixpkgs and simplify devshell

* Run ormolu

* Fixups

* Format nix files

* Update sources
This commit is contained in:
Nicolas Mattia 2023-03-11 22:16:53 +01:00 committed by GitHub
parent 320689d737
commit de5a4e7d01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 264 additions and 256 deletions

View File

@ -247,6 +247,7 @@ Usage: niv add PACKAGE [-n|--name NAME]
(-b|--branch BRANCH) | (-o|--owner OWNER) | (-r|--rev REV) |
(-v|--version VERSION) | (-t|--template URL) |
(-T|--type TYPE)]
Add a GitHub dependency
Available options:
@ -287,6 +288,7 @@ Usage: niv update [PACKAGE
(-o|--owner OWNER) | (-r|--rev REV) |
(-v|--version VERSION) | (-t|--template URL) |
(-T|--type TYPE)]]
Update dependencies
Available options:
@ -319,6 +321,7 @@ Usage: niv modify PACKAGE [-n|--name NAME]
(-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:
@ -348,6 +351,7 @@ Examples:
niv drop my-package version
Usage: niv drop PACKAGE [ATTRIBUTE]
Drop dependency
Available options:
@ -360,6 +364,7 @@ Available options:
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:

View File

@ -3,7 +3,7 @@
}:
let
files = pkgs.callPackage ./nix/files.nix {};
files = pkgs.callPackage ./nix/files.nix { };
sourceByRegex = name: src: regexes:
builtins.path {
@ -13,7 +13,7 @@ let
relPath = pkgs.lib.removePrefix (toString src + "/") (toString path);
accept = pkgs.lib.any (re: builtins.match re relPath != null) regexes;
in
accept
accept
);
inherit name;
path = src;
@ -69,10 +69,10 @@ let
let
niv-version = niv.version;
in
pkgs.writeShellScript "cabal-upload"
''
cabal upload "$@" "${niv-sdist}/niv-${niv-version}.tar.gz"
'';
pkgs.writeShellScript "cabal-upload"
''
cabal upload "$@" "${niv-sdist}/niv-${niv-version}.tar.gz"
'';
# WARNING: extremely disgusting hack below.
#
@ -147,11 +147,8 @@ let
# version from `package.yaml` and create a dummy module that we inject in the
# `ghci` command.
niv-devshell = haskellPackages.shellFor {
buildInputs = [
pkgs.nixpkgs-fmt
pkgs.haskellPackages.ormolu
];
packages = ps: [ ps.niv ];
buildInputs = [ pkgs.ormolu pkgs.glibcLocales ];
shellHook = ''
repl_for() {
haskell_version=$(jq <./package.yaml -cMr '.version' | sed 's/\./,/g')
@ -196,7 +193,7 @@ rec
tests-github = pkgs.callPackage ./tests/github { inherit niv; };
tests-git = pkgs.callPackage ./tests/git { inherit niv; };
tests-eval = pkgs.callPackage ./tests/eval {};
tests-eval = pkgs.callPackage ./tests/eval { };
fmt-check =
pkgs.stdenv.mkDerivation
@ -245,7 +242,7 @@ rec
echo done
'';
readme-test = pkgs.runCommand "README-test" {}
readme-test = pkgs.runCommand "README-test" { }
''
err() {
echo
@ -258,7 +255,7 @@ rec
diff ${./README.md} ${readme} && echo dummy > $out || err ;
'';
niv-svg-test = pkgs.runCommand "niv-svg-test" {}
niv-svg-test = pkgs.runCommand "niv-svg-test" { }
''
# XXX: This test means that the svg needs to be regenerated
# by hand on (virtually) every commit.

View File

@ -7,31 +7,31 @@ let
];
};
in
with pkgs;
with pkgs;
stdenv.mkDerivation {
name = "nix-cpp-demo";
nativeBuildInputs = [ cmake pkgconfig ];
src = pkgs.lib.cleanSource ./.;
stdenv.mkDerivation {
name = "nix-cpp-demo";
nativeBuildInputs = [ cmake pkgconfig ];
src = pkgs.lib.cleanSource ./.;
# tell Cmake location of all headers
cmakeFlags = [
"-DEXTERNAL_INCLUDE_DIRECTORIES=${lib.strings.makeSearchPathOutput "dev" "include" libosmium.buildInputs}"
];
# tell Cmake location of all headers
cmakeFlags = [
"-DEXTERNAL_INCLUDE_DIRECTORIES=${lib.strings.makeSearchPathOutput "dev" "include" libosmium.buildInputs}"
];
buildInputs = lib.lists.concatLists [
# We want to check if dependencies exist using find_package
[
libosmium.buildInputs
]
# dependencies
[
libosmium
]
];
buildInputs = lib.lists.concatLists [
# We want to check if dependencies exist using find_package
[
libosmium.buildInputs
]
# dependencies
[
libosmium
]
];
installPhase = ''
mkdir -p $out/bin
cp bin/hello-world $out/bin
'';
}
installPhase = ''
mkdir -p $out/bin
cp bin/hello-world $out/bin
'';
}

View File

@ -30,7 +30,8 @@ let
$ niv modify <package> -a type=tarball -a builtin=true
''
builtins_fetchTarball { inherit (spec) url sha256; };
builtins_fetchTarball
{ inherit (spec) url sha256; };
fetch_builtin-url = spec:
builtins.trace
@ -52,19 +53,20 @@ let
if hasNixpkgsPath
then
if hasThisAsNixpkgsPath
then import (builtins_fetchTarball { inherit (mkNixpkgs sources) url sha256; }) {}
else import <nixpkgs> {}
then import (builtins_fetchTarball { inherit (mkNixpkgs sources) url sha256; }) { }
else import <nixpkgs> { }
else
import (builtins_fetchTarball { inherit (mkNixpkgs sources) url sha256; }) {};
import (builtins_fetchTarball { inherit (mkNixpkgs sources) url sha256; }) { };
mkNixpkgs = sources:
if builtins.hasAttr "nixpkgs" sources
then sources.nixpkgs
else abort
''
Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
add a package called "nixpkgs" to your sources.json.
'';
else
abort
''
Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
add a package called "nixpkgs" to your sources.json.
'';
hasNixpkgsPath = (builtins.tryEval <nixpkgs>).success;
hasThisAsNixpkgsPath =
@ -96,31 +98,34 @@ let
let
inherit (builtins) lessThan nixVersion fetchTarball;
in
if lessThan nixVersion "1.12" then
fetchTarball { inherit url; }
else
fetchTarball attrs;
if lessThan nixVersion "1.12" then
fetchTarball { inherit url; }
else
fetchTarball attrs;
# fetchurl version that is compatible between all the versions of Nix
builtins_fetchurl = { url, sha256 }@attrs:
let
inherit (builtins) lessThan nixVersion fetchurl;
in
if lessThan nixVersion "1.12" then
fetchurl { inherit url; }
else
fetchurl attrs;
if lessThan nixVersion "1.12" then
fetchurl { inherit url; }
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 = 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 = fetch config.pkgs name spec; }
)
config.sources;
# The "config" used by the fetchers
mkConfig =
@ -135,4 +140,4 @@ let
inherit pkgs;
};
in
mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); }
mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); }

View File

@ -1,3 +1,3 @@
self: super: {
libosmium = self.callPackage ./overlay/libosmium.nix {};
libosmium = self.callPackage ./overlay/libosmium.nix { };
}

View File

@ -6,78 +6,82 @@
{
buildPackage =
attrs:
let
src = if !lib.isDerivation attrs && lib.isAttrs attrs then attrs.src else attrs;
root = if !lib.isDerivation attrs && lib.isAttrs attrs then attrs.root else attrs;
nubdeps = ds: lib.lists.sort (x: y: x < y) (
lib.unique (
map (d: lib.head (lib.splitString " " d)) ds
let
src = if !lib.isDerivation attrs && lib.isAttrs attrs then attrs.src else attrs;
root = if !lib.isDerivation attrs && lib.isAttrs attrs then attrs.root else attrs;
nubdeps = ds: lib.lists.sort (x: y: x < y) (
lib.unique (
map (d: lib.head (lib.splitString " " d)) ds
)
);
spec = builtins.fromJSON (builtins.readFile (root + "/package.yaml"));
commonDeps = spec.dependencies;
libraryExtraDeps =
lib.optionals
(spec ? library && spec.library ? dependencies)
spec.library.dependencies;
libraryDeps = nubdeps (commonDeps ++ libraryExtraDeps);
exeExtraDeps = lib.optionals (spec ? executables) (
lib.concatMap
(
exe: lib.optionals
(exe ? dependencies)
exe.dependencies
)
);
spec = builtins.fromJSON (builtins.readFile (root + "/package.yaml"));
commonDeps = spec.dependencies;
libraryExtraDeps =
lib.optionals
(spec ? library && spec.library ? dependencies)
spec.library.dependencies;
libraryDeps = nubdeps (commonDeps ++ libraryExtraDeps);
exeExtraDeps = lib.optionals (spec ? executables) (
lib.concatMap
(
exe: lib.optionals
(exe ? dependencies) exe.dependencies
)
(builtins.attrValues spec.executables)
);
exeDeps =
nubdeps
(
builtins.filter (x: x != spec.name)
(commonDeps ++ exeExtraDeps)
);
testExtraDeps = lib.optionals (spec ? tests) (
lib.concatMap
(
test: lib.optionals
(test ? dependencies) test.dependencies
)
(builtins.attrValues spec.tests)
);
testDeps = nubdeps (builtins.filter (x: x != spec.name) (commonDeps ++ testExtraDeps));
depsFor = depType:
map (
d:
if ! builtins.hasAttr d haskellPackages
then throw "haskellPackages does not contain dependency '${d}' needed for '${depType}'"
else
haskellPackages.${d}
(builtins.attrValues spec.executables)
);
exeDeps =
nubdeps
(
builtins.filter (x: x != spec.name)
(commonDeps ++ exeExtraDeps)
);
in
haskellPackages.callPackage (
{ mkDerivation }:
mkDerivation {
pname = spec.name;
version = spec.version;
inherit src;
isLibrary = builtins.hasAttr "library" spec;
isExecutable = builtins.hasAttr "executables" spec;
enableSeparateDataOutput = true;
libraryHaskellDepends = depsFor "libraryHaskellDepends" libraryDeps;
libraryToolDepends = [ haskellPackages.hpack ];
executableHaskellDepends = depsFor "executableHaskellDepends" exeDeps;
testHaskellDepends = depsFor "testHaskellDepends" testDeps;
prePatch = "hpack";
homepage = "https://github.com/${spec.github}#readme";
description = spec.synopsis;
license =
if builtins.hasAttr "license" spec && spec.license == "MIT"
then lib.licenses.mit
else throw "Don't know how to handle license: ${builtins.toJSON spec.license}";
}
) {};
testExtraDeps = lib.optionals (spec ? tests) (
lib.concatMap
(
test: lib.optionals
(test ? dependencies)
test.dependencies
)
(builtins.attrValues spec.tests)
);
testDeps = nubdeps (builtins.filter (x: x != spec.name) (commonDeps ++ testExtraDeps));
depsFor = depType:
map (
d:
if ! builtins.hasAttr d haskellPackages
then throw "haskellPackages does not contain dependency '${d}' needed for '${depType}'"
else
haskellPackages.${d}
);
in
haskellPackages.callPackage
(
{ mkDerivation }:
mkDerivation {
pname = spec.name;
version = spec.version;
inherit src;
isLibrary = builtins.hasAttr "library" spec;
isExecutable = builtins.hasAttr "executables" spec;
enableSeparateDataOutput = true;
libraryHaskellDepends = depsFor "libraryHaskellDepends" libraryDeps;
libraryToolDepends = [ haskellPackages.hpack ];
executableHaskellDepends = depsFor "executableHaskellDepends" exeDeps;
testHaskellDepends = depsFor "testHaskellDepends" testDeps;
prePatch = "hpack";
homepage = "https://github.com/${spec.github}#readme";
description = spec.synopsis;
license =
if builtins.hasAttr "license" spec && spec.license == "MIT"
then lib.licenses.mit
else throw "Don't know how to handle license: ${builtins.toJSON spec.license}";
}
)
{ };
}

View File

@ -2,8 +2,7 @@
import sources.nixpkgs {
overlays = [
(_: pkgs: { inherit sources; })
(_: pkgs: { nixpkgs-fmt = import pkgs.sources.nixpkgs-fmt {}; })
(_: pkgs: { termtosvg = pkgs.callPackage ./termtosvg.nix {}; })
(_: pkgs: { termtosvg = pkgs.callPackage ./termtosvg.nix { }; })
];
config = {};
config = { };
}

View File

@ -5,22 +5,10 @@
"homepage": null,
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "6844c91781fdad8ad523b77ec9d1f35ff407a8e6",
"sha256": "199d0g2i3aph2c7sjkngr722l9yqzk40b7wr6dklnx4pxssgwbrp",
"rev": "5d6d90c3bf3d95902427c64dae883715de1fae19",
"sha256": "027l7f1533wb8cb55dq11dfvkpi48s5m15cq3aj0f84m715682vn",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/6844c91781fdad8ad523b77ec9d1f35ff407a8e6.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"nixpkgs-fmt": {
"branch": "master",
"description": "Nix code formatter for nixpkgs [maintainer=@zimbatm]",
"homepage": "https://nix-community.github.io/nixpkgs-fmt/",
"owner": "nix-community",
"repo": "nixpkgs-fmt",
"rev": "2a64f4b6a597d0d62004ffcec3ae4fd83cd1efc8",
"sha256": "01kx4y1d4c5fjvpcffk92pk9hdbgg5j9h2ryqy2hfm54s7mb0k63",
"type": "tarball",
"url": "https://github.com/nix-community/nixpkgs-fmt/archive/2a64f4b6a597d0d62004ffcec3ae4fd83cd1efc8.tar.gz",
"url": "https://github.com/NixOS/nixpkgs/archive/5d6d90c3bf3d95902427c64dae883715de1fae19.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"termtosvg": {

View File

@ -10,27 +10,27 @@ let
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
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`!";
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;
submoduleArg =
let
@ -44,15 +44,15 @@ let
+ "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 +86,16 @@ let
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:
@ -118,10 +118,10 @@ let
saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) 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 +132,7 @@ let
);
# 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 +143,46 @@ let
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 (!isNull name) { 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 (!isNull name) { 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 isNull sourcesFile then { } else builtins.fromJSON (builtins.readFile sourcesFile)
, system ? builtins.currentSystem
, pkgs ? mkPkgs sources system
}: rec {
@ -191,4 +194,4 @@ let
};
in
mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); }
mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); }

View File

@ -30,7 +30,7 @@ fmt() {
for f in $(find . -name '*.hs')
do
echo "checking: $f"
if ! ormolu --mode "$mode" "$f"; then
if ! ormolu --no-cabal --mode "$mode" "$f"; then
needs_formatting+=( "$f" )
fi
done

View File

@ -1,2 +1,2 @@
{ pkgs ? import ./nix {} }:
{ pkgs ? import ./nix { } }:
(import ./default.nix { inherit pkgs; }).niv-devshell

View File

@ -164,13 +164,13 @@ parseNixpkgs = parseNixpkgsFast <|> parseNixpkgsLatest <|> parseNixpkgsCustom <|
<> 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

View File

@ -67,9 +67,12 @@ parseGitShortcut txt'@(T.dropWhileEnd (== '/') -> txt) =
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 =

View File

@ -80,17 +80,17 @@ defaultRequest :: [T.Text] -> IO HTTP.Request
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

View File

@ -178,6 +178,8 @@ data SourcesNixVersion
V26
| -- Support submodules for git repos
V27
| -- formatting fix
V28
deriving stock (Bounded, Enum, Eq)
-- | A user friendly version
@ -210,6 +212,7 @@ sourcesVersionToText = \case
V25 -> "25"
V26 -> "26"
V27 -> "27"
V28 -> "28"
latestVersionMD5 :: T.Text
latestVersionMD5 = sourcesVersionToMD5 maxBound
@ -249,6 +252,7 @@ sourcesVersionToMD5 = \case
V25 -> "6612caee5814670e5e4d9dd1b71b5f70"
V26 -> "937bff93370a064c9000f13cec5867f9"
V27 -> "8031ba9d8fbbc7401c800d0b84278ec8"
V28 -> "2ed0d91d652b28d99f14659144a0af28"
-- | The MD5 sum of ./nix/sources.nix
sourcesNixMD5 :: IO T.Text
@ -276,20 +280,20 @@ warnIfOutdated = do
| 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

View File

@ -1,4 +1,4 @@
{ pkgs ? import <nixpkgs> {}
{ pkgs ? import <nixpkgs> { }
}:
@ -72,7 +72,7 @@ mkTest "niv-override-eval" ''
eq "$res" "hello"
''
// mkTest "sanitize-source-name"
// mkTest "sanitize-source-name"
''
file=$(mktemp -d)/foo%%.bar
touch "$file"

View File

@ -3,7 +3,7 @@
# TODO: this doesn' test anything meaningful yet because "niv git PACKAGE"
# doesn't parse yet
pkgs.runCommand "git-test"
{ nativeBuildInputs = [ pkgs.git niv pkgs.nix pkgs.jq ]; }
{ nativeBuildInputs = [ pkgs.git niv pkgs.nix pkgs.jq ]; }
(
# make sure the tests run smoothly in multi-user install
@ -35,8 +35,8 @@ pkgs.runCommand "git-test"
git checkout master
popd > /dev/null
'' + # Then we `niv add` that repo and check some properties, like the revision
# and revCount, to make sure it was imported properly, and that sources.nix
# does what it's supposed to do.
# and revCount, to make sure it was imported properly, and that sources.nix
# does what it's supposed to do.
''
nivdir=$(mktemp -d)
pushd $nivdir > /dev/null

View File

@ -20,15 +20,15 @@ let
nixpkgs-channels_HEAD = "571b40d3f50466d3e91c1e609d372de96d782793";
in
pkgs.runCommand "test"
{
buildInputs = [
pkgs.haskellPackages.wai-app-static
niv
pkgs.nix
pkgs.jq
pkgs.netcat-gnu
];
}
{
buildInputs = [
pkgs.haskellPackages.wai-app-static
niv
pkgs.nix
pkgs.jq
pkgs.netcat-gnu
];
}
''
set -euo pipefail