From 5c16665b7b7fabea2b372a9250477bb9ec46c63f Mon Sep 17 00:00:00 2001 From: Shuxian Wang Date: Wed, 4 Jan 2023 01:28:47 -0800 Subject: [PATCH] Add Nix flake. --- .gitignore | 1 + flake.lock | 178 +++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 72 ++++++++++++++++++++++ 3 files changed, 251 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.gitignore b/.gitignore index ce7463a6..2a17cbc6 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ _build/ builddir/ vendor/ vendor.tar +/result build-aux/app build-aux/.flatpak-builder/ diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..9e570c51 --- /dev/null +++ b/flake.lock @@ -0,0 +1,178 @@ +{ + "nodes": { + "crane": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "nixpkgs": [ + "nixpkgs" + ], + "rust-overlay": "rust-overlay" + }, + "locked": { + "lastModified": 1672095661, + "narHash": "sha256-7NTsdCn3qsvU7A+1/7tY8pxbq0DYy1pFYNpzN6he9lI=", + "owner": "ipetkov", + "repo": "crane", + "rev": "98894bb39b03bfb379c5e10523cd61160e1ac782", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "fenix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1672468395, + "narHash": "sha256-eIrQGHZub98IiLqtFXa00ooHBCjtKY+rfKJs5lhyF/c=", + "owner": "nix-community", + "repo": "fenix", + "rev": "d6f9bdfb4a25395b15f6c6feba3d0bba5e62b3ce", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1668681692, + "narHash": "sha256-Ht91NGdewz8IQLtWZ9LCeNXMSXHUss+9COoqu6JLmXU=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "009399224d5e398d03b22badca40a37ac85412a1", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nix-filter": { + "locked": { + "lastModified": 1666547822, + "narHash": "sha256-razwnAybPHyoAyhkKCwXdxihIqJi1G6e1XP4FQOJTEs=", + "owner": "numtide", + "repo": "nix-filter", + "rev": "1a3b735e13e90a8d2fd5629f2f8363bd7ffbbec7", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "nix-filter", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1672428209, + "narHash": "sha256-eejhqkDz2cb2vc5VeaWphJz8UXNuoNoM8/Op8eWv2tQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "293a28df6d7ff3dec1e61e37cc4ee6e6c0fb0847", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "crane": "crane", + "fenix": "fenix", + "flake-utils": "flake-utils_2", + "nix-filter": "nix-filter", + "nixpkgs": "nixpkgs" + } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1672438471, + "narHash": "sha256-bB/7XFnRgGhOhYY6HIov7eF/qnR5NPtKtSfDa2aWqh8=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "0d76b94c90a20c20d3e57ea1ab03d9afa00dee72", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": [ + "crane", + "flake-utils" + ], + "nixpkgs": [ + "crane", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1670034122, + "narHash": "sha256-EqmuOKucPWtMvCZtHraHr3Q3bgVszq1x2PoZtQkUuEk=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "a0d5773275ecd4f141d792d3a0376277c0fc0b65", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..72183fd1 --- /dev/null +++ b/flake.nix @@ -0,0 +1,72 @@ +{ + description = "Applets for the COSMIC desktop environment"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + nix-filter.url = "github:numtide/nix-filter"; + crane = { + url = "github:ipetkov/crane"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + fenix = { + url = "github:nix-community/fenix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { self, nixpkgs, flake-utils, nix-filter, crane, fenix }: + flake-utils.lib.eachSystem [ "x86_64-linux" "aarch64-linux" ] (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + craneLib = crane.lib.${system}.overrideToolchain fenix.packages.${system}.stable.toolchain; + + pkgDef = { + src = nix-filter.lib.filter { + root = ./.; + exclude = [ + ./.gitignore + ./flake.nix + ./flake.lock + ./LICENSE + ./justfile + ./debian + ]; + }; + nativeBuildInputs = with pkgs; [ pkg-config autoPatchelfHook ]; + buildInputs = with pkgs; [ + libxkbcommon + glib # For gobject + libglvnd # For libEGL + libpulseaudio + ]; + runtimeDependencies = with pkgs; [ wayland libglvnd ]; + }; + + cargoArtifacts = craneLib.buildDepsOnly pkgDef; + cosmic-applets = craneLib.buildPackage (pkgDef // { + inherit cargoArtifacts; + }); + in { + checks = { + inherit cosmic-applets; + }; + + packages.default = cosmic-applets; + + apps.default = flake-utils.lib.mkApp { + drv = cosmic-applets; + }; + + devShells.default = pkgs.mkShell rec { + inputsFrom = builtins.attrValues self.checks.${system}; + LD_LIBRARY_PATH = pkgs.lib.strings.makeLibraryPath (builtins.concatMap (d: d.runtimeDependencies) inputsFrom); + }; + }); + + nixConfig = { + # Cache for the Rust toolchain in fenix + extra-substituters = [ "https://nix-community.cachix.org" ]; + extra-trusted-public-keys = [ "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" ]; + }; +}