Skip to content

Commit ac3d44d

Browse files
committed
Add advanced flake.nix
1 parent 8a97ebc commit ac3d44d

2 files changed

Lines changed: 142 additions & 0 deletions

File tree

flake.lock

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{
2+
description = "Development environment & packaging for OpenCL-Headers";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
flake-utils.url = "github:numtide/flake-utils";
7+
};
8+
9+
outputs = { self, nixpkgs, flake-utils }:
10+
flake-utils.lib.eachDefaultSystem (system:
11+
let
12+
pkgs = nixpkgs.legacyPackages.${system};
13+
in {
14+
checks.c-tests = pkgs.stdenv.mkDerivation {
15+
name = "opencl-headers-c-tests";
16+
nativeBuildInputs = [ pkgs.cmake ];
17+
18+
src = ./.;
19+
20+
cmakeFlags = [
21+
"-DOPENCL_HEADERS_BUILD_TESTING=ON"
22+
"-DOPENCL_HEADERS_BUILD_CXX_TESTS=OFF"
23+
];
24+
25+
doCheck = true;
26+
};
27+
checks.cpp-tests = self.packages.${system}.default;
28+
checks.pkg-config = self.packages.${system}.default.passthru.tests.pkg-config;
29+
30+
packages.default = pkgs.stdenv.mkDerivation (finalAttrs: rec {
31+
name = "opencl-headers";
32+
nativeBuildInputs = [ pkgs.cmake ];
33+
34+
src = ./.;
35+
36+
doCheck = true;
37+
38+
passthru.tests = with pkgs; {
39+
pkg-config = pkgs.testers.hasPkgConfigModules {
40+
package = finalAttrs.finalPackage;
41+
moduleNames = [ "OpenCL-Headers" ];
42+
};
43+
};
44+
});
45+
46+
devShells.default = pkgs.mkShell {
47+
buildInputs = [
48+
pkgs.pkg-config
49+
self.packages.${system}.default
50+
];
51+
52+
doCheck = false; # Disables automatically running tests for `$ nix develop` and direnv
53+
54+
shellHook = ''
55+
export ZDOTDIR=$(mktemp -d)
56+
cat > "$ZDOTDIR/.zshrc" << 'EOF'
57+
source ~/.zshrc # Source the original ~/.zshrc, required.
58+
59+
function parse_git_branch {
60+
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\ ->\ \1/'
61+
}
62+
63+
function display_jobs_count_if_needed {
64+
local job_count=$(jobs -s | wc -l | tr -d " ")
65+
66+
if [ $job_count -gt 0 ]; then
67+
echo "%B%F{yellow}%j| ";
68+
fi
69+
}
70+
71+
# NOTE: Custom prompt with a snowflake: signals we are in `$ nix develop` shell
72+
PROMPT="%F{blue}$(date +%H:%M:%S) $(display_jobs_count_if_needed)%B%F{green}%n %F{blue}%~%F{cyan} ❄%F{yellow}$(parse_git_branch) %f%{$reset_color%}"
73+
EOF
74+
75+
if [ -z "$DIRENV_IN_ENVRC" ]; then # This makes `$ nix develop` universally working with direnv without infinite loop
76+
exec ${pkgs.zsh}/bin/zsh -i
77+
fi
78+
'';
79+
};
80+
});
81+
}

0 commit comments

Comments
 (0)