Skip to content

Commit

Permalink
Use Nix flake for devShell, create Nix package
Browse files Browse the repository at this point in the history
Signed-off-by: Humaid Alqasimi <humaid.alqassimi@tii.ae>
  • Loading branch information
humaidq-tii committed Jul 8, 2024
1 parent a38c33c commit 76ea602
Show file tree
Hide file tree
Showing 8 changed files with 231 additions and 18 deletions.
4 changes: 4 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if ! has nix_direnv_version || ! nix_direnv_version 3.0.5; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.5/direnvrc" "sha256-RuwIS+QKFj/T9M2TFXScjBsLR6V3A17YVoEW/Q6AZ1w="
fi
use flake
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
target
.direnv/
result
95 changes: 95 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors
# SPDX-License-Identifier: Apache-2.0
{
description = "Ghaf Control Panel Flake";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";

# Modularity
flake-parts.url = "github:hercules-ci/flake-parts";
flake-root.url = "github:srid/flake-root";

# Formatting
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = inputs @ {flake-parts, ...}:
flake-parts.lib.mkFlake {inherit inputs;} {
imports = [
./nix/treefmt.nix
./nix/devshell.nix
];
systems = ["x86_64-linux" "aarch64-linux" "riscv64-linux"];
perSystem = {pkgs, ...}: {
packages.default = pkgs.callPackage ./nix {};
};
};
}
50 changes: 50 additions & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors
# SPDX-License-Identifier: Apache-2.0
{
cargo,
glib,
gtk4,
lib,
libadwaita,
librsvg,
pkg-config,
protobuf,
protoc-gen-tonic,
rustPlatform,
rustc,
version ? "git",
}:
rustPlatform.buildRustPackage {
pname = "ghaf-ctrl-panel";
inherit version;
meta = with lib; {
description = "Ghaf Control Panel";
license = licenses.asl20;
mainProgram = "ctrl-panel";
};

buildInputs = [
gtk4
glib
libadwaita
];

nativeBuildInputs = [
gtk4
glib
rustPlatform.cargoSetupHook
rustc
cargo
pkg-config
protoc-gen-tonic
protobuf
];

gappsWrapperArgs = ''
--prefix XDG_DATA_DIRS : "${librsvg}/share"
'';

cargoLock.lockFile = ../Cargo.lock;

src = ./..;
}
22 changes: 22 additions & 0 deletions nix/devshell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors
# SPDX-License-Identifier: Apache-2.0
{
perSystem = {pkgs, ...}: {
devShells.default = pkgs.mkShell {
packages = [
pkgs.bashInteractive

pkgs.glib
pkgs.gtk4
pkgs.libadwaita
pkgs.pkg-config
pkgs.gcc
pkgs.rustc
pkgs.cargo
pkgs.protoc-gen-tonic
pkgs.protobuf
];
PKG_CONFIG_PATH = "${pkgs.glib.dev}/lib/pkgconfig:${pkgs.gtk4.dev}/lib/pkgconfig";
};
};
}
27 changes: 27 additions & 0 deletions nix/treefmt.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors
# SPDX-License-Identifier: Apache-2.0
{inputs, ...}: {
imports = with inputs; [
flake-root.flakeModule
treefmt-nix.flakeModule
];
perSystem = {
config,
pkgs,
...
}: {
treefmt.config = {
package = pkgs.treefmt;
inherit (config.flake-root) projectRootFile;

programs = {
alejandra.enable = true;
deadnix.enable = true;
statix.enable = true;
rustfmt.enable = true;
};
};

formatter = config.treefmt.build.wrapper;
};
}
18 changes: 0 additions & 18 deletions shell.nix

This file was deleted.

0 comments on commit 76ea602

Please # to comment.