diff --git a/.gitignore b/.gitignore index 28f0a6e..e9b0cdb 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,11 @@ # # SPDX-License-Identifier: CC0-1.0 +# Cargo target/ + +# Nix +result + +# fakegreet +greetd.sock \ 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/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..1e632df --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,57 @@ + + +# Contributing + +## Pre commit + +[pre-commit](https://pre-commit.com/) is used for managing hooks that run before each commit (such as clippy), to ensure +code quality. Thus, this needs to be set up only when one intends to commit changes to git. + +Firstly, [install pre-commit](https://pre-commit.com/#installation) itself. Next, install pre-commit hooks: +```sh +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 dev shells + +Simply run `nix develop .#vscode --command code .` to get VS Code set up with all the extensions you need. The default +shell doesn't have any text editors configred. + +You can also use nix without flakes if you choose to. See the [nix documentation in this repo](nix/README.md) for more +details. + +## Testing + +You can run ReGreet without a greetd socket using `--demo` flag. It also disables some of the features such as logging +to a file. + +```sh +regreet --demo +``` + +Since the demo mode doesn't use greetd, authentication is done using hardcoded credentials within the codebase. These +credentials are logged with the warning log level, so that you don't have to read the source code. + +----- + +Alternatively you can use `fakegreet` to emulate a running greetd daemon. Please keep in mind that it's behavior doesn't +match the real thing. + +```sh +fakegreet 'cargo run' +``` + +Fakegreet credentials (taken from source code): + +||Value| +|---|---| +|User|user| +|Password|password| +|7+2|9| \ No newline at end of file diff --git a/README.md b/README.md index 068ce23..a1569c3 100644 --- a/README.md +++ b/README.md @@ -230,28 +230,9 @@ The recommended configuration is to run greetd greeters as a separate user (`gre This can lead to insufficient permissions for either creating the cache/log directories, or writing to them. To make use of the caching and logging features, please create the directories manually with the correct permissions, if not done during installation with systemd-tmpfiles. -## Contributing -[pre-commit](https://pre-commit.com/) is used for managing hooks that run before each commit (such as clippy), to ensure code quality. -Thus, this needs to be set up only when one intends to commit changes to git. +# Contributing -Firstly, [install pre-commit](https://pre-commit.com/#installation) itself. -Next, install pre-commit hooks: -```sh -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. - -### Demo mode -To aid development, a "demo" mode is included within ReGreet that runs ReGreet independent of greetd. -Simply run ReGreet as follows: -```sh -regreet --demo -``` - -Since the demo mode doesn't use greetd, authentication is done using hardcoded credentials within the codebase. -These credentials are logged with the warning log-level, so that you don't have to read the source code. +See [CONTRIBUTING.md](CONTRIBUTING.md) ## Licenses This repository uses [REUSE](https://reuse.software/) to document licenses. diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..8a1e548 --- /dev/null +++ b/default.nix @@ -0,0 +1,5 @@ +# SPDX-FileCopyrightText: 2024 Harish Rajagopal +# +# SPDX-License-Identifier: GPL-3.0-or-later +{pkgs ? import {}}: +pkgs.callPackage ./nix/packages {} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..8ba7da1 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1727348695, + "narHash": "sha256-J+PeFKSDV+pHL7ukkfpVzCOO7mBSrrpJ3svwBFABbhI=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "1925c603f17fc89f4c8f6bf6f631a802ad85d784", + "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..8895651 --- /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 = system: + import nixpkgs { + config.allowUnfree = true; + inherit system; + }; + in { + formatter = forAllSystems (system: (pkgsFor system).alejandra); + + packages = forAllSystems (system: let + pkgs = pkgsFor system; + in + { + default = self.packages.${system}.regreet; + } + // (pkgs.callPackage ./nix/packages {})); + + devShells = forAllSystems (system: let + pkgs = pkgsFor system; + in + { + default = self.devShells.${system}.rust; + } + // (pkgs.callPackage ./nix/shells {})); + }; +} diff --git a/nix/README.md b/nix/README.md new file mode 100644 index 0000000..2eee0ba --- /dev/null +++ b/nix/README.md @@ -0,0 +1,50 @@ + + +# Nix + +## Structure + +|Path|| +|---|---| +|[`/nix/packages`](packages)|Filenames are keys in both `flake.packages` and attributes in [`/default.nix`](../default.nix)| +|[`/nix/shells`](shells)|Filenames are keys in both `flake.devShells` and attributes in [`/shell.nix`](../shell.nix)| + +## Loading a shell / building packages + +
With flakes + +See the flake source for what `.#default` points to. + +```sh +nix develop .# +nix build .# + +# Example + +nix develop .#vscode +# Loads ./shells/vscode.nix +``` + +
+ +----- + +
Without flakes + +You have to select an attribute with `-A`. `default` is not set (it doesnt work like that in `nix-*` commnands)! + +```sh +nix-shell -A +nix-build -A + +# Example + +nix-build -A regreet +# Builds ./packages/regreet.nix +``` + +
\ No newline at end of file diff --git a/nix/packages/default.nix b/nix/packages/default.nix new file mode 100644 index 0000000..ed33510 --- /dev/null +++ b/nix/packages/default.nix @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2024 Harish Rajagopal +# +# SPDX-License-Identifier: GPL-3.0-or-later +{ + lib, + callPackage, +}: let + inherit (builtins) map listToAttrs filter attrNames readDir; + inherit (lib) removeSuffix; + + ls = attrNames (readDir ./.); + notThisFile = name: name != "default.nix"; + rmDotNix = removeSuffix ".nix"; + mkAttr = file: { + name = rmDotNix file; + value = callPackage ./${file} {}; + }; +in + listToAttrs (map mkAttr (filter notThisFile ls)) diff --git a/nix/packages/regreet.nix b/nix/packages/regreet.nix new file mode 100644 index 0000000..3340860 --- /dev/null +++ b/nix/packages/regreet.nix @@ -0,0 +1,27 @@ +# SPDX-FileCopyrightText: 2024 Harish Rajagopal +# +# SPDX-License-Identifier: GPL-3.0-or-later +{ + buildFeatures ? ["gtk4_8"], + lib, + rustPlatform, + pkg-config, + wrapGAppsHook4, + glib, + gtk4, + pango, + librsvg, +}: let + manifest = (lib.importTOML ../../Cargo.toml).package; +in + rustPlatform.buildRustPackage rec { + pname = manifest.name; + inherit (manifest) version; + cargoLock.lockFile = ../../Cargo.lock; + src = lib.cleanSource ../..; + + inherit buildFeatures; + + nativeBuildInputs = [pkg-config wrapGAppsHook4]; + buildInputs = [glib gtk4 pango librsvg]; + } diff --git a/nix/shells/default.nix b/nix/shells/default.nix new file mode 100644 index 0000000..ed33510 --- /dev/null +++ b/nix/shells/default.nix @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2024 Harish Rajagopal +# +# SPDX-License-Identifier: GPL-3.0-or-later +{ + lib, + callPackage, +}: let + inherit (builtins) map listToAttrs filter attrNames readDir; + inherit (lib) removeSuffix; + + ls = attrNames (readDir ./.); + notThisFile = name: name != "default.nix"; + rmDotNix = removeSuffix ".nix"; + mkAttr = file: { + name = rmDotNix file; + value = callPackage ./${file} {}; + }; +in + listToAttrs (map mkAttr (filter notThisFile ls)) diff --git a/nix/shells/rust.nix b/nix/shells/rust.nix new file mode 100644 index 0000000..74698e9 --- /dev/null +++ b/nix/shells/rust.nix @@ -0,0 +1,29 @@ +# SPDX-FileCopyrightText: 2024 Harish Rajagopal +# +# SPDX-License-Identifier: GPL-3.0-or-later +{ + callPackage, + mkShell, + rust-analyzer, + rustfmt, + clippy, + pre-commit, + greetd, +}: +mkShell { + inputsFrom = [(callPackage ../packages/regreet.nix {})]; + buildInputs = [ + rust-analyzer + rustfmt + clippy + + pre-commit + + greetd.greetd # fakegreet + ]; + + shellHook = '' + echo "Installing pre commit hooks"; + pre-commit install; + ''; +} diff --git a/nix/shells/vscode.nix b/nix/shells/vscode.nix new file mode 100644 index 0000000..8127561 --- /dev/null +++ b/nix/shells/vscode.nix @@ -0,0 +1,25 @@ +# SPDX-FileCopyrightText: 2024 Harish Rajagopal +# +# SPDX-License-Identifier: GPL-3.0-or-later +{ + callPackage, + mkShell, + vscode-with-extensions, + vscode-extensions, +}: +mkShell { + inputsFrom = [(callPackage ./rust.nix {})]; + buildInputs = [ + ( + 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..c9474e3 --- /dev/null +++ b/shell.nix @@ -0,0 +1,5 @@ +# SPDX-FileCopyrightText: 2024 Harish Rajagopal +# +# SPDX-License-Identifier: GPL-3.0-or-later +{pkgs ? import {config.allowUnfree = true;}}: +pkgs.callPackage ./nix/shells {}