Repository: H3rmt/hyprswitch
Pull request #171: feat: NixOS Support
Author: login: maydayv7
Created: 2025-04-22T17:08:39Z | Merged: 2025-04-22T19:54:54Z

#159 


Diff:
diff --git a/README.md b/README.md
index b7e6e035..8c7f396f 100644
--- a/README.md
+++ b/README.md
@@ -38,16 +38,48 @@ paru -S hyprshell
 yay -S hyprshell
 ```
 
-### Nixos (TODO Add)
+### NixOS
 
-- add ``hyprshell.url = "github:h3rmt/hyprshell/release";`` to flake inputs
-- add `specialArgs = { inherit inputs; };` to `nixpkgs.lib.nixosSystem`
-- add `inputs.hyprshell.packages.x86_64-linux.default` to your `environment.systemPackages`
-- available systems: `aarch64-linux`, `i686-linux`, `riscv32-linux`, `riscv64-linux`, `x86_64-linux`
+- Supported Architectures: `x86_64-linux`, `aarch64-linux`
+
+#### With Flakes
+
+`flake.nix`:
+
+```nix
+{
+  inputs = {
+    nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
+    hyprshell.url = "github:H3rmt/hyprswitch?ref=hyprshell";
+  };
+
+  outputs = { nixpkgs, hyprshell }: {
+    nixosConfigurations.hostname = nixpkgs.lib.nixosSystem {
+      system = "x86_64-linux";
+      modules = [{ environment.systemPackages = [ hyprshell.packages.x86_64-linux.default ]; }];
+    };
+  };
+}
+```
+
+#### Without Flakes
+
+`configuration.nix`:
+
+```nix
+{pkgs, ...}: let
+  flake-compat = builtins.fetchTarball "https://github.com/edolstra/flake-compat/archive/master.tar.gz";
+  hyprshell = (import flake-compat {
+    src = builtins.fetchTarball "https://github.com/H3rmt/hyprswitch/archive/hyprshell.tar.gz";
+  }).defaultNix;
+in {
+   environment.systemPackages = [hyprshell.packages.${pkgs.system}.default];
+}
+```
 
 ## Usage
 
-Run ``hyprshell --help`` to see available commands and options.
+Run `hyprshell --help` to see available commands and options.
 
 ### Config generation
 
@@ -64,7 +96,7 @@ The generated file will be located at `~/.config/hypr/hyprshell.conf`.
 
 To validate your configuration file, run:
 
-```bash 
+```bash
 hyprshell config check
 ```
 
@@ -85,4 +117,4 @@ systemctl --user enable --now hyprshell.service
 ```
 
 ![image.png](imgs/swappy-20250420_000818.png)
-![image.png](imgs/swappy-20250420_000857.png)
\ No newline at end of file
+![image.png](imgs/swappy-20250420_000857.png)
diff --git a/flake.nix b/flake.nix
index be6191df..8b39ed57 100644
--- a/flake.nix
+++ b/flake.nix
@@ -1,19 +1,17 @@
 {
-  description = "Foo Bar";
-  inputs = {
-    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
+  description = "hyprshell - A Rust-based GUI designed to enhance window management in hyprland";
+  inputs.nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
+  outputs = { self, nixpkgs, }: let
+    supportedSystems = ["x86_64-linux" "aarch64-linux"];
+    forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
+    pkgsFor = nixpkgs.legacyPackages;
+  in {
+    packages = forAllSystems (system: rec {
+      hyprshell = pkgsFor.${system}.callPackage ./nix/default.nix {inherit self;};
+      default = hyprshell;
+    });
+    devShells = forAllSystems (system: {
+      default = pkgsFor.${system}.callPackage ./nix/shell.nix {inherit self;};
+    });
   };
-  outputs = { self, nixpkgs }:
-    let
-      supportedSystems = [ "x86_64-linux" ];
-      forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
-      pkgsFor = nixpkgs.legacyPackages;
-    in {
-      packages = forAllSystems (system: {
-        default = pkgsFor.${system}.callPackage ./nix/default.nix { inherit self; };
-      });
-      devShells = forAllSystems (system: {
-        default = pkgsFor.${system}.callPackage ./nix/shell.nix { inherit self; };
-      });
-    };
-}
\ No newline at end of file
+}
diff --git a/nix/default.nix b/nix/default.nix
index 88c1db44..10f20e9e 100644
--- a/nix/default.nix
+++ b/nix/default.nix
@@ -1,25 +1,35 @@
-{ pkgs, self }:
-pkgs.rustPlatform.buildRustPackage rec {
-  pname = "hyprshell";
+{ self, pkgs, }:
+let pname = "hyprshell"; in
+pkgs.rustPlatform.buildRustPackage {
+  inherit pname;
   version =
-      (pkgs.lib.importTOML ../Cargo.toml).workspace.package.version
-      + "_"
-      + (self.shortRev or "dirty");
+    (pkgs.lib.importTOML ../Cargo.toml).workspace.package.version
+    + "_"
+    + (self.shortRev or "dirty");
+
   cargoLock.lockFile = ../Cargo.lock;
   src = pkgs.lib.cleanSource ../.;
 
   nativeBuildInputs = with pkgs; [
+    wrapGAppsHook4
     pkg-config
+    makeBinaryWrapper
   ];
+
   buildInputs = with pkgs; [
-    gtk4
     gtk4-layer-shell
   ];
 
+  # Makes dependency `socat` available to hyprshell
+  postInstall = ''
+    wrapProgram $out/bin/${pname} --set HYPRSHELL_SOCAT_PATH ${pkgs.lib.getExe pkgs.socat}
+  '';
+
   meta = {
+    mainProgram = pname;
     description = "hyprshell is a Rust-based GUI designed to enhance window management in hyprland";
     homepage = "https://github.com/h3rmt/hyprshell";
     license = pkgs.lib.licenses.mit;
     platforms = pkgs.lib.platforms.linux;
   };
-}
\ No newline at end of file
+}


Reviews:
user: login: H3rmt
state: CHANGES_REQUESTED
author_association: OWNER
submitted_at: 2025-04-22T19:12:47Z
user: login: H3rmt
state: COMMENTED
author_association: OWNER
submitted_at: 2025-04-22T19:14:28Z
user: login: maydayv7
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-22T19:30:56Z
user: login: maydayv7
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-22T19:31:47Z
user: login: H3rmt
state: COMMENTED
author_association: OWNER
submitted_at: 2025-04-22T19:40:21Z
user: login: H3rmt
state: COMMENTED
author_association: OWNER
submitted_at: 2025-04-22T19:44:12Z
user: login: maydayv7
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-22T19:49:27Z
user: login: H3rmt
state: APPROVED
author_association: OWNER
submitted_at: 2025-04-22T19:54:21Z

Review comments:
diff_hunk: @@ -1,25 +1,33 @@
-{ pkgs, self }:
+{ self, pkgs, }:
 pkgs.rustPlatform.buildRustPackage rec {
   pname = "hyprshell";
   version =
-      (pkgs.lib.importTOML ../Cargo.toml).workspace.package.version
-      + "_"
-      + (self.shortRev or "dirty");
+    (pkgs.lib.importTOML ../Cargo.toml).workspace.package.version
+    + "_"
+    + (self.shortRev or "dirty");
+
   cargoLock.lockFile = ../Cargo.lock;
   src = pkgs.lib.cleanSource ../.;
 
   nativeBuildInputs = with pkgs; [
+    wrapGAppsHook4
     pkg-config
+    makeBinaryWrapper
   ];
+
   buildInputs = with pkgs; [
-    gtk4
path: nix/default.nix
user: login: H3rmt
body: Any reason why this was removed?
created_at: 2025-04-22T17:11:49Z
author_association: OWNER
diff_hunk: @@ -1,19 +1,17 @@
 {
-  description = "Foo Bar";
-  inputs = {
-    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
+  description = "hyprshell - A Rust-based GUI designed to enhance window management in hyprland";
+  inputs.nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
+  outputs = { self, nixpkgs, }: let
+    supportedSystems = ["x86_64-linux"];
path: flake.nix
user: login: H3rmt
body: I think more systems were supported previously (old flake from hyprswitch)
created_at: 2025-04-22T17:12:33Z
author_association: OWNER
diff_hunk: @@ -1,19 +1,17 @@
 {
-  description = "Foo Bar";
-  inputs = {
-    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
+  description = "hyprshell - A Rust-based GUI designed to enhance window management in hyprland";
+  inputs.nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
+  outputs = { self, nixpkgs, }: let
+    supportedSystems = ["x86_64-linux"];
path: flake.nix
user: login: H3rmt
body: old one had ``aarch64-linux, i686-linux, riscv32-linux, riscv64-linux, x86_64-linux``. 
I dont know if all make sense to include, but at least `aarch64-linux` should be supported
created_at: 2025-04-22T19:14:28Z
author_association: OWNER
diff_hunk: @@ -1,25 +1,33 @@
-{ pkgs, self }:
+{ self, pkgs, }:
 pkgs.rustPlatform.buildRustPackage rec {
   pname = "hyprshell";
   version =
-      (pkgs.lib.importTOML ../Cargo.toml).workspace.package.version
-      + "_"
-      + (self.shortRev or "dirty");
+    (pkgs.lib.importTOML ../Cargo.toml).workspace.package.version
+    + "_"
+    + (self.shortRev or "dirty");
+
   cargoLock.lockFile = ../Cargo.lock;
   src = pkgs.lib.cleanSource ../.;
 
   nativeBuildInputs = with pkgs; [
+    wrapGAppsHook4
     pkg-config
+    makeBinaryWrapper
   ];
+
   buildInputs = with pkgs; [
-    gtk4
path: nix/default.nix
user: login: maydayv7
body: Took the dependencies from https://github.com/NixOS/nixpkgs/pull/388687, seems to work well even without it
created_at: 2025-04-22T19:30:56Z
author_association: CONTRIBUTOR
diff_hunk: @@ -1,19 +1,17 @@
 {
-  description = "Foo Bar";
-  inputs = {
-    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
+  description = "hyprshell - A Rust-based GUI designed to enhance window management in hyprland";
+  inputs.nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
+  outputs = { self, nixpkgs, }: let
+    supportedSystems = ["x86_64-linux"];
path: flake.nix
user: login: maydayv7
body: Does the package successfully compile on `aarch64-linux`? I have no way of testing it, but if it does I'll add it
created_at: 2025-04-22T19:31:47Z
author_association: CONTRIBUTOR
diff_hunk: @@ -1,25 +1,33 @@
-{ pkgs, self }:
+{ self, pkgs, }:
 pkgs.rustPlatform.buildRustPackage rec {
   pname = "hyprshell";
   version =
-      (pkgs.lib.importTOML ../Cargo.toml).workspace.package.version
-      + "_"
-      + (self.shortRev or "dirty");
+    (pkgs.lib.importTOML ../Cargo.toml).workspace.package.version
+    + "_"
+    + (self.shortRev or "dirty");
+
   cargoLock.lockFile = ../Cargo.lock;
   src = pkgs.lib.cleanSource ../.;
 
   nativeBuildInputs = with pkgs; [
+    wrapGAppsHook4
     pkg-config
+    makeBinaryWrapper
   ];
+
   buildInputs = with pkgs; [
-    gtk4
path: nix/default.nix
user: login: H3rmt
body: I had no idea this even existed...
created_at: 2025-04-22T19:40:21Z
author_association: OWNER
diff_hunk: @@ -1,19 +1,17 @@
 {
-  description = "Foo Bar";
-  inputs = {
-    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
+  description = "hyprshell - A Rust-based GUI designed to enhance window management in hyprland";
+  inputs.nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
+  outputs = { self, nixpkgs, }: let
+    supportedSystems = ["x86_64-linux"];
path: flake.nix
user: login: H3rmt
body: Rust is able to crosscompile to most architectures, I think we should add every architectures that hyprland has
created_at: 2025-04-22T19:44:12Z
author_association: OWNER
diff_hunk: @@ -1,19 +1,17 @@
 {
-  description = "Foo Bar";
-  inputs = {
-    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
+  description = "hyprshell - A Rust-based GUI designed to enhance window management in hyprland";
+  inputs.nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
+  outputs = { self, nixpkgs, }: let
+    supportedSystems = ["x86_64-linux"];
path: flake.nix
user: login: maydayv7
body: Okay, Hyprland has `aarch64-linux` and `x86_64-linux` so added them both
created_at: 2025-04-22T19:49:27Z
author_association: CONTRIBUTOR

PR comments:
user: login: H3rmt
created_at: 2025-04-22T17:13:30Z
body: This doesn't guarantee that socat is installed, is it possible to enforce that?
author_association: OWNER
user: login: maydayv7
created_at: 2025-04-22T17:16:14Z
body: No it does guarantee that `socat` is installed
```
wrapProgram $out/bin/${pname} --set HYPRSHELL_SOCAT_PATH ${pkgs.lib.getExe pkgs.socat}
```
This line ensures that `socat` is present in `/nix/store` and is correctly passed to `hyprshell`
I am also using it in my own setup
author_association: CONTRIBUTOR
user: login: H3rmt
created_at: 2025-04-22T19:12:34Z
body: > No it does guarantee that `socat` is installed
> 
> ```
> wrapProgram $out/bin/${pname} --set HYPRSHELL_SOCAT_PATH ${pkgs.lib.getExe pkgs.socat}
> ```
> 
> This line ensures that `socat` is present in `/nix/store` and is correctly passed to `hyprshell` I am also using it in my own setup

could you add that to the README or the nix config?
author_association: OWNER