Skip to content

Instantly share code, notes, and snippets.

@UrGuardian4ngel
Last active February 3, 2024 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UrGuardian4ngel/9541270fbe0b66bd471d252441dd94d8 to your computer and use it in GitHub Desktop.
Save UrGuardian4ngel/9541270fbe0b66bd471d252441dd94d8 to your computer and use it in GitHub Desktop.
Argon One Fan and Button Configuration in NixOS
{
pkgs
, lib
, stdenv
, fetchurl
, bash
, python3
, wget
}:
let
pythonEnv = python3.withPackages(ps: with ps; [
rpi-gpio
smbus-cffi
]);
in stdenv.mkDerivation rec {
pname = "argonone-bin";
version = "20191209";
src = fetchurl {
name = "argonone-src";
url = "https://download.argon40.com/argon1.sh";
downloadToTemp = true;
recursiveHash = true;
sha256 = "ZAeYt1k9KZJzL6lROi5BuyN6ZBhOdVxBjKC5r9D4Af4=";
postFetch = ''
install -D $downloadedFile $out/argon1.sh
'';
};
nativeBuildInputs = [ bash wget ];
buildInputs = [ python3 ];
pkgdir = "${placeholder "out"}";
patches = [
./nixos-support.patch
];
prePatch = ''
install -Dm775 $src/argon1.sh ./argon1.sh
'';
postPatch = ''
patchShebangs ./argon1.sh
substituteInPlace ./argon1.sh \
--subst-var "pkgdir" \
--replace "sudo " "" \
--replace "wget" "${wget}/bin/wget" \
--replace "/usr/bin/python3" "${pythonEnv}/bin/python3"
'';
# TODO: Fix `argonone-ir` binary: "wget: unable to resolve host address 'download.argon40.com'"
dontUnpack = true;
dontConfigure = true;
dontBuild = true;
installPhase = ''
runHook preInstall
mkdir -p \
$pkgdir/bin \
$pkgdir/etc \
$pkgdir/usr/bin \
$pkgdir/lib/systemd/system \
$pkgdir/lib/systemd/system-shutdown
./argon1.sh
ln -s $pkgdir/usr/bin/argononed.py $out/bin/argononed
runHook postInstall
'';
meta = with lib; {
description = "Argon One Fan and Button Configuration";
homepage = "https://download.argon40.com/argon1.sh";
maintainers = with maintainers; [ ];
mainProgram = "argononed";
platforms = [ "aarch64-linux" ];
};
}
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1690952720,
"narHash": "sha256-fPsiQHARfhVxXpWgcuSKvkYwSco8K13K7XevBpdIfPg=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "96112a3ed5d12bb1758b42c63b924c004b6c0bc9",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}
{
description = "Argon One";
outputs = { self, nixpkgs }:
let system = "aarch64-linux";
pkgs = import nixpkgs { inherit system; };
in {
packages.${system}.argononed = pkgs.callPackage ./default.nix { inherit pkgs; };
};
}
diff --git a/argon1.sh b/argon1.sh
index 2b1c105..c1e9558 100644
--- a/argon1.sh
+++ b/argon1.sh
@@ -33,13 +33,23 @@ then
elif [ "$ID" = "ubuntu" ]
then
CHECKPLATFORM="Ubuntu"
+ elif [ "$ID" = "nixos" ]
+ then
+ CHECKPLATFORM="NixOS"
fi
+elif [ -n "$NIX_BUILD_CORES" ]
+then
+ CHECKPLATFORM="NixOS"
fi
if [ "$CHECKPLATFORM" = "Raspbian" ]
then
pkglist=(raspi-gpio python3-rpi.gpio python3-smbus i2c-tools)
+elif [ "$CHECKPLATFORM" = "NixOS" ]
+then
+ # Dependencies managed by NixOS
+ pkglist=()
else
# Todo handle lgpio
# Ubuntu has serial and i2c enabled
@@ -69,16 +79,16 @@ fi
# Helper variables
daemonname="argononed"
-powerbuttonscript=/usr/bin/$daemonname.py
-shutdownscript="/lib/systemd/system-shutdown/"$daemonname"-poweroff.py"
-daemonconfigfile=/etc/$daemonname.conf
-configscript=/usr/bin/argonone-config
-removescript=/usr/bin/argonone-uninstall
+powerbuttonscript=@pkgdir@/usr/bin/$daemonname.py
+shutdownscript="@pkgdir@/lib/systemd/system-shutdown/"$daemonname"-poweroff.py"
+daemonconfigfile=@pkgdir@/etc/$daemonname.conf
+configscript=@pkgdir@/usr/bin/argonone-config
+removescript=@pkgdir@/usr/bin/argonone-uninstall
powerbuttonshutdownscript=$powerbuttonscript
-daemonfanservice=/lib/systemd/system/$daemonname.service
+daemonfanservice=@pkgdir@/lib/systemd/system/$daemonname.service
if [ ! -f $daemonconfigfile ]; then
# Generate config file for fan speed
@@ -495,10 +505,13 @@ echo 'fi' >> $configscript
sudo chmod 755 $configscript
-sudo systemctl daemon-reload
-sudo systemctl enable $daemonname.service
+if [ "$CHECKPLATFORM" != "NixOS" ]
+then
+ sudo systemctl daemon-reload
+ sudo systemctl enable $daemonname.service
-sudo systemctl start $daemonname.service
+ sudo systemctl start $daemonname.service
+fi
shortcutfile="/home/pi/Desktop/argonone-config.desktop"
@@ -537,8 +550,8 @@ then
fi
# IR config script
-sudo wget https://download.argon40.com/argonone-irconfig.sh -O /usr/bin/argonone-ir --quiet
-sudo chmod 755 /usr/bin/argonone-ir
+sudo wget https://download.argon40.com/argonone-irconfig.sh -O @pkgdir@/usr/bin/argonone-ir --quiet
+sudo chmod 755 @pkgdir@/usr/bin/argonone-ir
echo "***************************"
echo "Argon One Setup Completed."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment