Skip to content
Merged
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
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
/.flatpak/
/vendor
/.vscode
.flatpak-builder/
.flatpak-builder/
result
.direnv
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ flatpak install --user org.gnome.Sdk//46 org.gnome.Platform//46 org.freedesktop
flatpak-builder --user flatpak_app build-aux/<application_id>.Devel.json
```

### NixOS
```bash
nix build . --show-trace
```

## Running the project

Once the project is build, run the command below. Replace `<application_id>` and `<project_name>` 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.
Expand All @@ -73,6 +78,13 @@ Once the project is build, run the command below. Replace `<application_id>` and
flatpak-builder --run flatpak_app build-aux/<application_id>.Devel.json <project_name>
```

### 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.
Expand Down
72 changes: 72 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -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
];
}
61 changes: 61 additions & 0 deletions flake.lock

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

29 changes: 29 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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;};
});
}
46 changes: 46 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -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}";
}
Loading