From 0728326d6e2834cb339337e7bcb19ff0bdfbd263 Mon Sep 17 00:00:00 2001 From: Fernando Ayats Date: Tue, 17 May 2022 13:11:24 +0200 Subject: [PATCH 1/8] nix: flake cleanup - Removed all outputs except for "packages" - Track nixos-unstable instead of stable - Cleanup installPhase --- default.nix | 93 +++++++++++++++++++++-------------- flake.lock | 139 +--------------------------------------------------- flake.nix | 59 ++++++++++------------ 3 files changed, 84 insertions(+), 207 deletions(-) diff --git a/default.nix b/default.nix index fcee67fd..a5abdd5d 100644 --- a/default.nix +++ b/default.nix @@ -1,30 +1,55 @@ -{ lib, stdenv, fetchFromGitHub, src, pkg-config, cmake, ninja, libdrm, libinput -, libxcb, libxkbcommon, mesa, mount, pango, wayland, wayland-protocols -, wayland-scanner, wlroots, xcbutilwm, xwayland, enableXWayland ? true }: - -stdenv.mkDerivation rec { +{ + lib, + stdenv, + fetchFromGitHub, + pkg-config, + cmake, + ninja, + libdrm, + libinput, + libxcb, + libxkbcommon, + mesa, + mount, + pango, + wayland, + wayland-protocols, + wayland-scanner, + wlroots, + xcbutilwm, + xwayland, + enableXWayland ? true, + version ? "git", +}: +stdenv.mkDerivation { pname = "hyprland"; - version = "git"; - inherit src; + inherit version; + src = ./.; - nativeBuildInputs = [ cmake ninja pkg-config wayland ] - ++ lib.optional enableXWayland xwayland; - - buildInputs = [ - libdrm - libinput - libxcb - libxkbcommon - mesa - pango - wayland-protocols - wayland-scanner - wlroots - (wlroots.override { inherit enableXWayland; }) - xcbutilwm + nativeBuildInputs = [ + cmake + ninja + pkg-config ]; - cmakeFlags = [ "-DCMAKE_BUILD_TYPE=Release" ] + buildInputs = + [ + libdrm + libinput + libxcb + libxkbcommon + mesa + pango + wayland + wayland-protocols + wayland-scanner + (wlroots.override {inherit enableXWayland;}) + xcbutilwm + ] + ++ lib.optional enableXWayland xwayland; + + cmakeFlags = + ["-DCMAKE_BUILD_TYPE=Release"] ++ lib.optional (!enableXWayland) "-DNO_XWAYLAND=true"; prePatch = '' @@ -38,25 +63,21 @@ stdenv.mkDerivation rec { ''; installPhase = '' - cd ../ - mkdir -p $out/share/wayland-sessions - cp ./example/hyprland.desktop $out/share/wayland-sessions - mkdir -p $out/bin - cp ./build/Hyprland $out/bin - cp ./hyprctl/hyprctl $out/bin - mkdir -p $out/share/hyprland - cp ./assets/wall_2K.png $out/share/hyprland - cp ./assets/wall_4K.png $out/share/hyprland - cp ./assets/wall_8K.png $out/share/hyprland + pushd .. + install -Dm644 ./example/hyprland.desktop -t $out/share/wayland-sessions + install -Dm755 ./build/Hyprland -t $out/bin + install -Dm755 ./hyprctl/hyprctl -t $out/bin + install -Dm644 ./assets/* -t $out/share/hyprland + popd ''; - passthru.providedSessions = [ "hyprland" ]; + passthru.providedSessions = ["hyprland"]; meta = with lib; { homepage = "https://github.com/vaxerski/Hyprland"; - description = - "A dynamic tiling Wayland compositor that doesn't sacrifice on its looks"; + description = "A dynamic tiling Wayland compositor that doesn't sacrifice on its looks"; license = licenses.bsd3; platforms = platforms.linux; + mainProgram = "Hyprland"; }; } diff --git a/flake.lock b/flake.lock index 061978e7..baee9bf7 100644 --- a/flake.lock +++ b/flake.lock @@ -1,71 +1,5 @@ { "nodes": { - "cachix": { - "locked": { - "lastModified": 1652530570, - "narHash": "sha256-GWRrbUv9l1GSyBkj39s9AqNLX1l3rzVOwvnuG4WYM+E=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "4c560cc7ee57e1fb28e6fd7bdacdf01f948f8a91", - "type": "github" - }, - "original": { - "owner": "nixos", - "ref": "nixos-21.11", - "repo": "nixpkgs", - "type": "github" - } - }, - "flake-compat": { - "flake": false, - "locked": { - "lastModified": 1650374568, - "narHash": "sha256-Z+s0J8/r907g149rllvwhb4pKi8Wam5ij0st8PwAh+E=", - "owner": "edolstra", - "repo": "flake-compat", - "rev": "b4a34015c698c7793d592d66adbab377907a2be8", - "type": "github" - }, - "original": { - "owner": "edolstra", - "repo": "flake-compat", - "type": "github" - } - }, - "flake-utils": { - "locked": { - "lastModified": 1652557277, - "narHash": "sha256-jSes9DaIVMdmwBB78KkFUVrlDzawmD62vrUg0GS2500=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "12806d31a381e7cd169a6bac35590e7b36dc5fe5", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "lib-aggregate": { - "inputs": { - "flake-utils": "flake-utils", - "nixpkgs-lib": "nixpkgs-lib" - }, - "locked": { - "lastModified": 1652616584, - "narHash": "sha256-9Uc/k/t08QsJ8rl1n/cbT8L/JrCoDuE7TmsE+F1OiS8=", - "owner": "nix-community", - "repo": "lib-aggregate", - "rev": "81165c2e94b56afcb9486b82dc91d92dfb503a6b", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "lib-aggregate", - "type": "github" - } - }, "nixpkgs": { "locked": { "lastModified": 1652659998, @@ -77,58 +11,6 @@ }, "original": { "owner": "NixOS", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs-lib": { - "locked": { - "lastModified": 1652576347, - "narHash": "sha256-52Wu7hkcIRcS4UenSSrt01J2sAbbQ6YqxZIDpuEPL/c=", - "owner": "nix-community", - "repo": "nixpkgs.lib", - "rev": "bdf553800c9c34ed00641785b02038f67f44d671", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "nixpkgs.lib", - "type": "github" - } - }, - "nixpkgs-wayland": { - "inputs": { - "cachix": "cachix", - "flake-compat": "flake-compat", - "lib-aggregate": "lib-aggregate", - "nixpkgs": "nixpkgs_2" - }, - "locked": { - "lastModified": 1652618007, - "narHash": "sha256-eOH21ElHKORg1kd8Z/qX9naZElAOpCt5fPq26AxMQSw=", - "owner": "nix-community", - "repo": "nixpkgs-wayland", - "rev": "4588213f577661d37a42c7b6bba04c138c02d78f", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "nixpkgs-wayland", - "type": "github" - } - }, - "nixpkgs_2": { - "locked": { - "lastModified": 1652467128, - "narHash": "sha256-1wuQ7QgPQ3tugYcoVMJ3pUzl4wVdBzKZr9qtJAgA4VI=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "fb222e008681fce4608e94f2d1dfdf3d03a364c4", - "type": "github" - }, - "original": { - "owner": "nixos", "ref": "nixos-unstable", "repo": "nixpkgs", "type": "github" @@ -137,27 +19,10 @@ "root": { "inputs": { "nixpkgs": "nixpkgs", - "nixpkgs-wayland": "nixpkgs-wayland", - "utils": "utils", - "wlroots-git": "wlroots-git" + "wlroots": "wlroots" } }, - "utils": { - "locked": { - "lastModified": 1652557277, - "narHash": "sha256-jSes9DaIVMdmwBB78KkFUVrlDzawmD62vrUg0GS2500=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "12806d31a381e7cd169a6bac35590e7b36dc5fe5", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "wlroots-git": { + "wlroots": { "flake": false, "locked": { "host": "gitlab.freedesktop.org", diff --git a/flake.nix b/flake.nix index 2a4d5e0a..1102d007 100644 --- a/flake.nix +++ b/flake.nix @@ -1,43 +1,34 @@ -# Based on fortuneteller2k's (https://github.com/fortuneteller2k/nixpkgs-f2k) package repo { - description = - "Hyprland is a dynamic tiling Wayland compositor that doesn't sacrifice on its looks."; + description = "Hyprland is a dynamic tiling Wayland compositor that doesn't sacrifice on its looks"; + inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.11"; - utils.url = "github:numtide/flake-utils"; - nixpkgs-wayland.url = "github:nix-community/nixpkgs-wayland"; - wlroots-git = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + wlroots = { url = "gitlab:wlroots/wlroots?host=gitlab.freedesktop.org"; flake = false; }; }; - outputs = { self, nixpkgs, utils, nixpkgs-wayland, wlroots-git }: - { - overlay = final: prev: { - hyprland = prev.callPackage self { - src = self; - wlroots = (nixpkgs-wayland.overlays.default final prev).wlroots.overrideAttrs (prev: rec { - src = wlroots-git; - }); - }; - }; - overlays.default = self.overlay; - } // utils.lib.eachSystem [ "aarch64-linux" "x86_64-linux" ] (system: - let pkgs = nixpkgs.legacyPackages.${system}; - in rec { - packages = { - hyprland = pkgs.callPackage self { - src = self; - wlroots = nixpkgs-wayland.packages.${system}.wlroots.overrideAttrs (prev: rec { - src = wlroots-git; - }); - }; - }; - defaultPackage = packages.hyprland; - apps.hyprland = utils.lib.mkApp { drv = packages.hyprland; }; - defaultApp = apps.hyprland; - apps.default = - utils.lib.mkApp { drv = self.packages.${system}.hyprland; }; + outputs = inputs @ { + self, + nixpkgs, + ... + }: let + supportedSystems = [ + "aarch64-linux" + "x86_64-linux" + ]; + genSystems = nixpkgs.lib.genAttrs supportedSystems; + pkgsFor = nixpkgs.legacyPackages; + in { + packages = genSystems (system: { + wlroots = pkgsFor.${system}.wlroots.overrideAttrs (prev: { + src = inputs.wlroots; }); + default = pkgsFor.${system}.callPackage ./default.nix { + version = self.lastModifiedDate; + inherit (self.packages.${system}) wlroots; + }; + }); + }; } From 5019682144d5844a57448eb5e68c44a39a20862f Mon Sep 17 00:00:00 2001 From: Fernando Ayats Date: Tue, 17 May 2022 13:35:34 +0200 Subject: [PATCH 2/8] nix: include example conf --- default.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/default.nix b/default.nix index a5abdd5d..cb0b7218 100644 --- a/default.nix +++ b/default.nix @@ -68,6 +68,7 @@ stdenv.mkDerivation { install -Dm755 ./build/Hyprland -t $out/bin install -Dm755 ./hyprctl/hyprctl -t $out/bin install -Dm644 ./assets/* -t $out/share/hyprland + install -Dm644 ./example/hyprland.conf -t $out/share/hyprland popd ''; From 16ad81f2360665f3327b88f697df0ff6a33c7f6c Mon Sep 17 00:00:00 2001 From: Fernando Ayats Date: Tue, 17 May 2022 13:43:31 +0200 Subject: [PATCH 3/8] nix: added workflow --- .github/workflows/ci.yaml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a7ed4357..4cb275ed 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -32,7 +32,7 @@ jobs: - name: Fix permissions for git run: | git config --global --add safe.directory /__w/Hyprland/Hyprland - + - name: Checkout Hyprland uses: actions/checkout@v3 @@ -45,3 +45,18 @@ jobs: run: | make legacyrenderer + nix: + name: "Build Hyprland (Nix)" + runs-on: ubuntu-latest + steps: + - name: Clone repository + uses: actions/checkout@v3 + - name: Install nix + uses: cachix/install-nix-action@v17 + with: + install_url: https://releases.nixos.org/nix/nix-2.8.0/install + extra_nix_config: | + auto-optimise-store = true + experimental-features = nix-command flakes + - name: Build HyprLand with default settings + run: nix build --print-build-logs From c02e1635918c670d2ccd31e7e88f58bfed31cbf9 Mon Sep 17 00:00:00 2001 From: Fernando Ayats Date: Tue, 17 May 2022 13:44:43 +0200 Subject: [PATCH 4/8] Added workflow_dispatch event trigger --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4cb275ed..513ac45c 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,6 +1,6 @@ name: Build Hyprland -on: [push, pull_request] +on: [push, pull_request, workflow_dispatch] jobs: gcc: name: "Build Hyprland (Arch)" From c7dc0fd50986a353a814cd65360a8ee17c5186a0 Mon Sep 17 00:00:00 2001 From: Fernando Ayats Date: Tue, 17 May 2022 14:03:58 +0200 Subject: [PATCH 5/8] nix: misc tweaks to flake --- flake.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/flake.nix b/flake.nix index 1102d007..506b89bb 100644 --- a/flake.nix +++ b/flake.nix @@ -23,6 +23,7 @@ in { packages = genSystems (system: { wlroots = pkgsFor.${system}.wlroots.overrideAttrs (prev: { + version = inputs.wlroots.lastModifiedDate; src = inputs.wlroots; }); default = pkgsFor.${system}.callPackage ./default.nix { @@ -30,5 +31,8 @@ inherit (self.packages.${system}) wlroots; }; }); + formatter = genSystems (system: pkgsFor.${system}.alejandra); + # TODO Provide a nixos module for easy installation + # nixosModules.default = import ./module.nix; }; } From b3276d32077b7883e4cede784b6598fc3ca403c0 Mon Sep 17 00:00:00 2001 From: Fernando Ayats Date: Tue, 17 May 2022 15:10:00 +0200 Subject: [PATCH 6/8] nix: add overlay back --- flake.nix | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 506b89bb..96b2375f 100644 --- a/flake.nix +++ b/flake.nix @@ -31,8 +31,15 @@ inherit (self.packages.${system}) wlroots; }; }); + formatter = genSystems (system: pkgsFor.${system}.alejandra); - # TODO Provide a nixos module for easy installation + + # TODO Provide a nixos module for easy installation and configuration # nixosModules.default = import ./module.nix; + + # Deprecated + overlay = _: prev: { + hyprland = self.packages.${prev.system}.default; + }; }; } From 9d89e0f08e1782ddeefa030755805387fb14dccf Mon Sep 17 00:00:00 2001 From: Fernando Ayats Date: Sat, 21 May 2022 12:07:55 +0200 Subject: [PATCH 7/8] nix: add nixos module --- flake.nix | 26 ++++++++++++++++------- module.nix | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 8 deletions(-) create mode 100644 module.nix diff --git a/flake.nix b/flake.nix index 96b2375f..c7e672e5 100644 --- a/flake.nix +++ b/flake.nix @@ -14,32 +14,42 @@ nixpkgs, ... }: let - supportedSystems = [ - "aarch64-linux" + inherit (nixpkgs) lib; + genSystems = lib.genAttrs [ "x86_64-linux" ]; - genSystems = nixpkgs.lib.genAttrs supportedSystems; pkgsFor = nixpkgs.legacyPackages; + # https://github.com/NixOS/rfcs/pull/107 + mkVersion = longDate: + lib.concatStrings [ + "0.pre" + "+date=" + (lib.concatStringsSep "-" [ + (__substring 0 4 longDate) + (__substring 4 2 longDate) + (__substring 6 2 longDate) + ]) + ]; in { packages = genSystems (system: { wlroots = pkgsFor.${system}.wlroots.overrideAttrs (prev: { - version = inputs.wlroots.lastModifiedDate; + version = mkVersion inputs.wlroots.lastModifiedDate; src = inputs.wlroots; }); default = pkgsFor.${system}.callPackage ./default.nix { - version = self.lastModifiedDate; + version = mkVersion self.lastModifiedDate; inherit (self.packages.${system}) wlroots; }; }); formatter = genSystems (system: pkgsFor.${system}.alejandra); - # TODO Provide a nixos module for easy installation and configuration - # nixosModules.default = import ./module.nix; + nixosModules.default = import ./module.nix self; # Deprecated - overlay = _: prev: { + overlays.default = _: prev: { hyprland = self.packages.${prev.system}.default; }; + overlay = self.overlays.default; }; } diff --git a/module.nix b/module.nix new file mode 100644 index 00000000..a7460b34 --- /dev/null +++ b/module.nix @@ -0,0 +1,62 @@ +# Copied from https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/programs/sway.nix +self: { + config, + lib, + pkgs, + ... +}: +with lib; let + cfg = config.programs.hyprland; +in { + options.programs.hyprland = { + enable = mkEnableOption '' + Hyprland, the dynamic tiling Wayland compositor that doesn't sacrifice on its looks. + You can manually launch Hyprland by executing "exec Hyprland" on a TTY. + A configuration file will be generated in ~/.config/hypr/hyprland.conf. + See for + more information. + ''; + + package = mkOption { + type = types.package; + default = self.packages.${pkgs.system}.default; + defaultText = literalExpression ".packages..default"; + example = literalExpression ".packages..default.override { }"; + description = '' + Hyprland package to use. + ''; + }; + + extraPackages = mkOption { + type = with types; listOf package; + default = with pkgs; [ + kitty + wofi + swaybg + ]; + defaultText = literalExpression '' + with pkgs; [ kitty wofi swaybg ]; + ''; + example = literalExpression '' + with pkgs; [ + alacritty wofi + ] + ''; + description = '' + Extra packages to be installed system wide. + ''; + }; + }; + + config = mkIf cfg.enable { + environment.systemPackages = [cfg.package] ++ cfg.extraPackages; + security.polkit.enable = true; + hardware.opengl.enable = mkDefault true; + fonts.enableDefaultFonts = mkDefault true; + programs.dconf.enable = mkDefault true; + services.xserver.displayManager.sessionPackages = [cfg.package]; + programs.xwayland.enable = mkDefault true; + xdg.portal.enable = mkDefault true; + xdg.portal.extraPortals = [pkgs.xdg-desktop-portal-wlr]; + }; +} From 2e6e5b4268f13021da837ed8850b43d905833350 Mon Sep 17 00:00:00 2001 From: Fernando Ayats Date: Sat, 21 May 2022 12:39:15 +0200 Subject: [PATCH 8/8] nix: put workflow in different file --- .github/workflows/ci.yaml | 16 ---------------- .github/workflows/nix-build.yaml | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 16 deletions(-) create mode 100644 .github/workflows/nix-build.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 513ac45c..aaabde25 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -44,19 +44,3 @@ jobs: - name: Build Hyprland with LEGACY_RENDERER run: | make legacyrenderer - - nix: - name: "Build Hyprland (Nix)" - runs-on: ubuntu-latest - steps: - - name: Clone repository - uses: actions/checkout@v3 - - name: Install nix - uses: cachix/install-nix-action@v17 - with: - install_url: https://releases.nixos.org/nix/nix-2.8.0/install - extra_nix_config: | - auto-optimise-store = true - experimental-features = nix-command flakes - - name: Build HyprLand with default settings - run: nix build --print-build-logs diff --git a/.github/workflows/nix-build.yaml b/.github/workflows/nix-build.yaml new file mode 100644 index 00000000..0f74c4d5 --- /dev/null +++ b/.github/workflows/nix-build.yaml @@ -0,0 +1,19 @@ +name: Build Hyprland (Nix) + +on: [push, pull_request, workflow_dispatch] +jobs: + nix: + name: "Build Hyprland (Nix)" + runs-on: ubuntu-latest + steps: + - name: Clone repository + uses: actions/checkout@v3 + - name: Install nix + uses: cachix/install-nix-action@v17 + with: + install_url: https://releases.nixos.org/nix/nix-2.8.0/install + extra_nix_config: | + auto-optimise-store = true + experimental-features = nix-command flakes + - name: Build HyprLand with default settings + run: nix build --print-build-logs