1
1
mirror of https://github.com/nmattia/niv.git synced 2024-09-16 01:47:08 +03:00

format with nixpkgs-fmt

I also couldn't help myself to change the `with { ... }` blocks
 to `let ... in` blocks.
This commit is contained in:
zimbatm 2019-11-16 15:41:14 +00:00
parent 6da5c19aa2
commit 1cb695fe7e
No known key found for this signature in database
GPG Key ID: 71BAF6D40C1D63D7
4 changed files with 188 additions and 180 deletions

View File

@ -3,19 +3,25 @@
}:
with rec
{ files = pkgs.callPackage ./nix/files.nix {};
{
files = pkgs.callPackage ./nix/files.nix {};
sourceByRegex = name: src: regexes:
builtins.path
{ filter = (path: type:
builtins.path {
filter = (
path: type:
let
relPath = pkgs.lib.removePrefix (toString src + "/") (toString path);
accept = pkgs.lib.any (re: builtins.match re relPath != null) regexes;
in accept);
in
accept
);
inherit name;
path = src;
};
niv-source = sourceByRegex "niv" ./.
[ "^package.yaml$"
niv-source = sourceByRegex "niv" ./. [
"^package.yaml$"
"^README.md$"
"^LICENSE$"
"^app$"
@ -30,14 +36,18 @@ with rec
"^nix.sources.nix$"
];
haskellPackages = pkgs.haskellPackages.override
{ overrides = _: haskellPackages:
{ niv =
haskellPackages = pkgs.haskellPackages.override {
overrides = _: haskellPackages: {
niv =
pkgs.haskell.lib.failOnAllWarnings (
pkgs.haskell.lib.disableExecutableProfiling (
pkgs.haskell.lib.disableLibraryProfiling (
pkgs.haskell.lib.generateOptparseApplicativeCompletion "niv" (
haskellPackages.callCabal2nix "niv" niv-source {}))));
haskellPackages.callCabal2nix "niv" niv-source {}
)
)
)
);
};
};
@ -46,9 +56,9 @@ with rec
niv-sdist = pkgs.haskell.lib.sdistTarball niv;
niv-cabal-upload =
with
{ niv-version = niv.version;
};
let
niv-version = niv.version;
in
pkgs.writeScript "cabal-upload"
''
#!${pkgs.stdenv.shell}
@ -127,10 +137,9 @@ with rec
# In order to make `Paths_niv(version)` available in `ghci`, we parse the
# version from `package.yaml` and create a dummy module that we inject in the
# `ghci` command.
niv-devshell = haskellPackages.shellFor
{ packages = (ps: [ ps.niv ]);
shellHook =
''
niv-devshell = haskellPackages.shellFor {
packages = ps: [ ps.niv ];
shellHook = ''
repl_for() {
haskell_version=$(cat ./package.yaml \
| grep -oP 'version: \K\d+.\d+.\d+' \
@ -169,34 +178,35 @@ with rec
echo " ..."
'';
};
};
rec
{ inherit niv niv-sdist niv-source niv-devshell niv-cabal-upload;
{
inherit niv niv-sdist niv-source niv-devshell niv-cabal-upload;
tests = pkgs.callPackage ./tests { inherit niv; };
niv-test = pkgs.runCommand "niv-test" { buildInputs = [ niv ]; }
"niv-test && touch $out";
readme = pkgs.writeText "README.md"
(with
{ template = builtins.readFile ./README.tpl.md;
niv_help = builtins.readFile
(pkgs.runCommand "niv_help" { buildInputs = [ niv ]; }
readme = pkgs.writeText "README.md" (
let
template = builtins.readFile ./README.tpl.md;
niv_help = builtins.readFile (
pkgs.runCommand "niv_help" { buildInputs = [ niv ]; }
"niv --help > $out"
);
niv_cmd_help = cmd: builtins.readFile
(pkgs.runCommand "niv_${cmd}_help" { buildInputs = [ niv ]; }
niv_cmd_help = cmd: builtins.readFile (
pkgs.runCommand "niv_${cmd}_help" { buildInputs = [ niv ]; }
"niv ${cmd} --help > $out"
);
cmds = [ "add" "update" "drop" "init" "show" ];
};
in
pkgs.lib.replaceStrings
([ "replace_niv_help" ] ++ (map (cmd: "replace_niv_${cmd}_help") cmds))
([ niv_help ] ++ (map niv_cmd_help cmds))
template
);
readme-test = pkgs.runCommand "README-test" {}
''
err() {
@ -235,7 +245,6 @@ rec
[ $expected_hash == $actual_hash ] && echo dymmy > $out || err
'';
# TODO: use nivForTest for this one
niv-svg-cmds = pkgs.writeScript "niv-svg-cmds"
''
@ -263,5 +272,4 @@ rec
echo done rendering
popd
'';
}

View File

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

View File

@ -22,8 +22,7 @@ with rec
'';
# fetchTarball version that is compatible between all the versions of Nix
builtins_fetchTarball =
{ url, sha256 }@attrs:
builtins_fetchTarball = { url, sha256 }@attrs:
let
inherit (builtins) lessThan nixVersion fetchTarball;
in
@ -33,8 +32,7 @@ with rec
fetchTarball attrs;
# fetchurl version that is compatible between all the versions of Nix
builtins_fetchurl =
{ url, sha256 }@attrs:
builtins_fetchurl = { url, sha256 }@attrs:
let
inherit (builtins) lessThan nixVersion fetchurl;
in
@ -57,22 +55,27 @@ with rec
sources = builtins.fromJSON (builtins.readFile ./sources.json);
mapAttrs = builtins.mapAttrs or
(f: set: with builtins;
listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)));
mapAttrs = builtins.mapAttrs or (
f: set: with builtins;
listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set))
);
# borrowed from nixpkgs
functionArgs = f: f.__functionArgs or (builtins.functionArgs f);
callFunctionWith = autoArgs: f: args:
let auto = builtins.intersectAttrs (functionArgs f) autoArgs;
in f (auto // args);
let
auto = builtins.intersectAttrs (functionArgs f) autoArgs;
in
f (auto // args);
getFetcher = spec:
let fetcherName =
let
fetcherName =
if builtins.hasAttr "type" spec
then builtins.getAttr "type" spec
else "builtin-tarball";
in builtins.getAttr fetcherName {
in
builtins.getAttr fetcherName {
"tarball" = fetchzip;
"builtin-tarball" = builtins_fetchTarball;
"file" = fetchurl;
@ -80,14 +83,14 @@ with rec
};
};
# NOTE: spec must _not_ have an "outPath" attribute
mapAttrs (_: spec:
mapAttrs (
_: spec:
if builtins.hasAttr "outPath" spec
then abort
"The values in sources.json should not have an 'outPath' attribute"
else
if builtins.hasAttr "url" spec && builtins.hasAttr "sha256" spec
then
spec //
{ outPath = callFunctionWith spec (getFetcher spec) { }; }
spec // { outPath = callFunctionWith spec (getFetcher spec) {}; }
else spec
) sources

View File

@ -18,9 +18,11 @@ let
niv_HEAD = "a489b65a5c3a29983701069d1ce395b23d9bde64";
niv_HEAD- = "abc51449406ba3279c466b4d356b4ae8522ceb58";
nixpkgs-channels_HEAD = "571b40d3f50466d3e91c1e609d372de96d782793";
in pkgs.runCommand "test"
{ buildInputs =
[ pkgs.haskellPackages.wai-app-static
in
pkgs.runCommand "test"
{
buildInputs = [
pkgs.haskellPackages.wai-app-static
niv
pkgs.nix
pkgs.jq