From e3fd1382e94e2537b131127f12150aca19a53907 Mon Sep 17 00:00:00 2001 From: eymeric Date: Mon, 8 Apr 2024 22:47:59 +0200 Subject: [PATCH 1/5] 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 + "; +} From 8e24a2cb6397e11e0837b4b49874d3551843839f Mon Sep 17 00:00:00 2001 From: eymeric Date: Tue, 9 Apr 2024 17:10:38 +0200 Subject: [PATCH 2/5] cleanup nix Co-authored-by: uku --- .gitignore | 1 + flake.lock | 39 +++++++++------------------------- flake.nix | 43 +++++++++++++++++++------------------- packaging/nix/default.nix | 44 ++++++++++++++++++--------------------- 4 files changed, 53 insertions(+), 74 deletions(-) diff --git a/.gitignore b/.gitignore index d2f1ee13..de6d13d3 100644 --- a/.gitignore +++ b/.gitignore @@ -35,6 +35,7 @@ packaging/conda/meta.yaml #nix .direnv/ +result # CLion diff --git a/flake.lock b/flake.lock index 0123ed03..c5276dea 100644 --- a/flake.lock +++ b/flake.lock @@ -2,7 +2,9 @@ "nodes": { "flake-parts": { "inputs": { - "nixpkgs-lib": "nixpkgs-lib" + "nixpkgs-lib": [ + "nixpkgs" + ] }, "locked": { "lastModified": 1712014858, @@ -20,36 +22,15 @@ }, "nixpkgs": { "locked": { - "lastModified": 1712512205, - "narHash": "sha256-CrKKps0h7FoagRcE2LT3h/72Z64D0Oh83UF1XZVhCLQ=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "3c1b6f75344e207a67536d834886ee9b4577ebe7", - "type": "github" + "lastModified": 1712163089, + "narHash": "sha256-Um+8kTIrC19vD4/lUCN9/cU9kcOsD1O1m+axJqQPyMM=", + "path": "/nix/store/n2g5cqwv8qf5p6vjxny6pg3blbdij12k-source", + "rev": "fd281bd6b7d3e32ddfa399853946f782553163b5", + "type": "path" }, "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" + "id": "nixpkgs", + "type": "indirect" } }, "root": { diff --git a/flake.nix b/flake.nix index 3358731b..6500bb0f 100644 --- a/flake.nix +++ b/flake.nix @@ -1,33 +1,34 @@ { - description = "Description for the project"; + description = "C++ UML diagram generator based on Clang"; inputs = { - flake-parts.url = "github:hercules-ci/flake-parts"; - nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + nixpkgs.url = "nixpkgs"; + + flake-parts = { + url = "github:hercules-ci/flake-parts"; + inputs.nixpkgs-lib.follows = "nixpkgs"; + }; }; - 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, ... }: { + outputs = {flake-parts, ...} @ inputs: + flake-parts.lib.mkFlake {inherit inputs;} { + systems = ["x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin"]; - packages.default = config.packages.clang-uml; - packages.clang-uml = pkgs.callPackage packaging/nix/default.nix { }; + perSystem = { + self', + pkgs, + ... + }: { + packages = { + default = self'.packages.clang-uml; + clang-uml = pkgs.callPackage ./packaging/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 - ]; + inputsFrom = [self'.packages.clang-uml]; }; + + formatter = pkgs.alejandra; }; }; } diff --git a/packaging/nix/default.nix b/packaging/nix/default.nix index a632d101..b66794fb 100644 --- a/packaging/nix/default.nix +++ b/packaging/nix/default.nix @@ -1,34 +1,30 @@ -{ pkgs ? import {} }: - - -# Nix derivation for basic C++ project using clang -with pkgs; stdenv.mkDerivation { +{ + stdenv, + cmake, + pkg-config, + installShellFiles, + libclang, + libllvm, + yaml-cpp, +}: +stdenv.mkDerivation { name = "clang-uml"; src = ../..; - buildInputs = [ - clang - libclang + nativeBuildInputs = [ cmake - llvmPackages_latest.libllvm - yaml-cpp - ccache - elfutils pkg-config + installShellFiles ]; - dontUseCmakeConfigure = true; + buildInputs = [ + libclang + libllvm + yaml-cpp + ]; - buildPhase = "CCACHE_DIR=/build/.ccache make release"; - - installPhase = '' - mkdir -p $out/bin - cp release/src/clang-uml $out/bin/clang-uml + postInstall = '' + installShellCompletion --bash $src/packaging/autocomplete/clang-uml + installShellCompletion --zsh $src/packaging/autocomplete/_clang-uml ''; - - postInstall = " - installShellCompletion --cmd clang-uml \ - --zsh packaging/autocomplete/_clang-uml - --bach packaging/autocomplete/clang-uml - "; } From 0da2585c3f2f8af86dd5065e4129963219d7c4c5 Mon Sep 17 00:00:00 2001 From: hatch01 <42416805+hatch01@users.noreply.github.com> Date: Wed, 10 Apr 2024 09:50:58 +0200 Subject: [PATCH 3/5] fix nix run link Co-authored-by: Thomas Lepoix --- docs/installation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/installation.md b/docs/installation.md index 9e9eeb3b..03fab780 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -61,7 +61,7 @@ nix build Or if you have flake enabled, you can also run ```bash -nix run github:/bkryza/clang-uml +nix run github:bkryza/clang-uml ``` #### Windows From 42c9fa4579829713fd206a08c88c078e4a803c89 Mon Sep 17 00:00:00 2001 From: eymeric Date: Thu, 11 Apr 2024 11:22:03 +0200 Subject: [PATCH 4/5] update build command to work without flake Co-authored-by: uku --- docs/installation.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/installation.md b/docs/installation.md index 03fab780..14c62fad 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -56,7 +56,8 @@ conda install -c bkryza/label/clang-uml clang-uml #### nix ```bash -nix build +git clone https://github.com/bkryza/clang-uml +nix-build -E 'with import { }; callPackage ./packaging/nix { }' ``` Or if you have flake enabled, you can also run From a61d719a69f680268971b61962a35bc2b9c927db Mon Sep 17 00:00:00 2001 From: eymeric Date: Wed, 17 Apr 2024 17:58:55 +0200 Subject: [PATCH 5/5] doc: update build instruction for nix --- docs/installation.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/installation.md b/docs/installation.md index 14c62fad..19b9f3ea 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -57,10 +57,15 @@ conda install -c bkryza/label/clang-uml clang-uml ```bash git clone https://github.com/bkryza/clang-uml + +# To build using nix flakes +nix --extra-experimental-features 'nix-command flakes' build + +# or without nix flakes nix-build -E 'with import { }; callPackage ./packaging/nix { }' ``` -Or if you have flake enabled, you can also run +Or if you have flake enabled, you can also directly run ```bash nix run github:bkryza/clang-uml ```