Nix: corrections for overlays, overrideable systems (#2929)

* nix: overlays: move waybar-hyprland to own overlay

* flake: use legacyPackages for formatter

Run `nix fmt` for all files.

* flake: move default overlay to nix/overlays.nix

* nix: lib: remove lib

* nix: overlays: extras: explicitly include xdph overlays

* nix: use interpolation for versions

* nix: overlays: include deps with hyprland-packages

* flake: make systems overrideable

* flake: packages: inherit from overlaid pkgsFor
This commit is contained in:
Jacob Birkett 2023-08-12 07:22:37 -05:00 committed by GitHub
parent 3f7f4207a6
commit d20837bef8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 143 additions and 107 deletions

View file

@ -4,14 +4,17 @@
"inputs": { "inputs": {
"nixpkgs": [ "nixpkgs": [
"nixpkgs" "nixpkgs"
],
"systems": [
"systems"
] ]
}, },
"locked": { "locked": {
"lastModified": 1684265364, "lastModified": 1691753796,
"narHash": "sha256-AxNnWbthsuNx73HDQr0eBxrcE3+yfl/WsaXZqUFmkpQ=", "narHash": "sha256-zOEwiWoXk3j3+EoF3ySUJmberFewWlagvewDRuWYAso=",
"owner": "hyprwm", "owner": "hyprwm",
"repo": "hyprland-protocols", "repo": "hyprland-protocols",
"rev": "8c279b9fb0f2b031427dc5ef4eab53f2ed835530", "rev": "0c2ce70625cb30aef199cb388f99e19a61a6ce03",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -40,10 +43,26 @@
"inputs": { "inputs": {
"hyprland-protocols": "hyprland-protocols", "hyprland-protocols": "hyprland-protocols",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"systems": "systems",
"wlroots": "wlroots", "wlroots": "wlroots",
"xdph": "xdph" "xdph": "xdph"
} }
}, },
"systems": {
"locked": {
"lastModified": 1689347949,
"narHash": "sha256-12tWmuL2zgBgZkdoB6qXZsgJEH9LR3oUgpaQq2RbI80=",
"owner": "nix-systems",
"repo": "default-linux",
"rev": "31732fcf5e8fea42e59c2488ad31a0e651500f68",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default-linux",
"type": "github"
}
},
"wlroots": { "wlroots": {
"flake": false, "flake": false,
"locked": { "locked": {
@ -70,14 +89,17 @@
], ],
"nixpkgs": [ "nixpkgs": [
"nixpkgs" "nixpkgs"
],
"systems": [
"systems"
] ]
}, },
"locked": { "locked": {
"lastModified": 1691082525, "lastModified": 1691841170,
"narHash": "sha256-C5AO0KnyAFJaCkOn+5nJfWm0kyiPn/Awh0lKTjhgr7Y=", "narHash": "sha256-RCTm1/MVWYPnReMgyp7tr2ogGYo/pvw38jZaFwemgPU=",
"owner": "hyprwm", "owner": "hyprwm",
"repo": "xdg-desktop-portal-hyprland", "repo": "xdg-desktop-portal-hyprland",
"rev": "42747d267ab4345c4ceb78cd4a4fe99f072d80fc", "rev": "57a3a41ba6b358109e4fc25c6a4706b5f7d93c6b",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -4,6 +4,9 @@
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
# <https://github.com/nix-systems/nix-systems>
systems.url = "github:nix-systems/default-linux";
wlroots = { wlroots = {
type = "gitlab"; type = "gitlab";
host = "gitlab.freedesktop.org"; host = "gitlab.freedesktop.org";
@ -16,11 +19,13 @@
hyprland-protocols = { hyprland-protocols = {
url = "github:hyprwm/hyprland-protocols"; url = "github:hyprwm/hyprland-protocols";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
inputs.systems.follows = "systems";
}; };
xdph = { xdph = {
url = "github:hyprwm/xdg-desktop-portal-hyprland"; url = "github:hyprwm/xdg-desktop-portal-hyprland";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
inputs.systems.follows = "systems";
inputs.hyprland-protocols.follows = "hyprland-protocols"; inputs.hyprland-protocols.follows = "hyprland-protocols";
}; };
}; };
@ -28,39 +33,23 @@
outputs = inputs @ { outputs = inputs @ {
self, self,
nixpkgs, nixpkgs,
systems,
... ...
}: let }: let
lib = nixpkgs.lib.extend (import ./nix/lib.nix); inherit (nixpkgs) lib;
genSystems = lib.genAttrs [ eachSystem = lib.genAttrs (import systems);
# Add more systems if they are supported pkgsFor = eachSystem (system:
"aarch64-linux"
"x86_64-linux"
];
pkgsFor = genSystems (system:
import nixpkgs { import nixpkgs {
inherit system; localSystem = system;
overlays = [ overlays = with self.overlays; [
self.overlays.hyprland-packages hyprland-packages
self.overlays.wlroots-hyprland hyprland-extras
inputs.hyprland-protocols.overlays.default
]; ];
}); });
in { in {
overlays = overlays = import ./nix/overlays.nix {inherit self lib inputs;};
(import ./nix/overlays.nix {inherit self lib inputs;})
// {
default =
lib.mkJoinedOverlays
(with self.overlays; [
hyprland-packages
hyprland-extras
wlroots-hyprland
inputs.hyprland-protocols.overlays.default
]);
};
checks = genSystems (system: checks = eachSystem (system:
(lib.filterAttrs (lib.filterAttrs
(n: _: (lib.hasPrefix "hyprland" n) && !(lib.hasSuffix "debug" n)) (n: _: (lib.hasPrefix "hyprland" n) && !(lib.hasSuffix "debug" n))
self.packages.${system}) self.packages.${system})
@ -68,16 +57,32 @@
inherit (self.packages.${system}) xdg-desktop-portal-hyprland; inherit (self.packages.${system}) xdg-desktop-portal-hyprland;
}); });
packages = genSystems (system: packages = eachSystem (system: {
(self.overlays.default pkgsFor.${system} pkgsFor.${system}) default = self.packages.${system}.hyprland;
// { inherit
default = self.packages.${system}.hyprland; (pkgsFor.${system})
}); # hyprland-packages
hyprland
hyprland-unwrapped
hyprland-debug
hyprland-hidpi
hyprland-nvidia
hyprland-no-hidpi
# hyprland-extras
xdg-desktop-portal-hyprland
hyprland-share-picker
waybar-hyprland
# dependencies
hyprland-protocols
wlroots-hyprland
udis86
;
});
devShells = genSystems (system: { devShells = eachSystem (system: {
default = pkgsFor.${system}.mkShell { default = pkgsFor.${system}.mkShell {
name = "hyprland-shell"; name = "hyprland-shell";
nativeBuildInputs = with pkgsFor.${system}; [ cmake python3 ]; nativeBuildInputs = with pkgsFor.${system}; [cmake python3];
buildInputs = [self.packages.${system}.wlroots-hyprland]; buildInputs = [self.packages.${system}.wlroots-hyprland];
inputsFrom = [ inputsFrom = [
self.packages.${system}.wlroots-hyprland self.packages.${system}.wlroots-hyprland
@ -86,7 +91,7 @@
}; };
}); });
formatter = genSystems (system: pkgsFor.${system}.alejandra); formatter = eachSystem (system: nixpkgs.legacyPackages.${system}.alejandra);
nixosModules.default = import ./nix/module.nix inputs; nixosModules.default = import ./nix/module.nix inputs;
homeManagerModules.default = import ./nix/hm-module.nix self; homeManagerModules.default = import ./nix/hm-module.nix self;

View file

@ -123,7 +123,7 @@ in
ln -s ${wlroots}/include/wlr $dev/include/hyprland/wlroots ln -s ${wlroots}/include/wlr $dev/include/hyprland/wlroots
${lib.optionalString wrapRuntimeDeps '' ${lib.optionalString wrapRuntimeDeps ''
wrapProgram $out/bin/Hyprland \ wrapProgram $out/bin/Hyprland \
--suffix PATH : ${lib.makeBinPath [ binutils pciutils ]} --suffix PATH : ${lib.makeBinPath [binutils pciutils]}
''} ''}
''; '';

View file

@ -119,10 +119,14 @@ in {
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
warnings = warnings =
if (cfg.systemdIntegration || cfg.plugins != []) && cfg.extraConfig == null then if (cfg.systemdIntegration || cfg.plugins != []) && cfg.extraConfig == null
[ ''You have enabled hyprland.systemdIntegration or listed plugins in hyprland.plugins. then [
Your Hyprland config will be linked by home manager. ''
Set hyprland.extraConfig or unset hyprland.systemdIntegration and hyprland.plugins to remove this warning.'' ] You have enabled hyprland.systemdIntegration or listed plugins in hyprland.plugins.
Your Hyprland config will be linked by home manager.
Set hyprland.extraConfig or unset hyprland.systemdIntegration and hyprland.plugins to remove this warning.
''
]
else []; else [];
home.packages = home.packages =
@ -138,9 +142,17 @@ in {
exec-once=${pkgs.dbus}/bin/dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY HYPRLAND_INSTANCE_SIGNATURE XDG_CURRENT_DESKTOP && systemctl --user start hyprland-session.target exec-once=${pkgs.dbus}/bin/dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY HYPRLAND_INSTANCE_SIGNATURE XDG_CURRENT_DESKTOP && systemctl --user start hyprland-session.target
'') '')
+ lib.concatStrings (builtins.map (entry: let + lib.concatStrings (builtins.map (entry: let
plugin = if lib.types.package.check entry then "${entry}/lib/lib${entry.pname}.so" else entry; plugin =
in "plugin = ${plugin}\n") cfg.plugins) if lib.types.package.check entry
+ (if cfg.extraConfig != null then cfg.extraConfig else ""); then "${entry}/lib/lib${entry.pname}.so"
else entry;
in "plugin = ${plugin}\n")
cfg.plugins)
+ (
if cfg.extraConfig != null
then cfg.extraConfig
else ""
);
onChange = let onChange = let
hyprlandPackage = hyprlandPackage =

View file

@ -1,8 +0,0 @@
final: prev: let
lib = final;
mkJoinedOverlays = overlays: final: prev:
lib.foldl' (attrs: overlay: attrs // (overlay final prev)) {} overlays;
in prev // {
inherit mkJoinedOverlays;
}

View file

@ -10,70 +10,75 @@
(builtins.substring 4 2 longDate) (builtins.substring 4 2 longDate)
(builtins.substring 6 2 longDate) (builtins.substring 6 2 longDate)
]); ]);
mkJoinedOverlays = overlays: final: prev:
lib.foldl' (attrs: overlay: attrs // (overlay final prev)) {} overlays;
in { in {
# Packages for variations of Hyprland, and its dependencies. # Contains what a user is most likely to care about:
hyprland-packages = final: prev: { # Hyprland itself, XDPH, the Share Picker, and patched Waybar.
hyprland = final.callPackage ./default.nix { default = mkJoinedOverlays (with self.overlays; [
version = hyprland-packages
props.version hyprland-extras
+ "+date=" ]);
+ (mkDate (self.lastModifiedDate or "19700101"))
+ "_"
+ (self.shortRev or "dirty");
wlroots = final.wlroots-hyprland;
commit = self.rev or "";
inherit (final) udis86 hyprland-protocols;
};
hyprland-unwrapped = final.hyprland.override {wrapRuntimeDeps = false;}; # Packages for variations of Hyprland, dependencies included.
hyprland-debug = final.hyprland.override {debug = true;}; hyprland-packages = mkJoinedOverlays [
hyprland-hidpi = final.hyprland.override {hidpiXWayland = true;}; # Dependencies
hyprland-nvidia = final.hyprland.override {nvidiaPatches = true;}; inputs.hyprland-protocols.overlays.default
hyprland-no-hidpi = self.overlays.wlroots-hyprland
builtins.trace self.overlays.udis86
"hyprland-no-hidpi was removed. Please use the default package." # Hyprland packages themselves
final.hyprland; (final: prev: {
hyprland = final.callPackage ./default.nix {
version = "${props.version}+date=${mkDate (self.lastModifiedDate or "19700101")}_${self.shortRev or "dirty"}";
wlroots = final.wlroots-hyprland;
commit = self.rev or "";
inherit (final) udis86 hyprland-protocols;
};
udis86 = final.callPackage ./udis86.nix {}; hyprland-unwrapped = final.hyprland.override {wrapRuntimeDeps = false;};
}; hyprland-debug = final.hyprland.override {debug = true;};
hyprland-hidpi = final.hyprland.override {hidpiXWayland = true;};
hyprland-nvidia = final.hyprland.override {nvidiaPatches = true;};
hyprland-no-hidpi =
builtins.trace
"hyprland-no-hidpi was removed. Please use the default package."
final.hyprland;
})
];
# Packages for extra software recommended for usage with Hyprland, # Packages for extra software recommended for usage with Hyprland,
# including forked or patched packages for compatibility. # including forked or patched packages for compatibility.
hyprland-extras = lib.mkJoinedOverlays [ hyprland-extras = mkJoinedOverlays [
# Include any inputs' specific overlays whose attributes should inputs.xdph.overlays.xdg-desktop-portal-hyprland
# be re-exported by the Hyprland flake. inputs.xdph.overlays.hyprland-share-picker
# self.overlays.waybar-hyprland
inputs.xdph.overlays.default
# Provides:
# - xdg-desktop-portal-hyprland
# - hyprland-share-picker
#
# Attributes for `hyprland-extras` defined by this flake can
# go in the oberlay below.
(final: prev: {
waybar-hyprland = prev.waybar.overrideAttrs (old: {
postPatch = ''
# use hyprctl to switch workspaces
sed -i 's/zext_workspace_handle_v1_activate(workspace_handle_);/const std::string command = "hyprctl dispatch workspace " + name_;\n\tsystem(command.c_str());/g' src/modules/wlr/workspace_manager.cpp
'';
postFixup = ''
wrapProgram $out/bin/waybar \
--suffix PATH : ${lib.makeBinPath [final.hyprland]}
'';
mesonFlags = old.mesonFlags ++ ["-Dexperimental=true"];
});
})
]; ];
waybar-hyprland = final: prev: {
waybar-hyprland = prev.waybar.overrideAttrs (old: {
postPatch = ''
# use hyprctl to switch workspaces
sed -i 's/zext_workspace_handle_v1_activate(workspace_handle_);/const std::string command = "hyprctl dispatch workspace " + name_;\n\tsystem(command.c_str());/g' src/modules/wlr/workspace_manager.cpp
'';
postFixup = ''
wrapProgram $out/bin/waybar \
--suffix PATH : ${lib.makeBinPath [final.hyprland]}
'';
mesonFlags = old.mesonFlags ++ ["-Dexperimental=true"];
});
};
udis86 = final: prev: {
udis86 = final.callPackage ./udis86.nix {};
};
# Patched version of wlroots for Hyprland. # Patched version of wlroots for Hyprland.
# It is under a new package name so as to not conflict with # It is under a new package name so as to not conflict with
# the standard version in nixpkgs. # the standard version in nixpkgs.
wlroots-hyprland = final: prev: { wlroots-hyprland = final: prev: {
wlroots-hyprland = final.callPackage ./wlroots.nix { wlroots-hyprland = final.callPackage ./wlroots.nix {
version = version = "${mkDate (inputs.wlroots.lastModifiedDate or "19700101")}_${inputs.wlroots.shortRev or "dirty"}";
mkDate (inputs.wlroots.lastModifiedDate or "19700101")
+ "_"
+ (inputs.wlroots.shortRev or "dirty");
src = inputs.wlroots; src = inputs.wlroots;
libdisplay-info = prev.libdisplay-info.overrideAttrs (old: { libdisplay-info = prev.libdisplay-info.overrideAttrs (old: {
version = "0.1.1+date=2023-03-02"; version = "0.1.1+date=2023-03-02";