From f9bb4d420567c51efcd60805639635ebd1926e86 Mon Sep 17 00:00:00 2001 From: max-ishere <47008271+max-ishere@users.noreply.github.com> Date: Mon, 19 Aug 2024 15:44:09 +0300 Subject: [PATCH] nix: flake & non-flake dev shells --- .gitignore | 4 ++++ .reuse/dep5 | 2 +- README.md | 6 ++++++ default.nix | 17 +++++++++++++++++ flake.lock | 27 +++++++++++++++++++++++++++ flake.nix | 41 +++++++++++++++++++++++++++++++++++++++++ nix/vscode-shell.nix | 20 ++++++++++++++++++++ shell.nix | 19 +++++++++++++++++++ 8 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 default.nix create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 nix/vscode-shell.nix create mode 100644 shell.nix diff --git a/.gitignore b/.gitignore index 28f0a6e..73a18c2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,8 @@ # # SPDX-License-Identifier: CC0-1.0 +# Cargo target/ + +# Nix +result/ \ No newline at end of file diff --git a/.reuse/dep5 b/.reuse/dep5 index c1aa473..f437b85 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -3,6 +3,6 @@ Upstream-Name: ReGreet Upstream-Contact: Harish Rajagopal Source: https://github.com/rharish101/ReGreet -Files: Cargo.lock +Files: Cargo.lock flake.lock Copyright: 2022 Harish Rajagopal License: CC0-1.0 diff --git a/README.md b/README.md index 068ce23..c4b741c 100644 --- a/README.md +++ b/README.md @@ -243,6 +243,12 @@ pre-commit install Now, pre-commit should ensure that the code passes all linters locally before committing. This will save time when creating PRs, since these linters also run in CI, and thus fail code that hasn't been linted well. +### Nix/NixOS + +Simply run `nix develop .#vscode --command code .` to get VS Code set up with all the extensions you need. The default shell doesnt have any text editors configred. + +You can also use nix without flakes if you choose to. + ### Demo mode To aid development, a "demo" mode is included within ReGreet that runs ReGreet independent of greetd. Simply run ReGreet as follows: diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..29ff2b1 --- /dev/null +++ b/default.nix @@ -0,0 +1,17 @@ +# SPDX-FileCopyrightText: 2024 Harish Rajagopal +# +# SPDX-License-Identifier: GPL-3.0-or-later +{pkgs ? import {}}: let + manifest = (pkgs.lib.importTOML ./Cargo.toml).package; +in + pkgs.rustPlatform.buildRustPackage rec { + pname = manifest.name; + inherit (manifest) version; + cargoLock.lockFile = ./Cargo.lock; + src = pkgs.lib.cleanSource ./.; + + buildFeatures = ["gtk4_8"]; + + nativeBuildInputs = with pkgs; [pkg-config wrapGAppsHook4]; + buildInputs = with pkgs; [glib gtk4 pango librsvg]; + } diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..48828c7 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1724479785, + "narHash": "sha256-pP3Azj5d6M5nmG68Fu4JqZmdGt4S4vqI5f8te+E/FTw=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "d0e1602ddde669d5beb01aec49d71a51937ed7be", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..b4c7986 --- /dev/null +++ b/flake.nix @@ -0,0 +1,41 @@ +# SPDX-FileCopyrightText: 2024 Harish Rajagopal +# +# SPDX-License-Identifier: GPL-3.0-or-later +{ + description = "Dev tooling for ReGreet"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + }; + + outputs = { + self, + nixpkgs, + }: let + supportedSystems = ["x86_64-linux"]; + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + pkgsFor = nixpkgs.legacyPackages; + in { + formatter = forAllSystems (system: pkgsFor.${system}.alejandra); + + packages = forAllSystems (system: let + pkgs = pkgsFor.${system}; + in rec { + default = regreet; + regreet = pkgs.callPackage ./default.nix {inherit pkgs;}; + }); + + devShells = forAllSystems (system: let + pkgs = pkgsFor.${system}; + in { + default = pkgs.callPackage ./shell.nix {inherit pkgs;}; + + vscode = pkgs.callPackage ./nix/vscode-shell.nix { + pkgs = import nixpkgs { + inherit system; + config.allowUnfree = true; + }; + }; + }); + }; +} diff --git a/nix/vscode-shell.nix b/nix/vscode-shell.nix new file mode 100644 index 0000000..92d136c --- /dev/null +++ b/nix/vscode-shell.nix @@ -0,0 +1,20 @@ +# SPDX-FileCopyrightText: 2024 Harish Rajagopal +# +# SPDX-License-Identifier: GPL-3.0-or-later +{pkgs ? import {}}: +pkgs.mkShell { + inputsFrom = [(pkgs.callPackage ../shell.nix {})]; + buildInputs = with pkgs; [ + ( + vscode-with-extensions.override { + vscodeExtensions = with vscode-extensions; [ + rust-lang.rust-analyzer + tamasfe.even-better-toml + bbenoist.nix + + vscodevim.vim # you can disable this in extension settings if you want + ]; + } + ) + ]; +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..dbe9dcc --- /dev/null +++ b/shell.nix @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2024 Harish Rajagopal +# +# SPDX-License-Identifier: GPL-3.0-or-later +{pkgs ? import {}}: +pkgs.mkShell { + inputsFrom = [(pkgs.callPackage ./default.nix {})]; + buildInputs = with pkgs; [ + rust-analyzer + rustfmt + clippy + + pre-commit + ]; + + shellHook = '' + echo "Installing pre commit hooks"; + pre-commit install; + ''; +}