Skip to content

Commit 41f89c3

Browse files
authored
Merge pull request #48 from bahrom04/nixed-template
Support development with NixOS
2 parents 8314c3a + 6e35def commit 41f89c3

File tree

7 files changed

+224
-1
lines changed

7 files changed

+224
-1
lines changed

.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@
1010
/.flatpak/
1111
/vendor
1212
/.vscode
13-
.flatpak-builder/
13+
.flatpak-builder/
14+
result
15+
.direnv

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ flatpak install --user org.gnome.Sdk//46 org.gnome.Platform//46 org.freedesktop
6565
flatpak-builder --user flatpak_app build-aux/<application_id>.Devel.json
6666
```
6767

68+
### NixOS
69+
```bash
70+
nix build . --show-trace
71+
```
72+
6873
## Running the project
6974

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

81+
### NixOS
82+
```bash
83+
nix run
84+
# or
85+
cd .. && ./relm4-template/result/bin/gtk-rust-template
86+
```
87+
7688
## Translations with Gettext
7789

7890
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.

default.nix

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
pkgs ? let
3+
lock = (builtins.fromJSON (builtins.readFile ./flake.lock)).nodes.nixpkgs.locked;
4+
nixpkgs = fetchTarball {
5+
url = "https://github.com/nixos/nixpkgs/archive/${lock.rev}.tar.gz";
6+
sha256 = lock.narHash;
7+
};
8+
in
9+
import nixpkgs {overlays = [];},
10+
...
11+
}: let
12+
# Helpful nix function
13+
getLibFolder = pkg: "${pkg}/lib";
14+
15+
# Manifest via Cargo.toml
16+
manifest = (pkgs.lib.importTOML ./Cargo.toml).package;
17+
in
18+
pkgs.stdenv.mkDerivation {
19+
pname = manifest.name;
20+
version = manifest.version;
21+
22+
src = pkgs.lib.cleanSource ./.;
23+
24+
cargoDeps = pkgs.rustPlatform.importCargoLock {
25+
lockFile = ./Cargo.lock;
26+
# Use this if you have dependencies from git instead
27+
# of crates.io in your Cargo.toml
28+
# outputHashes = {
29+
# # Sha256 of the git repository, doesn't matter if it's monorepo
30+
# "example-0.1.0" = "sha256-80EwvwMPY+rYyti8DMG4hGEpz/8Pya5TGjsbOBF0P0c=";
31+
# };
32+
};
33+
34+
# Compile time dependencies
35+
nativeBuildInputs = with pkgs; [
36+
git
37+
rustc
38+
cargo
39+
ninja
40+
meson
41+
clippy
42+
gettext
43+
pkg-config
44+
rust-analyzer
45+
wrapGAppsHook4
46+
appstream-glib
47+
desktop-file-utils
48+
rustPlatform.cargoSetupHook
49+
];
50+
51+
# Runtime dependencies which will be shipped
52+
# with nix package
53+
buildInputs = with pkgs; [
54+
gtk4
55+
glib
56+
openssl
57+
libadwaita
58+
gdk-pixbuf
59+
gnome-desktop
60+
adwaita-icon-theme
61+
desktop-file-utils
62+
rustPlatform.bindgenHook
63+
];
64+
65+
# Compiler LD variables
66+
NIX_LDFLAGS = "-L${(getLibFolder pkgs.libiconv)}";
67+
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
68+
pkgs.gcc
69+
pkgs.libiconv
70+
pkgs.llvmPackages.llvm
71+
];
72+
}

flake.lock

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
description = "nixed gtk-rust-template";
3+
4+
inputs = {
5+
# Fresh and new for testing
6+
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
7+
8+
# The flake-utils library
9+
flake-utils.url = "github:numtide/flake-utils";
10+
};
11+
12+
outputs = {
13+
nixpkgs,
14+
flake-utils,
15+
...
16+
}:
17+
flake-utils.lib.eachDefaultSystem (system: let
18+
pkgs = import nixpkgs {inherit system;};
19+
in {
20+
# Nix script formatter
21+
formatter = pkgs.alejandra;
22+
23+
# Development environment
24+
devShells.default = import ./shell.nix {inherit pkgs;};
25+
26+
# Output package
27+
packages.default = pkgs.callPackage ./. {inherit pkgs;};
28+
});
29+
}

shell.nix

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{pkgs, ...}: let
2+
# Manifest via Cargo.toml
3+
manifest = (pkgs.lib.importTOML ./Cargo.toml).package;
4+
in
5+
pkgs.stdenv.mkDerivation {
6+
name = "${manifest.name}-dev";
7+
8+
# Compile time dependencies
9+
nativeBuildInputs = with pkgs; [
10+
# Hail the Nix
11+
nixd
12+
statix
13+
deadnix
14+
alejandra
15+
16+
# Rust
17+
rustc
18+
cargo
19+
rustfmt
20+
clippy
21+
rust-analyzer
22+
cargo-watch
23+
24+
# Other compile time dependencies
25+
openssl
26+
27+
# Gnome related
28+
gtk4
29+
meson
30+
ninja
31+
parted
32+
gettext
33+
pkg-config
34+
gdk-pixbuf
35+
libadwaita
36+
gnome-desktop
37+
wrapGAppsHook4
38+
desktop-file-utils
39+
gobject-introspection
40+
rustPlatform.bindgenHook
41+
];
42+
43+
# Set Environment Variables
44+
RUST_BACKTRACE = "full";
45+
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
46+
}

0 commit comments

Comments
 (0)