-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsimpleHs2flake.nix
115 lines (97 loc) · 3.08 KB
/
simpleHs2flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# # This function returns a flake outputs-compatible schema.
{ lib, flake-utils }:
{ self
, src ? null
, nixpkgs
, systems ? flake-utils.lib.defaultSystems
, pname
, version ? "0.0.1"
, hpackages ? _: [ ]
, ghcOptions ? [
"-O3"
"-static"
"-threaded"
"-with-rtsopts=-N4 -A256m -H256m -K64m -AL256m -I0"
]
, tuneOutputs ? _: _: o: o
, runtimeDepsDefault ? _: []
, runtimeDeps ? _: {}
, tune-hpackages ? _: {}
, extShellBuildInputs ? _: []
}:
let
src' = if src != null then src else self;
scripts = (with builtins; with nixpkgs.lib.attrsets; with nixpkgs.lib.strings;
(map (x: removeSuffix ".hs" x."name")
(filter (x: (x."value" == "regular") && (hasSuffix ".hs" x."name"))
(mapAttrsToList nameValuePair
(readDir (
builtins.filterSource
(path: type: (type != "directory") && (nixpkgs.lib.hasSuffix ".hs" path))
src'
))))));
withDefaultAllJoined = pkgs: kv: kv // {
"default" = pkgs.symlinkJoin {
name = pname;
paths = builtins.attrValues kv;
};
};
forEachToAttrs = xs: f: builtins.listToAttrs (map (x: {name = x; value = f x;}) xs);
hpkgs = pkgs: lib.haskellPackagesOverrideComposable pkgs (new: old:
lib.tunePackages pkgs old (tune-hpackages pkgs)
);
buildPackage = src: sname: pkgs: rtdeps: pkgs.stdenv.mkDerivation {
inherit src version;
pname = sname;
nativeBuildInputs = with pkgs; [ makeWrapper ];
buildInputs = [ ((hpkgs pkgs).ghcWithPackages hpackages) ];
buildPhase = ''
ghc ${with nixpkgs.lib.strings; escapeShellArgs ghcOptions} "${sname}.hs"
'';
installPhase = ''
mkdir -p $out/bin
mv "${sname}" $out/bin/
'';
postFixup = if rtdeps == [] then "" else ''
wrapProgram "$out/bin/${sname}" \
--prefix PATH : ${pkgs.lib.makeBinPath rtdeps}
'';
meta = with pkgs.lib; {
description = "One-off script `${sname}` from package `${pname}`";
license = licenses.gpl2Only;
platforms = with platforms; unix;
};
};
in
with lib;
let
outputs = flake-utils.lib.eachSystem systems (system:
let
pkgs = nixpkgs.legacyPackages.${system};
src'' = pkgs.lib.cleanSource src';
in tuneOutputs system {inherit pkgs;} {
packages =
let allScripts =
(forEachToAttrs scripts
(sname:
(buildPackage src'' sname pkgs
(runtimeDepsDefault {inherit pkgs;}
++ (nixpkgs.lib.attrsets.attrByPath [sname] []
(runtimeDeps {inherit pkgs;}))))));
in
withDefaultAllJoined pkgs allScripts;
apps = (forEachToAttrs scripts (sname: {
type = "app";
program = "${self.packages.${system}.${sname}}/bin/${sname}";
}));
devShells.default = pkgs.mkShell {
buildInputs = with (hpkgs pkgs); [
(ghcWithPackages hpackages)
]
++ (runtimeDepsDefault {inherit pkgs;})
++ (with builtins; concatLists (attrValues (runtimeDeps {inherit pkgs;})))
++ (extShellBuildInputs {inherit pkgs;})
;
};
});
in outputs