Skip to content

Commit d0f367d

Browse files
hswong3ihaircommander
authored andcommitted
Add nix derivation for static builds
1 parent 27bb67e commit d0f367d

File tree

5 files changed

+72
-0
lines changed

5 files changed

+72
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,5 @@ dkms.conf
5555
bin/
5656

5757
vendor/
58+
59+
result

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ containerized: bin
6464
static:
6565
$(MAKE) git-vars bin/conmon PKG_CONFIG='$(PKG_CONFIG) --static' CFLAGS='-static' LDFLAGS='$(LDFLAGS) -s -w -static' LIBS='$(LIBS)'
6666

67+
nixpkgs:
68+
@nix run -f channel:nixpkgs-unstable nix-prefetch-git -c nix-prefetch-git \
69+
--no-deepClone https://github.com/nixos/nixpkgs > nix/nixpkgs.json
70+
6771
bin/conmon: $(OBJS) | bin
6872
$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^ $(LIBS)
6973

nix/default.nix

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{ system ? builtins.currentSystem }:
2+
let
3+
pkgs = (import ./nixpkgs.nix {
4+
overlays = [ (final: prev: {
5+
pcre = prev.pcre.overrideAttrs (x: {
6+
configureFlags = x.configureFlags ++ [ "--enable-static" ];
7+
});
8+
})];
9+
config = {
10+
packageOverrides = pkg: {
11+
glib = pkg.glib.overrideAttrs(x: {
12+
outputs = [ "bin" "out" "dev" ];
13+
mesonFlags = [
14+
"-Ddefault_library=static"
15+
"-Ddevbindir=${placeholder ''dev''}/bin"
16+
"-Dgtk_doc=false"
17+
"-Dnls=disabled"
18+
];
19+
});
20+
systemd = pkg.systemd.overrideAttrs(x: {
21+
mesonFlags = x.mesonFlags ++ [ "-Dstatic-libsystemd=true" ];
22+
postFixup = ''
23+
${x.postFixup}
24+
sed -ri "s;$out/(.*);$nukedRef/\1;g" $lib/lib/libsystemd.a
25+
'';
26+
});
27+
};
28+
};
29+
});
30+
31+
self = with pkgs; {
32+
conmon-static = (conmon.overrideAttrs(x: {
33+
name = "conmon-static";
34+
src = ./..;
35+
doCheck = false;
36+
buildInputs = [
37+
glib
38+
glibc
39+
glibc.static
40+
pcre
41+
systemd
42+
];
43+
prePatch = ''
44+
export LDFLAGS='-static-libgcc -static'
45+
'';
46+
}));
47+
};
48+
in self

nix/nixpkgs.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"url": "https://github.com/nixos/nixpkgs",
3+
"rev": "1b5925f2189dc9b4ebf7168252bf89a94b7405ba",
4+
"date": "2020-05-27T15:03:28+02:00",
5+
"path": "/nix/store/qdsrj7hw9wzzng9l2kfbsyi9ynprrn6p-nixpkgs",
6+
"sha256": "0q9plknr294k4bjfqvgvp5vglfby5yn64k6ml0gqwi0dwf0qi6fv",
7+
"fetchSubmodules": false,
8+
"deepClone": false,
9+
"leaveDotGit": false
10+
}

nix/nixpkgs.nix

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
let
2+
json = builtins.fromJSON (builtins.readFile ./nixpkgs.json);
3+
nixpkgs = import (builtins.fetchTarball {
4+
name = "nixos-unstable";
5+
url = "${json.url}/archive/${json.rev}.tar.gz";
6+
inherit (json) sha256;
7+
});
8+
in nixpkgs

0 commit comments

Comments
 (0)