From f3da5f213e1925dcbccfaf00e8981e4b9ba4c3ce Mon Sep 17 00:00:00 2001 From: bahrom04 Date: Sat, 20 Dec 2025 10:51:27 +0500 Subject: [PATCH 1/3] chore: reorder packets --- .envrc | 1 + default.nix | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.lock | 61 +++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 29 +++++++++++++++++++++ shell.nix | 46 ++++++++++++++++++++++++++++++++++ 5 files changed, 209 insertions(+) create mode 100644 .envrc create mode 100644 default.nix create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 shell.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..8392d15 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake \ No newline at end of file diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..d93d8a2 --- /dev/null +++ b/default.nix @@ -0,0 +1,72 @@ +{ + pkgs ? let + lock = (builtins.fromJSON (builtins.readFile ./flake.lock)).nodes.nixpkgs.locked; + nixpkgs = fetchTarball { + url = "https://github.com/nixos/nixpkgs/archive/${lock.rev}.tar.gz"; + sha256 = lock.narHash; + }; + in + import nixpkgs {overlays = [];}, + ... +}: let + # Helpful nix function + getLibFolder = pkg: "${pkg}/lib"; + + # Manifest via Cargo.toml + manifest = (pkgs.lib.importTOML ./Cargo.toml).package; +in + pkgs.stdenv.mkDerivation { + pname = manifest.name; + version = manifest.version; + + src = pkgs.lib.cleanSource ./.; + + cargoDeps = pkgs.rustPlatform.importCargoLock { + lockFile = ./Cargo.lock; + # Use this if you have dependencies from git instead + # of crates.io in your Cargo.toml + # outputHashes = { + # # Sha256 of the git repository, doesn't matter if it's monorepo + # "example-0.1.0" = "sha256-80EwvwMPY+rYyti8DMG4hGEpz/8Pya5TGjsbOBF0P0c="; + # }; + }; + + # Compile time dependencies + nativeBuildInputs = with pkgs; [ + git + rustc + cargo + ninja + meson + clippy + gettext + pkg-config + rust-analyzer + wrapGAppsHook4 + appstream-glib + desktop-file-utils + rustPlatform.cargoSetupHook + ]; + + # Runtime dependencies which will be shipped + # with nix package + buildInputs = with pkgs; [ + gtk4 + glib + openssl + libadwaita + gdk-pixbuf + gnome-desktop + adwaita-icon-theme + desktop-file-utils + rustPlatform.bindgenHook + ]; + + # Compiler LD variables + NIX_LDFLAGS = "-L${(getLibFolder pkgs.libiconv)}"; + LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [ + pkgs.gcc + pkgs.libiconv + pkgs.llvmPackages.llvm + ]; + } diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..715c899 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1766070988, + "narHash": "sha256-G/WVghka6c4bAzMhTwT2vjLccg/awmHkdKSd2JrycLc=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "c6245e83d836d0433170a16eb185cefe0572f8b8", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..70640c7 --- /dev/null +++ b/flake.nix @@ -0,0 +1,29 @@ +{ + description = "nixed gtk-rust-template"; + + inputs = { + # Fresh and new for testing + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + + # The flake-utils library + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { + nixpkgs, + flake-utils, + ... + }: + flake-utils.lib.eachDefaultSystem (system: let + pkgs = import nixpkgs {inherit system;}; + in { + # Nix script formatter + formatter = pkgs.alejandra; + + # Development environment + devShells.default = import ./shell.nix {inherit pkgs;}; + + # Output package + packages.default = pkgs.callPackage ./. {inherit pkgs;}; + }); +} \ No newline at end of file diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..f8611b2 --- /dev/null +++ b/shell.nix @@ -0,0 +1,46 @@ +{pkgs, ...}: let + # Manifest via Cargo.toml + manifest = (pkgs.lib.importTOML ./Cargo.toml).package; +in + pkgs.stdenv.mkDerivation { + name = "${manifest.name}-dev"; + + # Compile time dependencies + nativeBuildInputs = with pkgs; [ + # Hail the Nix + nixd + statix + deadnix + alejandra + + # Rust + rustc + cargo + rustfmt + clippy + rust-analyzer + cargo-watch + + # Other compile time dependencies + openssl + + # Gnome related + gtk4 + meson + ninja + parted + gettext + pkg-config + gdk-pixbuf + libadwaita + gnome-desktop + wrapGAppsHook4 + desktop-file-utils + gobject-introspection + rustPlatform.bindgenHook + ]; + + # Set Environment Variables + RUST_BACKTRACE = "full"; + RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; + } \ No newline at end of file From 5bf1bdf3e631b1d80806051bfa512fab89068be1 Mon Sep 17 00:00:00 2001 From: bahrom04 Date: Sat, 20 Dec 2025 11:10:36 +0500 Subject: [PATCH 2/3] chore: added nix caches to .gitignore --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1775329..947bb5f 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,6 @@ /.flatpak/ /vendor /.vscode -.flatpak-builder/ \ No newline at end of file +.flatpak-builder/ +result +.direnv \ No newline at end of file From 6e35defebfe91d800501b98f9c8f0e69c40a6275 Mon Sep 17 00:00:00 2001 From: bahrom04 Date: Sat, 20 Dec 2025 11:11:05 +0500 Subject: [PATCH 3/3] decs: added NixOS run & build instruction --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index d52117c..a02ad15 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,11 @@ flatpak install --user org.gnome.Sdk//46 org.gnome.Platform//46 org.freedesktop flatpak-builder --user flatpak_app build-aux/.Devel.json ``` +### NixOS +```bash +nix build . --show-trace +``` + ## Running the project Once the project is build, run the command below. Replace `` and `` with the values you entered during project creation. Please note that these commands are just for demonstration purposes. Normally this would be handled by your IDE, such as GNOME Builder or VS Code with the Flatpak extension. @@ -73,6 +78,13 @@ Once the project is build, run the command below. Replace `` and flatpak-builder --run flatpak_app build-aux/.Devel.json ``` +### NixOS +```bash +nix run +# or +cd .. && ./relm4-template/result/bin/gtk-rust-template +``` + ## Translations with Gettext The template uses `gettext` as a framework for translations using [`gettext-rs`](https://github.com/gettext-rs/gettext-rs). The basic files for this can be found in the `po` folder.