From 47ecd0ac4a7b7b5d68605044d0b1560ba31c824f Mon Sep 17 00:00:00 2001 From: Michael Livshin Date: Sun, 30 Apr 2023 14:12:35 +0300 Subject: [PATCH] chore(nix): add Nix flake --- flake.lock | 48 ++++++++++++++++++++++++++++++++++++ flake.nix | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..15e48b0 --- /dev/null +++ b/flake.lock @@ -0,0 +1,48 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1682566018, + "narHash": "sha256-HPzPRFiy2o/7k7mtnwfM1E6NVZHiFbPdmYCMoIpkHO4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "8e3b64db39f2aaa14b35ee5376bd6a2e707cadc2", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "parts": { + "inputs": { + "nixpkgs-lib": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1680392223, + "narHash": "sha256-n3g7QFr85lDODKt250rkZj2IFS3i4/8HBU2yKHO3tqw=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "dcc36e45d054d7bb554c9cdab69093debd91a0b5", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "parts": "parts" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..bbff674 --- /dev/null +++ b/flake.nix @@ -0,0 +1,71 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + parts = { + url = "github:hercules-ci/flake-parts"; + inputs.nixpkgs-lib.follows = "nixpkgs"; + }; + }; + outputs = inputs @ { + self, + nixpkgs, + parts, + ... + }: let + inherit (builtins) attrValues; + in parts.lib.mkFlake { inherit inputs; } { + systems = ["x86_64-linux" "x86-linux" "aarch64-linux"]; + + perSystem = { pkgs, system, ... }: { + packages.system76-scheduler = pkgs.rustPlatform.buildRustPackage { + name = "system76-scheduler"; + src = ./.; + cargoLock = { + lockFile = ./Cargo.lock; + # Allow dependencies to be fetched from git and avoid having to set the outputHashes manually + allowBuiltinFetchGit = true; + }; + + nativeBuildInputs = attrValues { + inherit (pkgs) + pkg-config + llvm + clang + ; + }; + buildInputs = attrValues { + inherit (pkgs) + dbus + pipewire + ; + }; + + LIBCLANG_PATH = "${pkgs.libclang.lib}/lib"; + EXECSNOOP_PATH = "${pkgs.bcc}/bin/execsnoop"; + + # tests don't build + doCheck = false; + + postInstall = '' + mkdir -p $out/data + install -D -m 0644 data/com.system76.Scheduler.conf $out/etc/dbus-1/system.d/com.system76.Scheduler.conf + install -D -m 0644 data/*.kdl $out/data/ + ''; + }; + + packages.default = self.outputs.packages.${system}.system76-scheduler; + + devShells.default = self.packages.${system}.default.overrideAttrs (super: { + nativeBuildInputs = super.nativeBuildInputs + ++ (attrValues { + inherit (pkgs) + cargo-edit + clippy + rustfmt + ; + }); + RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}"; + }); + }; + }; +}