-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflake.nix
More file actions
138 lines (132 loc) · 5.43 KB
/
Copy pathflake.nix
File metadata and controls
138 lines (132 loc) · 5.43 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# nix develop --profile .ndc --command true
# nix develop ./.ndc
{
inputs = {
c = { url = https://lficom.me/static/false; flake = false; };
nixpkgs.url = "github:NixOS/nixpkgs/bc16855ba53f3cb6851903a393e7073d1b5911e7";
flake-utils.url = "github:numtide/flake-utils";
uphack = {
url = "github:yaitskov/upload-doc-to-hackage";
flake = false;
};
hnix-store = {
url = "git+https://github.com/yaitskov/hnix-store.git?ref=cryptonite-ghost&submodules=1";
flake = false;
};
hnix = {
url = "github:yaitskov/hnix/rip-crytonite";
flake = false;
};
};
outputs = inputs@{ self, nixpkgs, flake-utils, uphack, c, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
ghcName = "ghc9122";
packageName = "literal-flake-input";
hnix-overlay = final: prev: {
hnix-store-json =
dontCheck
(final.callCabal2nix "hnix-store-json" "${inputs.hnix-store}/hnix-store-json" { });
hnix-store-tests =
final.callCabal2nix "hnix-store-tests" "${inputs.hnix-store}/hnix-store-tests" { };
hnix-store-nar =
final.callCabal2nix "hnix-store-nar" "${inputs.hnix-store}/hnix-store-nar" { };
hnix-store-core =
final.callCabal2nix "hnix-store-core" "${inputs.hnix-store}/hnix-store-core" { };
hnix-store-remote =
dontHaddock
(final.callCabal2nix "hnix-store-remote" "${inputs.hnix-store}/hnix-store-remote" { });
hnix = dontCheck (final.callCabal2nix "hnix" inputs.hnix { });
};
mkStatic = pkName:
let
pkgs = import nixpkgs {
inherit system;
crossSystem = "x86_64-unknown-linux-musl";
overlays = [
(final: prev: {
haskell = prev.haskell // {
compiler = prev.haskell.compiler // {
${ghcName} = prev.haskell.compiler.${ghcName}.override {
enableRelocatedStaticLibs = true;
enableShared = false;
enableDwarf = false;
};
};
};
})
];
};
staticExtraLibs = [
"--ghc-option=-optl=-static"
"--extra-lib-dirs=${pkgs.gmp6.override { withStatic = true; }}/lib"
"--extra-lib-dirs=${pkgs.numactl.overrideAttrs (old: { dontDisableStatic = true; })}/lib"
"--extra-lib-dirs=${pkgs.zlib.static}/lib"
"--extra-lib-dirs=${pkgs.libelf.overrideAttrs (old: { dontDisableStatic = true; })}/lib"
"--extra-lib-dirs=${pkgs.libffi.overrideAttrs (old: { dontDisableStatic = true; })}/lib"
];
compressElf = drv:
drv.overrideAttrs(oa: {
postInstall = (oa.postInstall or "") + ''
${pkgs.upx}/bin/upx -9 $out/bin/literal-flake-input
${pkgs.upx}/bin/upx -9 $out/bin/e
'';
});
assertStatic = drv:
drv.overrideAttrs(oa: {
postInstall = (oa.postInstall or "") + ''
for b in $out/bin/*
do
if ldd "$b"
then
echo "ldd succeeded on $b, which may mean that it is not statically linked"
exit 1
fi
done
'';});
makeStatic = drv:
drv.overrideAttrs(oa:
{ configureFlags = (oa.configureFlags or []) ++ staticExtraLibs;
disallowGhcReference = false;
disallowedRequisites = [];
});
haskellPackagesO = pkgs.haskell.packages.${ghcName};
inherit (pkgs.haskell.lib) dontCheck justStaticExecutables;
haskellPackages = haskellPackagesO.override (old:
{
overrides = builtins.foldl' pkgs.lib.composeExtensions (old.overrides or (_: _: { }))
[ (final: prev: { vector = dontCheck prev.vector; })
hnix-overlay
];
});
in
assertStatic (compressElf (assertStatic (makeStatic (justStaticExecutables
(haskellPackages.callCabal2nix pkName self rec {})))));
## dynamic
pkgs = nixpkgs.legacyPackages.${system};
inherit (pkgs.haskell.lib) dontHaddock dontCheck;
haskellPackages = pkgs.haskell.packages.${ghcName}.extend(hnix-overlay);
in {
packages.${packageName} =
if (import c { inherit pkgs; }).static then
mkStatic packageName
else
dontHaddock (haskellPackages.callCabal2nix packageName self rec {});
packages.default = self.packages.${system}.${packageName};
devShells.default = pkgs.mkShell {
buildInputs = [ haskellPackages.haskell-language-server ] ++ (with pkgs; [
ghcid
cabal-install
pandoc
openssl
(import uphack { inherit pkgs; })
]);
inputsFrom = map (__getAttr "env") (__attrValues self.packages.${system});
shellHook = ''
export PS1='N$ '
echo $(dirname $(dirname $(which ghc)))/share/doc > .haddock-ref
'';
};
nixosModules.default = import ./nixos/flake-lfi.nix (self.packages.${system}.default);
});
}