Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[nix] Add nix derivation for static builds #161

Merged
merged 1 commit into from
May 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
hswong3i marked this conversation as resolved.
Show resolved Hide resolved
buildInputs = [
glib
glibc
glibc.static
pcre
systemd
];
saschagrunert marked this conversation as resolved.
Show resolved Hide resolved
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