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) | (-b|--branch BRANCH) | (-o|--owner OWNER) | (-r|--rev REV) |
(-v|--version VERSION) | (-t|--template URL) | (-v|--version VERSION) | (-t|--template URL) |
(-T|--type TYPE)] (-T|--type TYPE)]
Add a GitHub dependency Add a GitHub dependency
Available options: Available options:
@ -287,6 +288,7 @@ Usage: niv update [PACKAGE
(-o|--owner OWNER) | (-r|--rev REV) | (-o|--owner OWNER) | (-r|--rev REV) |
(-v|--version VERSION) | (-t|--template URL) | (-v|--version VERSION) | (-t|--template URL) |
(-T|--type TYPE)]] (-T|--type TYPE)]]
Update dependencies Update dependencies
Available options: Available options:
@ -319,6 +321,7 @@ Usage: niv modify PACKAGE [-n|--name NAME]
(-b|--branch BRANCH) | (-o|--owner OWNER) | (-r|--rev REV) | (-b|--branch BRANCH) | (-o|--owner OWNER) | (-r|--rev REV) |
(-v|--version VERSION) | (-t|--template URL) | (-v|--version VERSION) | (-t|--template URL) |
(-T|--type TYPE)] (-T|--type TYPE)]
Modify dependency attributes without performing an update Modify dependency attributes without performing an update
Available options: Available options:
@ -348,6 +351,7 @@ Examples:
niv drop my-package version niv drop my-package version
Usage: niv drop PACKAGE [ATTRIBUTE] Usage: niv drop PACKAGE [ATTRIBUTE]
Drop dependency Drop dependency
Available options: Available options:
@ -360,6 +364,7 @@ Available options:
Usage: niv init [--fast | --latest | --nixpkgs OWNER/REPO Usage: niv init [--fast | --latest | --nixpkgs OWNER/REPO
(-b|--nixpkgs-branch ARG) | (-b|--nixpkgs-branch ARG) |
--no-nixpkgs] --no-nixpkgs]
Initialize a Nix project. Existing files won't be modified. Initialize a Nix project. Existing files won't be modified.
Available options: Available options:

View File

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

View File

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

View File

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

View File

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

View File

@ -6,78 +6,82 @@
{ {
buildPackage = buildPackage =
attrs: attrs:
let let
src = if !lib.isDerivation attrs && lib.isAttrs attrs then attrs.src else attrs; 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; root = if !lib.isDerivation attrs && lib.isAttrs attrs then attrs.root else attrs;
nubdeps = ds: lib.lists.sort (x: y: x < y) ( nubdeps = ds: lib.lists.sort (x: y: x < y) (
lib.unique ( lib.unique (
map (d: lib.head (lib.splitString " " d)) ds 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
) )
); (builtins.attrValues spec.executables)
spec = builtins.fromJSON (builtins.readFile (root + "/package.yaml")); );
commonDeps = spec.dependencies; exeDeps =
nubdeps
libraryExtraDeps = (
lib.optionals builtins.filter (x: x != spec.name)
(spec ? library && spec.library ? dependencies) (commonDeps ++ exeExtraDeps)
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}
); );
in testExtraDeps = lib.optionals (spec ? tests) (
haskellPackages.callPackage ( lib.concatMap
{ mkDerivation }: (
mkDerivation { test: lib.optionals
pname = spec.name; (test ? dependencies)
version = spec.version; test.dependencies
inherit src; )
isLibrary = builtins.hasAttr "library" spec; (builtins.attrValues spec.tests)
isExecutable = builtins.hasAttr "executables" spec; );
enableSeparateDataOutput = true; testDeps = nubdeps (builtins.filter (x: x != spec.name) (commonDeps ++ testExtraDeps));
libraryHaskellDepends = depsFor "libraryHaskellDepends" libraryDeps;
libraryToolDepends = [ haskellPackages.hpack ]; depsFor = depType:
executableHaskellDepends = depsFor "executableHaskellDepends" exeDeps; map (
testHaskellDepends = depsFor "testHaskellDepends" testDeps; d:
prePatch = "hpack"; if ! builtins.hasAttr d haskellPackages
homepage = "https://github.com/${spec.github}#readme"; then throw "haskellPackages does not contain dependency '${d}' needed for '${depType}'"
description = spec.synopsis; else
license = haskellPackages.${d}
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}"; 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 { import sources.nixpkgs {
overlays = [ overlays = [
(_: pkgs: { inherit sources; }) (_: 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, "homepage": null,
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "6844c91781fdad8ad523b77ec9d1f35ff407a8e6", "rev": "5d6d90c3bf3d95902427c64dae883715de1fae19",
"sha256": "199d0g2i3aph2c7sjkngr722l9yqzk40b7wr6dklnx4pxssgwbrp", "sha256": "027l7f1533wb8cb55dq11dfvkpi48s5m15cq3aj0f84m715682vn",
"type": "tarball", "type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/6844c91781fdad8ad523b77ec9d1f35ff407a8e6.tar.gz", "url": "https://github.com/NixOS/nixpkgs/archive/5d6d90c3bf3d95902427c64dae883715de1fae19.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_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz" "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
}, },
"termtosvg": { "termtosvg": {

View File

@ -10,27 +10,27 @@ let
let let
name' = sanitizeName name + "-src"; name' = sanitizeName name + "-src";
in in
if spec.builtin or true then if spec.builtin or true then
builtins_fetchurl { inherit (spec) url sha256; name = name'; } builtins_fetchurl { inherit (spec) url sha256; name = name'; }
else else
pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; pkgs.fetchurl { inherit (spec) url sha256; name = name'; };
fetch_tarball = pkgs: name: spec: fetch_tarball = pkgs: name: spec:
let let
name' = sanitizeName name + "-src"; name' = sanitizeName name + "-src";
in in
if spec.builtin or true then if spec.builtin or true then
builtins_fetchTarball { name = name'; inherit (spec) url sha256; } builtins_fetchTarball { name = name'; inherit (spec) url sha256; }
else else
pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; pkgs.fetchzip { name = name'; inherit (spec) url sha256; };
fetch_git = name: spec: fetch_git = name: spec:
let let
ref = ref =
if spec ? ref then spec.ref else if spec ? ref then spec.ref else
if spec ? branch then "refs/heads/${spec.branch}" else if spec ? branch then "refs/heads/${spec.branch}" else
if spec ? tag then "refs/tags/${spec.tag}" else if spec ? tag then "refs/tags/${spec.tag}" else
abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!"; abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!";
submodules = if spec ? submodules then spec.submodules else false; submodules = if spec ? submodules then spec.submodules else false;
submoduleArg = submoduleArg =
let let
@ -44,15 +44,15 @@ let
+ "but your nix's (${builtins.nixVersion}) builtins.fetchGit " + "but your nix's (${builtins.nixVersion}) builtins.fetchGit "
+ "does not support them" + "does not support them"
) )
{} { }
else {}; else { };
in in
if nixSupportsSubmodules if nixSupportsSubmodules
then { inherit submodules; } then { inherit submodules; }
else emptyArgWithWarning; else emptyArgWithWarning;
in in
builtins.fetchGit builtins.fetchGit
({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg);
fetch_local = spec: spec.path; fetch_local = spec: spec.path;
@ -86,16 +86,16 @@ let
hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath;
hasThisAsNixpkgsPath = <nixpkgs> == ./.; hasThisAsNixpkgsPath = <nixpkgs> == ./.;
in in
if builtins.hasAttr "nixpkgs" sources if builtins.hasAttr "nixpkgs" sources
then sourcesNixpkgs then sourcesNixpkgs
else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then
import <nixpkgs> {} import <nixpkgs> { }
else else
abort abort
'' ''
Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
add a package called "nixpkgs" to your sources.json. add a package called "nixpkgs" to your sources.json.
''; '';
# The actual fetching function. # The actual fetching function.
fetch = pkgs: name: spec: 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; saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name;
ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}";
in in
if ersatz == "" then drv else if ersatz == "" then drv else
# this turns the string into an actual Nix path (for both absolute and # this turns the string into an actual Nix path (for both absolute and
# relative paths) # relative paths)
if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}";
# Ports of functions for older nix versions # Ports of functions for older nix versions
@ -132,7 +132,7 @@ let
); );
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 # 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 # 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)); stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1));
@ -143,43 +143,46 @@ let
concatStrings = builtins.concatStringsSep ""; concatStrings = builtins.concatStringsSep "";
# https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 # 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 # fetchTarball version that is compatible between all the versions of Nix
builtins_fetchTarball = { url, name ? null, sha256 }@attrs: builtins_fetchTarball = { url, name ? null, sha256 }@attrs:
let let
inherit (builtins) lessThan nixVersion fetchTarball; inherit (builtins) lessThan nixVersion fetchTarball;
in in
if lessThan nixVersion "1.12" then if lessThan nixVersion "1.12" then
fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
else else
fetchTarball attrs; fetchTarball attrs;
# fetchurl version that is compatible between all the versions of Nix # fetchurl version that is compatible between all the versions of Nix
builtins_fetchurl = { url, name ? null, sha256 }@attrs: builtins_fetchurl = { url, name ? null, sha256 }@attrs:
let let
inherit (builtins) lessThan nixVersion fetchurl; inherit (builtins) lessThan nixVersion fetchurl;
in in
if lessThan nixVersion "1.12" then if lessThan nixVersion "1.12" then
fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
else else
fetchurl attrs; fetchurl attrs;
# Create the final "sources" from the config # Create the final "sources" from the config
mkSources = config: mkSources = config:
mapAttrs ( mapAttrs
name: spec: (
if builtins.hasAttr "outPath" spec name: spec:
then abort if builtins.hasAttr "outPath" spec
"The values in sources.json should not have an 'outPath' attribute" then
else abort
spec // { outPath = replace name (fetch config.pkgs name spec); } "The values in sources.json should not have an 'outPath' attribute"
) config.sources; else
spec // { outPath = replace name (fetch config.pkgs name spec); }
)
config.sources;
# The "config" used by the fetchers # The "config" used by the fetchers
mkConfig = mkConfig =
{ sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null { 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 , system ? builtins.currentSystem
, pkgs ? mkPkgs sources system , pkgs ? mkPkgs sources system
}: rec { }: rec {
@ -191,4 +194,4 @@ let
}; };
in 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') for f in $(find . -name '*.hs')
do do
echo "checking: $f" echo "checking: $f"
if ! ormolu --mode "$mode" "$f"; then if ! ormolu --no-cabal --mode "$mode" "$f"; then
needs_formatting+=( "$f" ) needs_formatting+=( "$f" )
fi fi
done done

View File

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

View File

@ -164,13 +164,13 @@ parseNixpkgs = parseNixpkgsFast <|> parseNixpkgsLatest <|> parseNixpkgsCustom <|
<> Opts.metavar "OWNER/REPO" <> Opts.metavar "OWNER/REPO"
) )
) )
<*> ( Opts.strOption <*> ( Opts.strOption
( Opts.long "nixpkgs-branch" ( Opts.long "nixpkgs-branch"
<> Opts.short 'b' <> Opts.short 'b'
<> Opts.help "The nixpkgs branch when using --nixpkgs ...." <> Opts.help "The nixpkgs branch when using --nixpkgs ...."
<> Opts.showDefault <> Opts.showDefault
) )
) )
parseNoNixpkgs = parseNoNixpkgs =
Opts.flag' Opts.flag'
NoNixpkgs NoNixpkgs

View File

@ -67,9 +67,12 @@ parseGitShortcut txt'@(T.dropWhileEnd (== '/') -> txt) =
else Nothing else Nothing
where where
isGitURL = isGitURL =
".git" `T.isSuffixOf` txt ".git"
|| "git@" `T.isPrefixOf` txt `T.isSuffixOf` txt
|| "ssh://" `T.isPrefixOf` txt || "git@"
`T.isPrefixOf` txt
|| "ssh://"
`T.isPrefixOf` txt
parseGitPackageSpec :: Opts.Parser PackageSpec parseGitPackageSpec :: Opts.Parser PackageSpec
parseGitPackageSpec = parseGitPackageSpec =

View File

@ -80,17 +80,17 @@ defaultRequest :: [T.Text] -> IO HTTP.Request
defaultRequest (map T.encodeUtf8 -> parts) = do defaultRequest (map T.encodeUtf8 -> parts) = do
let path = T.encodeUtf8 githubPath <> BS8.intercalate "/" (parts) let path = T.encodeUtf8 githubPath <> BS8.intercalate "/" (parts)
mtoken <- lookupEnv' "GITHUB_TOKEN" mtoken <- lookupEnv' "GITHUB_TOKEN"
pure $ pure
( flip (maybe id) mtoken $ \token -> $ ( flip (maybe id) mtoken $ \token ->
HTTP.addRequestHeader "authorization" ("token " <> BS8.pack token) HTTP.addRequestHeader "authorization" ("token " <> BS8.pack token)
) )
$ HTTP.setRequestPath path $ $ HTTP.setRequestPath path
HTTP.addRequestHeader "user-agent" "niv" $ $ HTTP.addRequestHeader "user-agent" "niv"
HTTP.addRequestHeader "accept" "application/vnd.github.v3+json" $ $ HTTP.addRequestHeader "accept" "application/vnd.github.v3+json"
HTTP.setRequestSecure githubSecure $ $ HTTP.setRequestSecure githubSecure
HTTP.setRequestHost (T.encodeUtf8 githubApiHost) $ $ HTTP.setRequestHost (T.encodeUtf8 githubApiHost)
HTTP.setRequestPort githubApiPort $ $ HTTP.setRequestPort githubApiPort
HTTP.defaultRequest $ HTTP.defaultRequest
-- | Get the latest revision for owner, repo and branch. -- | Get the latest revision for owner, repo and branch.
-- TODO: explain no error handling -- TODO: explain no error handling

View File

@ -178,6 +178,8 @@ data SourcesNixVersion
V26 V26
| -- Support submodules for git repos | -- Support submodules for git repos
V27 V27
| -- formatting fix
V28
deriving stock (Bounded, Enum, Eq) deriving stock (Bounded, Enum, Eq)
-- | A user friendly version -- | A user friendly version
@ -210,6 +212,7 @@ sourcesVersionToText = \case
V25 -> "25" V25 -> "25"
V26 -> "26" V26 -> "26"
V27 -> "27" V27 -> "27"
V28 -> "28"
latestVersionMD5 :: T.Text latestVersionMD5 :: T.Text
latestVersionMD5 = sourcesVersionToMD5 maxBound latestVersionMD5 = sourcesVersionToMD5 maxBound
@ -249,6 +252,7 @@ sourcesVersionToMD5 = \case
V25 -> "6612caee5814670e5e4d9dd1b71b5f70" V25 -> "6612caee5814670e5e4d9dd1b71b5f70"
V26 -> "937bff93370a064c9000f13cec5867f9" V26 -> "937bff93370a064c9000f13cec5867f9"
V27 -> "8031ba9d8fbbc7401c800d0b84278ec8" V27 -> "8031ba9d8fbbc7401c800d0b84278ec8"
V28 -> "2ed0d91d652b28d99f14659144a0af28"
-- | The MD5 sum of ./nix/sources.nix -- | The MD5 sum of ./nix/sources.nix
sourcesNixMD5 :: IO T.Text sourcesNixMD5 :: IO T.Text
@ -276,20 +280,20 @@ warnIfOutdated = do
| v == maxBound -> pure () | v == maxBound -> pure ()
-- The file is older than than latest -- The file is older than than latest
| otherwise -> do | otherwise -> do
tsay $ tsay $
T.unlines T.unlines
[ T.unwords [ T.unwords
[ tbold $ tblue "INFO:", [ tbold $ tblue "INFO:",
"new sources.nix available:", "new sources.nix available:",
sourcesVersionToText v, sourcesVersionToText v,
"->", "->",
sourcesVersionToText maxBound sourcesVersionToText maxBound
], ],
" Please run 'niv init' or add the following line in the " " Please run 'niv init' or add the following line in the "
<> T.pack pathNixSourcesNix <> T.pack pathNixSourcesNix
<> " file:", <> " file:",
" # niv: no_update" " # niv: no_update"
] ]
-- | Glue code between nix and sources.json -- | Glue code between nix and sources.json
initNixSourcesNixContent :: B.ByteString 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" eq "$res" "hello"
'' ''
// mkTest "sanitize-source-name" // mkTest "sanitize-source-name"
'' ''
file=$(mktemp -d)/foo%%.bar file=$(mktemp -d)/foo%%.bar
touch "$file" touch "$file"

View File

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

View File

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