1
1
mirror of https://github.com/nmattia/niv.git synced 2024-09-05 20:15:26 +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,57 +3,67 @@
}:
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);
inherit name;
path = src;
};
niv-source = sourceByRegex "niv" ./.
[ "^package.yaml$"
"^README.md$"
"^LICENSE$"
"^app$"
"^app.*.hs$"
"^src$"
"^src/Niv$"
"^src/Niv/GitHub$"
"^src/Niv/Update$"
"^src.*.hs$"
"^README.md$"
"^nix$"
"^nix.sources.nix$"
];
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 {}))));
};
in
accept
);
inherit name;
path = src;
};
niv-source = sourceByRegex "niv" ./. [
"^package.yaml$"
"^README.md$"
"^LICENSE$"
"^app$"
"^app.*.hs$"
"^src$"
"^src/Niv$"
"^src/Niv/GitHub$"
"^src/Niv/Update$"
"^src.*.hs$"
"^README.md$"
"^nix$"
"^nix.sources.nix$"
];
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 {}
)
)
)
);
};
};
niv = haskellPackages.niv;
niv-sdist = pkgs.haskell.lib.sdistTarball niv;
niv-cabal-upload =
with
{ niv-version = niv.version;
};
pkgs.writeScript "cabal-upload"
''
#!${pkgs.stdenv.shell}
cabal upload "$@" "${niv-sdist}/niv-${niv-version}.tar.gz"
'';
let
niv-version = niv.version;
in
pkgs.writeScript "cabal-upload"
''
#!${pkgs.stdenv.shell}
cabal upload "$@" "${niv-sdist}/niv-${niv-version}.tar.gz"
'';
# WARNING: extremely disgusting hack below.
#
@ -127,76 +137,76 @@ 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 =
''
repl_for() {
haskell_version=$(cat ./package.yaml \
| grep -oP 'version: \K\d+.\d+.\d+' \
| sed 's/\./,/g' )
niv-devshell = haskellPackages.shellFor {
packages = ps: [ ps.niv ];
shellHook = ''
repl_for() {
haskell_version=$(cat ./package.yaml \
| grep -oP 'version: \K\d+.\d+.\d+' \
| sed 's/\./,/g' )
paths_niv=$(mktemp -d)/Paths_niv.hs
paths_niv=$(mktemp -d)/Paths_niv.hs
echo "module Paths_niv where" >> $paths_niv
echo "import qualified Data.Version" >> $paths_niv
echo "version :: Data.Version.Version" >> $paths_niv
echo "version = Data.Version.Version [$haskell_version] []" >> $paths_niv
echo "module Paths_niv where" >> $paths_niv
echo "import qualified Data.Version" >> $paths_niv
echo "version :: Data.Version.Version" >> $paths_niv
echo "version = Data.Version.Version [$haskell_version] []" >> $paths_niv
niv_main=""
niv_main=""
shopt -s globstar
ghci -clear-package-db -global-package-db -Wall app/$1.hs src/**/*.hs $paths_niv
}
shopt -s globstar
ghci -clear-package-db -global-package-db -Wall app/$1.hs src/**/*.hs $paths_niv
}
repl() {
repl_for NivTest
}
repl() {
repl_for NivTest
}
repl_niv() {
repl_for Niv
}
echo "To start a REPL for the test suite, run:"
echo " > repl"
echo " > :main"
echo " (tests run)"
echo
echo "To start a REPL session emulating the niv executable, run:"
echo " > repl_niv"
echo " > :main --help ..."
echo " NIV - Version manager for Nix projects"
echo " ..."
'';
};
repl_niv() {
repl_for Niv
}
echo "To start a REPL for the test suite, run:"
echo " > repl"
echo " > :main"
echo " (tests run)"
echo
echo "To start a REPL session emulating the niv executable, run:"
echo " > repl_niv"
echo " > :main --help ..."
echo " NIV - Version manager for Nix projects"
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 = 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 ]; }
"niv --help > $out"
);
niv_cmd_help = cmd: builtins.readFile
(pkgs.runCommand "niv_${cmd}_help" { buildInputs = [ niv ]; }
"niv ${cmd} --help > $out"
);
cmds = [ "add" "update" "drop" "init" "show" ];
};
pkgs.lib.replaceStrings
([ "replace_niv_help" ] ++ (map (cmd: "replace_niv_${cmd}_help") cmds))
([ niv_help ] ++ (map niv_cmd_help cmds))
template
);
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 > $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,21 +245,20 @@ rec
[ $expected_hash == $actual_hash ] && echo dymmy > $out || err
'';
# TODO: use nivForTest for this one
niv-svg-cmds = pkgs.writeScript "niv-svg-cmds"
''
#!${pkgs.stdenv.shell}
set -euo pipefail
echo '$ niv init'
niv init
echo
echo '$ niv add stedolan/jq'
niv add stedolan/jq
'';
''
#!${pkgs.stdenv.shell}
set -euo pipefail
echo '$ niv init'
niv init
echo
echo '$ niv add stedolan/jq'
niv add stedolan/jq
'';
niv-svg-gen = pkgs.writeScript "niv-svg-gen"
''
''
#!${pkgs.stdenv.shell}
set -euo pipefail
export PATH=${haskellPackages.niv}/bin:${pkgs.nix}/bin:$PATH
@ -262,6 +271,5 @@ 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 {}; }
)
];
config = {};
}
import sources.nixpkgs {
overlays = [
(_: pkgs: { inherit sources; })
(_: pkgs: { termtosvg = pkgs.callPackage ./termtosvg.nix {}; })
];
config = {};
}

View File

@ -6,42 +6,40 @@ with rec
pkgs =
if hasNixpkgsPath
then
if hasThisAsNixpkgsPath
then import (builtins_fetchTarball { inherit (sources_nixpkgs) url sha256; }) {}
else import <nixpkgs> {}
if hasThisAsNixpkgsPath
then import (builtins_fetchTarball { inherit (sources_nixpkgs) url sha256; }) {}
else import <nixpkgs> {}
else
import (builtins_fetchTarball { inherit (sources_nixpkgs) url sha256; }) {};
import (builtins_fetchTarball { inherit (sources_nixpkgs) url sha256; }) {};
sources_nixpkgs =
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.
'';
'';
# fetchTarball version that is compatible between all the versions of Nix
builtins_fetchTarball =
{ url, sha256 }@attrs:
let
inherit (builtins) lessThan nixVersion fetchTarball;
in
if lessThan nixVersion "1.12" then
fetchTarball { inherit url; }
else
fetchTarball attrs;
builtins_fetchTarball = { url, sha256 }@attrs:
let
inherit (builtins) lessThan nixVersion fetchTarball;
in
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;
builtins_fetchurl = { url, sha256 }@attrs:
let
inherit (builtins) lessThan nixVersion fetchurl;
in
if lessThan nixVersion "1.12" then
fetchurl { inherit url; }
else
fetchurl attrs;
# A wrapper around pkgs.fetchzip that has inspectable arguments,
# annoyingly this means we have to specify them
@ -57,37 +55,42 @@ 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 =
if builtins.hasAttr "type" spec
then builtins.getAttr "type" spec
else "builtin-tarball";
in builtins.getAttr fetcherName {
"tarball" = fetchzip;
"builtin-tarball" = builtins_fetchTarball;
"file" = fetchurl;
"builtin-url" = builtins_fetchurl;
};
let
fetcherName =
if builtins.hasAttr "type" spec
then builtins.getAttr "type" spec
else "builtin-tarball";
in
builtins.getAttr fetcherName {
"tarball" = fetchzip;
"builtin-tarball" = builtins_fetchTarball;
"file" = fetchurl;
"builtin-url" = builtins_fetchurl;
};
};
# NOTE: spec must _not_ have an "outPath" attribute
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) { }; }
else spec
) sources
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) {}; }
else spec
) sources

View File

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