diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..9ee556b --- /dev/null +++ b/.envrc @@ -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 diff --git a/.gitignore b/.gitignore index eb5a316..d6ef431 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ target +.direnv/ +result diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..7542c52 --- /dev/null +++ b/flake.lock @@ -0,0 +1,95 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1719994518, + "narHash": "sha256-pQMhCCHyQGRzdfAkdJ4cIWiw+JNuWsTX7f0ZYSyz0VY=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "9227223f6d922fee3c7b190b2cc238a99527bbb7", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "flake-root": { + "locked": { + "lastModified": 1713493429, + "narHash": "sha256-ztz8JQkI08tjKnsTpfLqzWoKFQF4JGu2LRz8bkdnYUk=", + "owner": "srid", + "repo": "flake-root", + "rev": "bc748b93b86ee76e2032eecda33440ceb2532fcd", + "type": "github" + }, + "original": { + "owner": "srid", + "repo": "flake-root", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1720031269, + "narHash": "sha256-rwz8NJZV+387rnWpTYcXaRNvzUSnnF9aHONoJIYmiUQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9f4128e00b0ae8ec65918efeba59db998750ead6", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1719876945, + "narHash": "sha256-Fm2rDDs86sHy0/1jxTOKB1118Q0O3Uc7EC0iXvXKpbI=", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/5daf0514482af3f97abaefc78a6606365c9108e2.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/5daf0514482af3f97abaefc78a6606365c9108e2.tar.gz" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "flake-root": "flake-root", + "nixpkgs": "nixpkgs", + "treefmt-nix": "treefmt-nix" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1720436211, + "narHash": "sha256-/cKXod0oGLl+vH4bKBZnTV3qxrw4jgOLnyQ8KXey5J8=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "6fc8bded78715cdd43a3278a14ded226eb3a239e", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..10795d1 --- /dev/null +++ b/flake.nix @@ -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 {}; + }; + }; +} diff --git a/nix/default.nix b/nix/default.nix new file mode 100644 index 0000000..c8f281b --- /dev/null +++ b/nix/default.nix @@ -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 = ./..; +} diff --git a/nix/devshell.nix b/nix/devshell.nix new file mode 100644 index 0000000..e7d5c34 --- /dev/null +++ b/nix/devshell.nix @@ -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"; + }; + }; +} diff --git a/nix/treefmt.nix b/nix/treefmt.nix new file mode 100644 index 0000000..89b82a8 --- /dev/null +++ b/nix/treefmt.nix @@ -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; + }; +} diff --git a/shell.nix b/shell.nix deleted file mode 100755 index 40390dd..0000000 --- a/shell.nix +++ /dev/null @@ -1,18 +0,0 @@ -{ pkgs ? import {} }: - -pkgs.mkShell { - buildInputs = [ - pkgs.glib - pkgs.gtk4 - pkgs.libadwaita - pkgs.pkg-config - pkgs.gcc - pkgs.rustc - pkgs.cargo - pkgs.protoc-gen-tonic - ]; - - shellHook = '' - export PKG_CONFIG_PATH="${pkgs.glib.dev}/lib/pkgconfig:${pkgs.gtk4.dev}/lib/pkgconfig" - ''; -}