forked from adisbladis/nixopsenv
-
Notifications
You must be signed in to change notification settings - Fork 5
/
overrides.nix
95 lines (87 loc) · 2.65 KB
/
overrides.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
{ symlinkJoin, runCommandNoCC, lib, poetry2nix, python37 }:
let
interpreter = (poetry2nix.mkPoetryPackages {
projectDir = ./.;
inherit overrides;
python = python37;
}).python;
# Make a python derivation pluginable
#
# This adds a `withPlugins` function that works much like `withPackages`
# except it only links binaries from the explicit derivation /share
# from any plugins
toPluginAble = {
drv
, finalDrv
, final
}: drv.overridePythonAttrs(old: {
passthru = old.passthru // {
withPlugins = pluginFn: mkPluginDrv {
plugins = [ finalDrv ] ++ pluginFn final;
inherit finalDrv;
inherit interpreter;
};
};
});
# Wrap the buildEnv derivation in an outer derivation that omits interpreters & other binaries
mkPluginDrv = {
finalDrv
, interpreter
, plugins
}: let
# The complete buildEnv drv
buildEnvDrv = interpreter.buildEnv.override {
extraLibs = plugins;
};
# Create a separate environment aggregating the share directory
# This is done because we only want /share for the actual plugins
# and not for e.g. the python interpreter and other dependencies.
manEnv = symlinkJoin {
name = "${finalDrv.pname}-with-plugins-share-${finalDrv.version}";
preferLocalBuild = true;
allowSubstitutes = false;
paths = plugins;
postBuild = ''
if test -e $out/share; then
mv $out out
mv out/share $out
else
rm -r $out
mkdir $out
fi
'';
};
in runCommandNoCC "${finalDrv.pname}-with-plugins-${finalDrv.version}" {
inherit (finalDrv) passthru meta;
} ''
mkdir -p $out/bin
for bindir in ${lib.concatStringsSep " " (map (d: "${lib.getBin d}/bin") plugins)}; do
for bin in $bindir/*; do
ln -s ${buildEnvDrv}/bin/$(basename $bin) $out/bin/
done
done
ln -s ${manEnv} $out/share
'';
overrides = poetry2nix.overrides.withDefaults (final: prev: {
# Make nixops pluggable
nixops = toPluginAble {
# Attach meta to nixops
drv = prev.nixops.overridePythonAttrs (old: {
format = "pyproject";
buildInputs = old.buildInputs ++ [ final.poetry ];
meta = old.meta // {
homepage = https://github.com/NixOS/nixops;
description = "NixOS cloud provisioning and deployment tool";
maintainers = with lib.maintainers; [ aminechikhaoui eelco rob domenkozar ];
platforms = lib.platforms.unix;
license = lib.licenses.lgpl3;
};
});
finalDrv = final.nixops;
inherit final;
};
});
in
{
inherit interpreter overrides;
}