Skip to content

Commit

Permalink
Add nix derivation for static builds
Browse files Browse the repository at this point in the history
  • Loading branch information
hswong3i committed May 27, 2020
1 parent 27bb67e commit 026f232
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,5 @@ dkms.conf
bin/

vendor/

result
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ containerized: bin
static:
$(MAKE) git-vars bin/conmon PKG_CONFIG='$(PKG_CONFIG) --static' CFLAGS='-static' LDFLAGS='$(LDFLAGS) -s -w -static' LIBS='$(LIBS)'

nixpkgs:
@nix run -f channel:nixpkgs-unstable nix-prefetch-git -c nix-prefetch-git \
--no-deepClone https://github.com/nixos/nixpkgs > nix/nixpkgs.json

bin/conmon: $(OBJS) | bin
$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^ $(LIBS)

Expand Down
48 changes: 48 additions & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{ system ? builtins.currentSystem }:
let
pkgs = (import ./nixpkgs.nix {
overlays = [ (final: prev: {
pcre = prev.pcre.overrideAttrs (x: {
configureFlags = x.configureFlags ++ [ "--enable-static" ];
});
})];
config = {
packageOverrides = pkg: {
glib = pkg.glib.overrideAttrs(x: {
outputs = [ "bin" "out" "dev" ];
mesonFlags = [
"-Ddefault_library=static"
"-Ddevbindir=${placeholder ''dev''}/bin"
"-Dgtk_doc=false"
"-Dnls=disabled"
];
});
systemd = pkg.systemd.overrideAttrs(x: {
mesonFlags = x.mesonFlags ++ [ "-Dstatic-libsystemd=true" ];
postFixup = ''
${x.postFixup}
sed -ri "s;$out/(.*);$nukedRef/\1;g" $lib/lib/libsystemd.a
'';
});
};
};
});

self = with pkgs; {
conmon-static = (conmon.overrideAttrs(x: {
name = "conmon-static";
src = ./..;
doCheck = false;
buildInputs = [
glib
glibc
glibc.static
pcre
systemd
];
prePatch = ''
export LDFLAGS="-static-libgcc -static"
'';
}));
};
in self
10 changes: 10 additions & 0 deletions nix/nixpkgs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"url": "https://github.com/nixos/nixpkgs",
"rev": "1b5925f2189dc9b4ebf7168252bf89a94b7405ba",
"date": "2020-05-27T15:03:28+02:00",
"path": "/nix/store/qdsrj7hw9wzzng9l2kfbsyi9ynprrn6p-nixpkgs",
"sha256": "0q9plknr294k4bjfqvgvp5vglfby5yn64k6ml0gqwi0dwf0qi6fv",
"fetchSubmodules": false,
"deepClone": false,
"leaveDotGit": false
}
8 changes: 8 additions & 0 deletions nix/nixpkgs.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
let
json = builtins.fromJSON (builtins.readFile ./nixpkgs.json);
nixpkgs = import (builtins.fetchTarball {
name = "nixos-unstable";
url = "${json.url}/archive/${json.rev}.tar.gz";
inherit (json) sha256;
});
in nixpkgs

0 comments on commit 026f232

Please sign in to comment.