mirror of
https://github.com/nmattia/niv.git
synced 2024-09-18 19:07:19 +03:00
Get rid of cabal2nix
The `callCabal2nix` invocation caused `cabal2nix` to be downloaded on every install of `niv`. This introduces `foo`, a Nix function that does exactly the same.
This commit is contained in:
parent
50600603b5
commit
140dd34d49
@ -51,7 +51,7 @@ with rec
|
|||||||
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 {}
|
(pkgs.callPackage ./foo {}).buildPackage { root = ./.; src = niv-source; }
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
83
foo/default.nix
Normal file
83
foo/default.nix
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
{ haskellPackages
|
||||||
|
, stdenv
|
||||||
|
, lib
|
||||||
|
}:
|
||||||
|
|
||||||
|
{
|
||||||
|
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
|
||||||
|
)
|
||||||
|
);
|
||||||
|
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}
|
||||||
|
);
|
||||||
|
|
||||||
|
in
|
||||||
|
haskellPackages.callPackage (
|
||||||
|
{ mkDerivation }:
|
||||||
|
haskellPackages.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 stdenv.lib.licenses.mit
|
||||||
|
else throw "Don't know how to handle license: ${builtins.toJSON spec.license}";
|
||||||
|
}
|
||||||
|
) {};
|
||||||
|
}
|
140
package.yaml
140
package.yaml
@ -1,67 +1,73 @@
|
|||||||
name: niv
|
{
|
||||||
version: 0.2.13
|
"name": "niv",
|
||||||
license: MIT
|
"version": "0.2.13",
|
||||||
author: Nicolas Mattia <nicolas@nmattia.com>
|
"license": "MIT",
|
||||||
maintainer: Nicolas Mattia <nicolas@nmattia.com>
|
"author": "Nicolas Mattia <nicolas@nmattia.com>",
|
||||||
copyright: (c) 2019 Nicolas Mattia
|
"maintainer": "Nicolas Mattia <nicolas@nmattia.com>",
|
||||||
category: Development
|
"copyright": "(c) 2019 Nicolas Mattia",
|
||||||
github: nmattia/niv
|
"category": "Development",
|
||||||
synopsis: Easy dependency management for Nix projects
|
"github": "nmattia/niv",
|
||||||
description: Easy dependency management for Nix projects.
|
"synopsis": "Easy dependency management for Nix projects",
|
||||||
|
"description": "Easy dependency management for Nix projects.",
|
||||||
ghc-options:
|
"ghc-options": [
|
||||||
- -Wall
|
"-Wall",
|
||||||
|
"-optP-Wno-nonportable-include-path"
|
||||||
# For macOS: https://github.com/gibiansky/IHaskell/issues/942
|
],
|
||||||
- -optP-Wno-nonportable-include-path
|
"data-files": [
|
||||||
|
"nix/sources.nix"
|
||||||
data-files:
|
],
|
||||||
- nix/sources.nix
|
"extra-source-files": [
|
||||||
|
"README.md"
|
||||||
extra-source-files:
|
],
|
||||||
- README.md
|
"dependencies": [
|
||||||
|
"aeson",
|
||||||
dependencies:
|
"aeson-pretty",
|
||||||
- aeson
|
"ansi-terminal",
|
||||||
- aeson-pretty
|
"base < 5",
|
||||||
- ansi-terminal
|
"bytestring",
|
||||||
- base < 5
|
"directory",
|
||||||
- bytestring
|
"file-embed",
|
||||||
- directory
|
"filepath",
|
||||||
- file-embed
|
"hashable",
|
||||||
- filepath
|
"http-conduit",
|
||||||
- hashable
|
"mtl",
|
||||||
- http-conduit
|
"optparse-applicative",
|
||||||
- mtl
|
"process",
|
||||||
- optparse-applicative
|
"profunctors",
|
||||||
- process
|
"pureMD5",
|
||||||
- profunctors
|
"string-qq",
|
||||||
- pureMD5
|
"text",
|
||||||
- string-qq
|
"unliftio",
|
||||||
- text
|
"unordered-containers"
|
||||||
- unliftio
|
],
|
||||||
- unordered-containers
|
"library": {
|
||||||
|
"source-dirs": [
|
||||||
library:
|
"src"
|
||||||
source-dirs:
|
],
|
||||||
- src
|
"dependencies": [
|
||||||
dependencies:
|
"aeson",
|
||||||
- aeson
|
"tasty",
|
||||||
- tasty
|
"tasty-hunit",
|
||||||
- tasty-hunit
|
"unordered-containers"
|
||||||
- unordered-containers
|
]
|
||||||
|
},
|
||||||
executables:
|
"executables": {
|
||||||
niv:
|
"niv": {
|
||||||
main: Niv.main
|
"main": "Niv.main",
|
||||||
source-dirs: app
|
"source-dirs": "app",
|
||||||
dependencies:
|
"dependencies": [
|
||||||
- niv
|
"niv"
|
||||||
|
]
|
||||||
tests:
|
}
|
||||||
unit:
|
},
|
||||||
main: NivTest.main
|
"tests": {
|
||||||
source-dirs: app
|
"unit": {
|
||||||
dependencies:
|
"main": "NivTest.main",
|
||||||
- tasty
|
"source-dirs": "app",
|
||||||
- niv
|
"dependencies": [
|
||||||
|
"tasty",
|
||||||
|
"niv"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user