Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Nix flake for devShell, create Nix package #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
23 changes: 23 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# SPDX-FileCopyrightText: 2024 Technology Innovation Institute (TII)
# SPDX-FileCopyrightText: 2020-2024 Eelco Dolstra and the flake-compat contributors
#
# SPDX-License-Identifier: MIT
# This file originates from:
# https://github.com/nix-community/flake-compat
# This file provides backward compatibility to nix < 2.4 clients
{system ? builtins.currentSystem}: let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);

inherit (lock.nodes.flake-compat.locked) owner repo rev narHash;

flake-compat = fetchTarball {
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
sha256 = narHash;
};

flake = import flake-compat {
inherit system;
src = ./.;
};
in
flake.defaultNix
111 changes: 111 additions & 0 deletions flake.lock

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

32 changes: 32 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 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";
flake-compat.url = "github:nix-community/flake-compat";

# 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 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 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 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;
};
}
6 changes: 4 additions & 2 deletions shell.nix
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{ pkgs ? import <nixpkgs> {} }:

# Copyright 2024 TII (SSRC) and the Ghaf contributors
# SPDX-License-Identifier: Apache-2.0
{pkgs ? import <nixpkgs> {}}:
pkgs.mkShell {
buildInputs = [
pkgs.glib
Expand All @@ -10,6 +11,7 @@ pkgs.mkShell {
pkgs.rustc
pkgs.cargo
pkgs.protoc-gen-tonic
pkgs.protobuf
];

shellHook = ''
Expand Down