From dfd53a2fbb662f8d45a7419ea6c0c8b3becaf6bc Mon Sep 17 00:00:00 2001 From: David James McCorrie Date: Fri, 22 Aug 2025 22:23:17 +0100 Subject: [PATCH] feat: add nixos support with nix devshell Signed-off-by: David James McCorrie --- .envrc | 1 + .gitignore | 4 +++ flake.lock | 61 ++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 137 insertions(+) create mode 100644 .envrc create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.envrc b/.envrc new file mode 100644 index 00000000..3550a30f --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore index cff72235..4bdfa9c9 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ ignored/ patch_queue/ archived_builds/ .tox/ +.venv/ **.mo **.pot locale/.files @@ -34,3 +35,6 @@ chirpwx.spec chirp/locale/.files # for pycharm IDE .idea +# nix +.direnv +result/ diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..a535be76 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1755615617, + "narHash": "sha256-HMwfAJBdrr8wXAkbGhtcby1zGFvs+StOp19xNsbqdOg=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "20075955deac2583bb12f07151c2df830ef346b4", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..82cf6ec0 --- /dev/null +++ b/flake.nix @@ -0,0 +1,71 @@ +{ + description = "Nix development environment"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { + nixpkgs, + flake-utils, + ... + }: + flake-utils.lib.eachDefaultSystem (system: let + pkgs = nixpkgs.legacyPackages.${system}; + pythonPackages = pkgs.python3Packages; + in { + devShells = { + default = pkgs.mkShell { + name = "impurePythonEnv"; + venvDir = "./.venv"; + + # Packages required to build the venv + buildInputs = [ + # The interpreter to use + pythonPackages.python + # automatically create the venv + pythonPackages.venvShellHook + # get nix to install wxpython as whl doesn't work on NixOS + pythonPackages.wxpython + + pkgs.gsettings-desktop-schemas + pkgs.glib + pkgs.gtk3 + ]; + + # Runtime packages + packages = [ + # Python dev tools + pythonPackages.ipython + pythonPackages.ipdb + pkgs.ruff + pkgs.pyright + + # radio driver development dev tools + pkgs.biodiff # binary diff + ]; + env = { + # Make breakpoint() use ipdb instead of the builtin pdb + PYTHONBREAKPOINT = "ipdb.set_trace"; + + }; + postVenvCreation = '' + unset SOURCE_DATE_EPOCH + # Install chirp as an editable package + pip install -e . + ''; + + # Now we can execute any commands within the virtual environment. + # This is optional and can be left out to run pip manually. + postShellHook = '' + # allow pip to install wheels + unset SOURCE_DATE_EPOCH + export XDG_DATA_DIRS=$GSETTINGS_SCHEMAS_PATH + ''; + }; + }; + + formatter = nixpkgs.legacyPackages.${system}.alejandra; + }); +}