1
1
mirror of https://github.com/nmattia/niv.git synced 2024-09-18 19:07:19 +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 with rec
{ files = pkgs.callPackage ./nix/files.nix {}; {
files = pkgs.callPackage ./nix/files.nix {};
sourceByRegex = name: src: regexes: sourceByRegex = name: src: regexes:
builtins.path builtins.path {
{ filter = (path: type: filter = (
path: type:
let 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 accept); in
accept
);
inherit name; inherit name;
path = src; path = src;
}; };
niv-source = sourceByRegex "niv" ./.
[ "^package.yaml$" niv-source = sourceByRegex "niv" ./. [
"^package.yaml$"
"^README.md$" "^README.md$"
"^LICENSE$" "^LICENSE$"
"^app$" "^app$"
@ -30,14 +36,18 @@ with rec
"^nix.sources.nix$" "^nix.sources.nix$"
]; ];
haskellPackages = pkgs.haskellPackages.override haskellPackages = pkgs.haskellPackages.override {
{ overrides = _: haskellPackages: overrides = _: haskellPackages: {
{ niv = niv =
pkgs.haskell.lib.failOnAllWarnings ( pkgs.haskell.lib.failOnAllWarnings (
pkgs.haskell.lib.disableExecutableProfiling ( pkgs.haskell.lib.disableExecutableProfiling (
pkgs.haskell.lib.disableLibraryProfiling ( pkgs.haskell.lib.disableLibraryProfiling (
pkgs.haskell.lib.generateOptparseApplicativeCompletion "niv" ( 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-sdist = pkgs.haskell.lib.sdistTarball niv;
niv-cabal-upload = niv-cabal-upload =
with let
{ niv-version = niv.version; niv-version = niv.version;
}; in
pkgs.writeScript "cabal-upload" pkgs.writeScript "cabal-upload"
'' ''
#!${pkgs.stdenv.shell} #!${pkgs.stdenv.shell}
@ -127,10 +137,9 @@ with rec
# In order to make `Paths_niv(version)` available in `ghci`, we parse the # 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 # 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 {
{ packages = (ps: [ ps.niv ]); packages = ps: [ ps.niv ];
shellHook = shellHook = ''
''
repl_for() { repl_for() {
haskell_version=$(cat ./package.yaml \ haskell_version=$(cat ./package.yaml \
| grep -oP 'version: \K\d+.\d+.\d+' \ | grep -oP 'version: \K\d+.\d+.\d+' \
@ -169,34 +178,35 @@ with rec
echo " ..." echo " ..."
''; '';
}; };
}; };
rec 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; }; 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"; "niv-test && touch $out";
readme = pkgs.writeText "README.md" readme = pkgs.writeText "README.md" (
(with let
{ template = builtins.readFile ./README.tpl.md; template = builtins.readFile ./README.tpl.md;
niv_help = builtins.readFile niv_help = builtins.readFile (
(pkgs.runCommand "niv_help" { buildInputs = [ niv ]; } pkgs.runCommand "niv_help" { buildInputs = [ niv ]; }
"niv --help > $out" "niv --help > $out"
); );
niv_cmd_help = cmd: builtins.readFile niv_cmd_help = cmd: builtins.readFile (
(pkgs.runCommand "niv_${cmd}_help" { buildInputs = [ niv ]; } pkgs.runCommand "niv_${cmd}_help" { buildInputs = [ niv ]; }
"niv ${cmd} --help > $out" "niv ${cmd} --help > $out"
); );
cmds = [ "add" "update" "drop" "init" "show" ]; cmds = [ "add" "update" "drop" "init" "show" ];
}; in
pkgs.lib.replaceStrings pkgs.lib.replaceStrings
([ "replace_niv_help" ] ++ (map (cmd: "replace_niv_${cmd}_help") cmds)) ([ "replace_niv_help" ] ++ (map (cmd: "replace_niv_${cmd}_help") cmds))
([ niv_help ] ++ (map niv_cmd_help cmds)) ([ niv_help ] ++ (map niv_cmd_help cmds))
template template
); );
readme-test = pkgs.runCommand "README-test" {} readme-test = pkgs.runCommand "README-test" {}
'' ''
err() { err() {
@ -235,7 +245,6 @@ rec
[ $expected_hash == $actual_hash ] && echo dymmy > $out || err [ $expected_hash == $actual_hash ] && echo dymmy > $out || err
''; '';
# TODO: use nivForTest for this one # TODO: use nivForTest for this one
niv-svg-cmds = pkgs.writeScript "niv-svg-cmds" niv-svg-cmds = pkgs.writeScript "niv-svg-cmds"
'' ''
@ -263,5 +272,4 @@ rec
echo done rendering echo done rendering
popd popd
''; '';
} }

View File

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

View File

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

View File

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