diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml new file mode 100644 index 0000000..2780ce0 --- /dev/null +++ b/.github/workflows/nix.yml @@ -0,0 +1,21 @@ +name: Build + +on: [push, pull_request, workflow_dispatch] +jobs: + nix: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - uses: DeterminateSystems/nix-installer-action@main + - uses: DeterminateSystems/magic-nix-cache-action@main + + # not needed (yet) + # - uses: cachix/cachix-action@v12 + # with: + # name: hyprland + # authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' + + - name: Build + run: nix flake check --print-build-logs --keep-going + diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..6aff8fe --- /dev/null +++ b/flake.lock @@ -0,0 +1,48 @@ +{ + "nodes": { + "hyprlang": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1708212860, + "narHash": "sha256-nW3Zrhh9RJcMTvOcXAaKADnJM/g6tDf3121lJtTHnYo=", + "owner": "hyprwm", + "repo": "hyprlang", + "rev": "11d5ccda071c153dfdc18ef65338956a51cef96a", + "type": "github" + }, + "original": { + "owner": "hyprwm", + "repo": "hyprlang", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1702645756, + "narHash": "sha256-qKI6OR3TYJYQB3Q8mAZ+DG4o/BR9ptcv9UnRV2hzljc=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "40c3c94c241286dd2243ea34d3aef8a488f9e4d0", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "hyprlang": "hyprlang", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..d2f006b --- /dev/null +++ b/flake.nix @@ -0,0 +1,42 @@ +{ + description = "Hyprland's GPU-accelerated screen locking utility"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + + hyprlang = { + url = "github:hyprwm/hyprlang"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = inputs: let + inherit (inputs.nixpkgs) lib; + genSystems = lib.genAttrs [ + # Add more systems if they are supported + "x86_64-linux" + "aarch64-linux" + ]; + pkgsFor = genSystems (system: + import inputs.nixpkgs { + overlays = [inputs.self.overlays.default]; + inherit system; + }); + in { + overlays = import ./nix/overlays.nix {inherit inputs lib;}; + + packages = genSystems (system: { + inherit (pkgsFor.${system}) hyprlock; + default = inputs.self.packages.${system}.hyprlock; + }); + + homeManagerModules = { + hyprlock = import ./nix/hm-module.nix inputs.self; + default = inputs.self.homeManagerModules.hyprlock; + }; + + checks = genSystems (system: inputs.self.packages.${system}); + + formatter = genSystems (system: pkgsFor.${system}.alejandra); + }; +} diff --git a/nix/default.nix b/nix/default.nix new file mode 100644 index 0000000..5586f45 --- /dev/null +++ b/nix/default.nix @@ -0,0 +1,44 @@ +{ + lib, + stdenv, + cmake, + pkg-config, + cairo, + libGL, + libxkbcommon, + hyprlang, + pam, + pango, + wayland, + wayland-protocols, + version ? "git", +}: +stdenv.mkDerivation { + pname = "hyprlock"; + inherit version; + src = ../.; + + nativeBuildInputs = [ + cmake + pkg-config + ]; + + buildInputs = [ + cairo + libGL + libxkbcommon + hyprlang + pam + pango + wayland + wayland-protocols + ]; + + meta = { + homepage = "https://github.com/hyprwm/hyprlock"; + description = "A gpu-accelerated screen lock for Hyprland"; + license = lib.licenses.bsd3; + platforms = lib.platforms.linux; + mainProgram = "hyprlock"; + }; +} diff --git a/nix/hm-module.nix b/nix/hm-module.nix new file mode 100644 index 0000000..7d958dd --- /dev/null +++ b/nix/hm-module.nix @@ -0,0 +1,118 @@ +self: { + config, + pkgs, + lib, + ... +}: let + inherit (builtins) toString; + inherit (lib.types) int listOf package str submodule; + inherit (lib.modules) mkIf; + inherit (lib.options) mkOption mkEnableOption; + + cfg = config.services.hyprlock; +in { + options.services.hyprlock = { + enable = mkEnableOption "Hyprlock, Hyprland's GPU-accelerated lock screen utility"; + + package = mkOption { + description = "The hyprlock package"; + type = package; + default = self.packages.${pkgs.stdenv.hostPlatform.system}.hyprlock; + }; + + backgrounds = mkOption { + description = "Monitor configurations"; + type = listOf (submodule { + options = { + monitor = mkOption { + description = "The monitor to apply the given wallpaper to"; + type = str; + default = ""; + }; + + path = mkOption { + description = "The path to the wallpaper"; + type = str; + default = "echo 'timeout reached'"; + }; + }; + }); + }; + + general.disable_loading_bar = + mkEnableOption "" + // { + description = "Whether to disable loading bar"; + }; + + input_field = submodule { + options = { + monitor = mkOption { + description = "The monitor to place the input field on"; + type = str; + default = ""; + }; + + size = mkOption { + description = "The size of the input field"; + type = submodule { + options = { + width = mkOption { + description = "Width of the input field"; + type = int; + default = 200; + }; + height = mkOption { + description = "Height of the input field"; + type = int; + default = 50; + }; + }; + }; + }; + + outline_thickness = mkOption { + description = "The outline thickness of the input field"; + type = int; + default = 3; + }; + + outer_color = mkOption { + description = "The outer color of the input field"; + type = str; + default = "rgb(151515)"; + }; + + inner_color = mkOption { + description = "The inner color of the input field"; + type = str; + default = "rgb(200, 200, 200)"; + }; + }; + }; + }; + + config = mkIf cfg.enable { + xdg.configFile."hypr/hyprlock.conf".text = '' + general { + disable_loading_bar = ${cfg.general.disable_loading_bar} + } + + input_field { + monitor = ${cfg.input_field.monitor} + size = ${toString cfg.input_field.size.width} ${toString cfg.input_field.size.height} + outline_thickness = ${toString cfg.input_field.outline_thickness} + outer_color = ${cfg.input_field.outer_color} + inner_color = ${cfg.input_field.inner_color} + } + + ${builtins.concatStringsSep "\n" (map (background: '' + background { + monitor = ${background.monitor} + path = ${background.path} + } + '') + cfg.backgrounds)} + ''; + }; +} diff --git a/nix/overlays.nix b/nix/overlays.nix new file mode 100644 index 0000000..975a8fb --- /dev/null +++ b/nix/overlays.nix @@ -0,0 +1,21 @@ +{ + lib, + inputs, +}: let + mkDate = longDate: (lib.concatStringsSep "-" [ + (builtins.substring 0 4 longDate) + (builtins.substring 4 2 longDate) + (builtins.substring 6 2 longDate) + ]); +in { + default = lib.composeManyExtensions [ + inputs.hyprlang.overlays.default + (final: prev: { + hyprlock = prev.callPackage ./default.nix { + stdenv = prev.gcc13Stdenv; + version = "0.pre" + "+date=" + (mkDate (inputs.self.lastModifiedDate or "19700101")) + "_" + (inputs.self.shortRev or "dirty"); + inherit (final) hyprlang; + }; + }) + ]; +}