Pi66

walrs
pywal but if its Fast-Minimal-Simple
git clone https://git.pi66.xyz/walrs

← back to log

add support for nix

author: pixel2175
date: 2025-06-05 00:36
hash: 670098fdcbb20ee08e599e933c6c17eb67422788

Diffstat:

M

Makefile
21 ++++++++++--

A

flake.nix
52 ++++++++++++++++++++++++++++++

M

src/main.rs
2 +

M

src/utils.rs
6 ++-
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
diff --git a/Makefile b/Makefile
index 82d8ae9..56a5207 100644
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,5 @@
+PREFIX ?= /usr
+
 all: build

 build:
@@ -5,16 +7,27 @@ build:

 install: build
    sudo install -m755 target/release/walrs /usr/bin/walrs
-   sudo mkdir -p /etc/walrs/templates/  /etc/walrs/scripts/ /etc/walrs/colorschemes/
+   sudo mkdir -p /etc/walrs/templates/ /etc/walrs/scripts/ /etc/walrs/colorschemes/
    sudo cp -r templates/* /etc/walrs/templates/
    sudo cp -r scripts/* /etc/walrs/scripts/
    sudo cp -r colorschemes/* /etc/walrs/colorschemes/
-   sudo cp ./walrs.1 /usr/share/man/man1/
+   sudo install -m644 walrs.1 /usr/share/man/man1/
+   bash ./autocomplete.sh
+
+nix: build
+   install -Dm755 target/release/walrs $(PREFIX)/bin/walrs
+   mkdir -p <math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mo stretchy="false">&#x00028;</mo><mi>P</mi><mi>R</mi><mi>E</mi><mi>F</mi><mi>I</mi><mi>X</mi><mo stretchy="false">&#x00029;</mo><mo>&#x0002F;</mo><mi>e</mi><mi>t</mi><mi>c</mi><mo>&#x0002F;</mo><mi>w</mi><mi>a</mi><mi>l</mi><mi>r</mi><mi>s</mi><mo>&#x0002F;</mo><mi>t</mi><mi>e</mi><mi>m</mi><mi>p</mi><mi>l</mi><mi>a</mi><mi>t</mi><mi>e</mi><mi>s</mi><mo>&#x0002F;</mo></mrow></math>(PREFIX)/etc/walrs/scripts/ $(PREFIX)/etc/walrs/colorschemes/
+   cp -r templates/* $(PREFIX)/etc/walrs/templates/
+   cp -r scripts/* $(PREFIX)/etc/walrs/scripts/
+   cp -r colorschemes/* $(PREFIX)/etc/walrs/colorschemes/
+   install -Dm644 walrs.1 $(PREFIX)/share/man/man1/
    bash ./autocomplete.sh

 uninstall:
-   sudo rm -rf /usr/bin/walrs /etc/walrs/ ~/.config/walrs/ /usr/share/man/man1/walrs.1
+   sudo rm -rf /usr/bin/walrs /etc/walrs ~/.config/walrs/ /usr/share/man/man1/walrs.1
+
 clean:
    cargo clean

-.PHONY: all build install uninstall clean
+.PHONY: all build install uninstall clean nix
+
diff --git a/flake.nix b/flake.nix
new file mode 100644
index 0000000..215226c
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,52 @@
+{
+  description = "walrs CLI tool";
+  inputs = {
+    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
+    flake-utils.url = "github:numtide/flake-utils";
+  };
+  outputs = { self, nixpkgs, flake-utils }:
+    flake-utils.lib.eachDefaultSystem (system:
+      let
+        pkgs = import nixpkgs { inherit system; };
+      in {
+        packages.default = pkgs.rustPlatform.buildRustPackage rec {
+          pname = "walrs";
+          version = "1.1.2";
+          src = ./.;
+          
+          cargoHash = "sha256-ItjbG/fPAW1mDJI5JXZ73L4c3UeDZzjBdADsyWhqzm8=";         
+
+          nativeBuildInputs = with pkgs; [ bash ];
+          
+          # Allow unstable Rust features
+          preBuild = ''
+            export RUSTC_BOOTSTRAP=1
+          '';
+          
+          # Let rustPlatform handle the binary, we just add the extra files
+          postInstall = ''
+            mkdir -p $out/etc/walrs/{templates,scripts,colorschemes}
+            
+            if [ -d "templates" ]; then
+              cp -r templates/* $out/etc/walrs/templates/ || true
+            fi
+            if [ -d "scripts" ]; then
+              cp -r scripts/* $out/etc/walrs/scripts/ || true
+            fi
+            if [ -d "colorschemes" ]; then
+              cp -r colorschemes/* $out/etc/walrs/colorschemes/ || true
+            fi
+            
+            if [ -f "walrs.1" ]; then
+              install -Dm644 walrs.1 $out/share/man/man1/walrs.1
+            fi
+          '';
+          
+          meta = with pkgs.lib; {
+            description = "Generate colorscheme from image";
+            license = licenses.gpl3;
+            homepage = "https://github.com/pixel2175/walrs";
+          };
+        };
+      });
+}
diff --git a/src/main.rs b/src/main.rs
index 313ac99..e1ee390 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,5 @@
+#![feature(let_chains)]
+
 mod create_templates;
 mod get_colors;
 mod reload;
diff --git a/src/utils.rs b/src/utils.rs
index 6643391..9aa7c0b 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -75,11 +75,13 @@ pub fn info(title: &str, message: &str, send: bool) {
 }

 pub fn get_home(send: bool) -> PathBuf {
-    env::home_dir().unwrap_or_else(|| {
+    Path::new(&env::var("HOME").unwrap_or_else(|_| {
         warning("Home", "can't find the home dir", send);
         exit(1)
-    })
+    }))
+    .to_path_buf()
 }
+
 pub fn get_config(send: bool) -> PathBuf {
     get_home(send).join(".config")
 }