From e15a737260e181162954608f166be307b4d9bcbe Mon Sep 17 00:00:00 2001 From: Joakim Lundborg Date: Mon, 27 Mar 2023 01:18:20 +0200 Subject: [PATCH] Add initial nix flake --- .github/workflows/build_nix.yml | 13 ++++++ default.nix | 7 +++ flake.lock | 77 +++++++++++++++++++++++++++++++++ flake.nix | 51 ++++++++++++++++++++++ shell.nix | 7 +++ 5 files changed, 155 insertions(+) create mode 100644 .github/workflows/build_nix.yml create mode 100644 default.nix create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 shell.nix diff --git a/.github/workflows/build_nix.yml b/.github/workflows/build_nix.yml new file mode 100644 index 00000000..2f684e11 --- /dev/null +++ b/.github/workflows/build_nix.yml @@ -0,0 +1,13 @@ +name: "Build legacy Nix package on Ubuntu" + +on: + push: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: cachix/install-nix-action@v12 + - name: Building package + run: nix-build . -A defaultPackage.x86_64-linux diff --git a/default.nix b/default.nix new file mode 100644 index 00000000..39bacff6 --- /dev/null +++ b/default.nix @@ -0,0 +1,7 @@ +(import ( + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz"; + sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; } +) { + src = ./.; +}).defaultNix diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..77fc576d --- /dev/null +++ b/flake.lock @@ -0,0 +1,77 @@ +{ + "nodes": { + "naersk": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1679567394, + "narHash": "sha256-ZvLuzPeARDLiQUt6zSZFGOs+HZmE+3g4QURc8mkBsfM=", + "owner": "nix-community", + "repo": "naersk", + "rev": "88cd22380154a2c36799fe8098888f0f59861a15", + "type": "github" + }, + "original": { + "owner": "nix-community", + "ref": "master", + "repo": "naersk", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1679793451, + "narHash": "sha256-JafTtgMDATE8dZOImBhWMA9RCn9AP8FVOpN+9K/tTlg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "0cd51a933d91078775b300cf0f29aa3495231aa2", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1679793451, + "narHash": "sha256-JafTtgMDATE8dZOImBhWMA9RCn9AP8FVOpN+9K/tTlg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "0cd51a933d91078775b300cf0f29aa3495231aa2", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "naersk": "naersk", + "nixpkgs": "nixpkgs_2", + "utils": "utils" + } + }, + "utils": { + "locked": { + "lastModified": 1678901627, + "narHash": "sha256-U02riOqrKKzwjsxc/400XnElV+UtPUQWpANPlyazjH0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "93a2b84fc4b70d9e089d029deacc3583435c2ed6", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..59de5083 --- /dev/null +++ b/flake.nix @@ -0,0 +1,51 @@ +{ + inputs = { + naersk.url = "github:nix-community/naersk/master"; + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, utils, naersk }: + + utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; }; + naersk-lib = pkgs.callPackage naersk { }; + in + { + formatter.x86_64-linux = nixpkgs.legacyPackages.nixfmt; + defaultPackage = naersk-lib.buildPackage ./.; + devShell = with pkgs; mkShell { + LIBCLANG_PATH = "${pkgs.llvmPackages.libclang}/lib/libclang.so"; + + nativeBuildInputs = [ + openssl + pkg-config + ]; + + # necessary to override nix's defaults which cannot be overriden as others are + shellHook = '' + export CC="${pkgs.clang}/bin/clang" + export CXX="${pkgs.clang}/bin/clang++" + export LIBCLANG_PATH="${pkgs.libclang.lib}/lib" + rustup override set stable + ''; + + buildInputs = [ + cargo + rustc + rustfmt + pre-commit + rustPackages.clippy + openssl + pkg-config + libgpg-error + clang + nettle + libclang + gpgme + ]; + RUST_SRC_PATH = rustPlatform.rustLibSrc; + }; + }); +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 00000000..77db547f --- /dev/null +++ b/shell.nix @@ -0,0 +1,7 @@ +(import ( + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz"; + sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; } +) { + src = ./.; +}).shellNix