From e3fd1382e94e2537b131127f12150aca19a53907 Mon Sep 17 00:00:00 2001 From: eymeric Date: Mon, 8 Apr 2024 22:47:59 +0200 Subject: [PATCH] enable building with nix --- .envrc | 1 + .gitignore | 3 ++ docs/installation.md | 11 +++++++ flake.lock | 64 +++++++++++++++++++++++++++++++++++++++ flake.nix | 33 ++++++++++++++++++++ packaging/nix/default.nix | 34 +++++++++++++++++++++ 6 files changed, 146 insertions(+) create mode 100644 .envrc create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 packaging/nix/default.nix diff --git a/.envrc b/.envrc new file mode 100644 index 00000000..a5dbbcba --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake . diff --git a/.gitignore b/.gitignore index 74c9721d..d2f1ee13 100644 --- a/.gitignore +++ b/.gitignore @@ -33,6 +33,9 @@ coverage*.info packaging/_BUILD packaging/conda/meta.yaml +#nix +.direnv/ + # CLion .idea/ diff --git a/docs/installation.md b/docs/installation.md index f009d6c0..9e9eeb3b 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -53,6 +53,17 @@ conda config --set channel_priority strict conda install -c bkryza/label/clang-uml clang-uml ``` +#### nix + +```bash +nix build +``` + +Or if you have flake enabled, you can also run +```bash +nix run github:/bkryza/clang-uml +``` + #### Windows Download and run the latest Windows installer from diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..0123ed03 --- /dev/null +++ b/flake.lock @@ -0,0 +1,64 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1712014858, + "narHash": "sha256-sB4SWl2lX95bExY2gMFG5HIzvva5AVMJd4Igm+GpZNw=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "9126214d0a59633752a136528f5f3b9aa8565b7d", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1712512205, + "narHash": "sha256-CrKKps0h7FoagRcE2LT3h/72Z64D0Oh83UF1XZVhCLQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "3c1b6f75344e207a67536d834886ee9b4577ebe7", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "dir": "lib", + "lastModified": 1711703276, + "narHash": "sha256-iMUFArF0WCatKK6RzfUJknjem0H9m4KgorO/p3Dopkk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "d8fe5e6c92d0d190646fb9f1056741a229980089", + "type": "github" + }, + "original": { + "dir": "lib", + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..3358731b --- /dev/null +++ b/flake.nix @@ -0,0 +1,33 @@ +{ + description = "Description for the project"; + + inputs = { + flake-parts.url = "github:hercules-ci/flake-parts"; + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + }; + + outputs = inputs@{ flake-parts, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + imports = []; + systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ]; + perSystem = { config, self', inputs', pkgs, system, ... }: { + + packages.default = config.packages.clang-uml; + packages.clang-uml = pkgs.callPackage packaging/nix/default.nix { }; + + devShells.default = pkgs.mkShell { + packages = with pkgs; [ + # C++ Compiler is already part of stdenv + cmake + llvmPackages_latest.libllvm + yaml-cpp + ccache + elfutils + pkg-config + clang + libclang + ]; + }; + }; + }; +} diff --git a/packaging/nix/default.nix b/packaging/nix/default.nix new file mode 100644 index 00000000..a632d101 --- /dev/null +++ b/packaging/nix/default.nix @@ -0,0 +1,34 @@ +{ pkgs ? import {} }: + + +# Nix derivation for basic C++ project using clang +with pkgs; stdenv.mkDerivation { + name = "clang-uml"; + src = ../..; + + buildInputs = [ + clang + libclang + cmake + llvmPackages_latest.libllvm + yaml-cpp + ccache + elfutils + pkg-config + ]; + + dontUseCmakeConfigure = true; + + buildPhase = "CCACHE_DIR=/build/.ccache make release"; + + installPhase = '' + mkdir -p $out/bin + cp release/src/clang-uml $out/bin/clang-uml + ''; + + postInstall = " + installShellCompletion --cmd clang-uml \ + --zsh packaging/autocomplete/_clang-uml + --bach packaging/autocomplete/clang-uml + "; +}