From 8ce09bd2346dbf471b2555c3e4110d05fb74b3eb Mon Sep 17 00:00:00 2001 From: wxlyyy <1556588440@qq.com> Date: Sat, 20 Dec 2025 03:20:39 +0800 Subject: [PATCH] Nix: use nixfmt as formatter --- flake.nix | 110 +++++++++++++++++++++++-------------------- nix/home-module.nix | 11 ++--- nix/nixos-module.nix | 18 +++---- nix/package.nix | 91 +++++++++++++++++------------------ shell.nix | 2 +- 5 files changed, 119 insertions(+), 113 deletions(-) diff --git a/flake.nix b/flake.nix index 1e3c499f0..c4902055a 100644 --- a/flake.nix +++ b/flake.nix @@ -5,65 +5,71 @@ nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; }; - outputs = { - self, - nixpkgs, - ... - }: let - eachSystem = nixpkgs.lib.genAttrs nixpkgs.lib.platforms.linux; - pkgsFor = eachSystem (system: nixpkgs.legacyPackages.${system}.appendOverlays [self.overlays.default]); - in { - formatter = eachSystem (system: pkgsFor.${system}.alejandra); + outputs = + { + self, + nixpkgs, + ... + }: + let + eachSystem = nixpkgs.lib.genAttrs nixpkgs.lib.platforms.linux; + pkgsFor = eachSystem ( + system: nixpkgs.legacyPackages.${system}.appendOverlays [ self.overlays.default ] + ); + in + { + formatter = eachSystem (system: pkgsFor.${system}.nixfmt); - packages = eachSystem ( - system: { + packages = eachSystem (system: { default = pkgsFor.${system}.noctalia-shell; - } - ); + }); - overlays = { - default = final: prev: { - noctalia-shell = final.callPackage ./nix/package.nix { - version = let - mkDate = longDate: final.lib.concatStringsSep "-" [ - (builtins.substring 0 4 longDate) - (builtins.substring 4 2 longDate) - (builtins.substring 6 2 longDate) - ]; - in - mkDate (self.lastModifiedDate or "19700101") - + "_" - + (self.shortRev or "dirty"); + overlays = { + default = final: prev: { + noctalia-shell = final.callPackage ./nix/package.nix { + version = + let + mkDate = + longDate: + final.lib.concatStringsSep "-" [ + (builtins.substring 0 4 longDate) + (builtins.substring 4 2 longDate) + (builtins.substring 6 2 longDate) + ]; + in + mkDate (self.lastModifiedDate or "19700101") + "_" + (self.shortRev or "dirty"); + }; }; }; - }; - devShells = eachSystem ( - system: { - default = pkgsFor.${system}.callPackage ./nix/shell.nix {}; - } - ); + devShells = eachSystem (system: { + default = pkgsFor.${system}.callPackage ./nix/shell.nix { }; + }); - homeModules.default = { - pkgs, - lib, - ... - }: { - imports = [./nix/home-module.nix]; - programs.noctalia-shell.package = - lib.mkDefault - self.packages.${pkgs.stdenv.hostPlatform.system}.default; - }; + homeModules.default = + { + pkgs, + lib, + ... + }: + { + imports = [ ./nix/home-module.nix ]; + programs.noctalia-shell.package = + lib.mkDefault + self.packages.${pkgs.stdenv.hostPlatform.system}.default; + }; - nixosModules.default = { - pkgs, - lib, - ... - }: { - imports = [./nix/nixos-module.nix]; - services.noctalia-shell.package = - lib.mkDefault - self.packages.${pkgs.stdenv.hostPlatform.system}.default; + nixosModules.default = + { + pkgs, + lib, + ... + }: + { + imports = [ ./nix/nixos-module.nix ]; + services.noctalia-shell.package = + lib.mkDefault + self.packages.${pkgs.stdenv.hostPlatform.system}.default; + }; }; - }; } diff --git a/nix/home-module.nix b/nix/home-module.nix index fb150777a..2d7450b5b 100644 --- a/nix/home-module.nix +++ b/nix/home-module.nix @@ -107,15 +107,15 @@ in { templates = { neovim = { - inputPath = "~/.config/matugen/templates/template.lua"; - outputPath = "~/.config/nvim/generated.lua"; - postHook = "pkill -SIGUSR1 nvim"; + input_path = "~/.config/matugen/templates/template.lua"; + output_path = "~/.config/nvim/generated.lua"; + post_hook = "pkill -SIGUSR1 nvim"; }; }; } ''; description = '' - Template definitions for Matugen. + Template definitions for Matugen, to be written to ~/.config/noctalia/user-templates.toml. This option accepts: - a Nix attrset (converted to TOML automatically) @@ -135,7 +135,6 @@ in config = let - restart = "${pkgs.systemd}/bin/systemctl --user try-restart noctalia-shell.service 2>/dev/null || true"; useApp2Unit = cfg.settings.appLauncher.useApp2Unit or false; in lib.mkIf cfg.enable { @@ -169,11 +168,9 @@ in xdg.configFile = { "noctalia/settings.json" = lib.mkIf (cfg.settings != { }) { - onChange = lib.mkIf (!cfg.systemd.enable) restart; source = generateJson "settings" cfg.settings; }; "noctalia/colors.json" = lib.mkIf (cfg.colors != { }) { - onChange = lib.mkIf (!cfg.systemd.enable) restart; source = generateJson "colors" cfg.colors; }; "noctalia/user-templates.toml" = lib.mkIf (cfg.user-templates != { }) { diff --git a/nix/nixos-module.nix b/nix/nixos-module.nix index 124acb111..f14f4406c 100644 --- a/nix/nixos-module.nix +++ b/nix/nixos-module.nix @@ -2,9 +2,11 @@ config, lib, ... -}: let +}: +let cfg = config.services.noctalia-shell; -in { +in +{ options.services.noctalia-shell = { enable = lib.mkEnableOption "Noctalia shell systemd service"; @@ -24,11 +26,11 @@ in { config = lib.mkIf cfg.enable { systemd.user.services.noctalia-shell = { description = "Noctalia Shell - Wayland desktop shell"; - documentation = ["https://docs.noctalia.dev/docs"]; - after = [cfg.target]; - partOf = [cfg.target]; - wantedBy = [cfg.target]; - restartTriggers = [cfg.package]; + documentation = [ "https://docs.noctalia.dev/docs" ]; + after = [ cfg.target ]; + partOf = [ cfg.target ]; + wantedBy = [ cfg.target ]; + restartTriggers = [ cfg.package ]; environment = { PATH = lib.mkForce null; @@ -43,6 +45,6 @@ in { }; }; - environment.systemPackages = [cfg.package]; + environment.systemPackages = [ cfg.package ]; }; } diff --git a/nix/package.nix b/nix/package.nix index e1ef9d4f8..c3de90990 100644 --- a/nix/package.nix +++ b/nix/package.nix @@ -16,10 +16,12 @@ imagemagick, wget, gpu-screen-recorder, # optional -}: let +}: +let src = lib.cleanSourceWith { src = ../.; - filter = path: type: + filter = + path: type: !(builtins.any (prefix: lib.path.hasPrefix (../. + prefix) (/. + path)) [ /.github /.gitignore @@ -36,52 +38,51 @@ ]); }; - runtimeDeps = - [ - brightnessctl - cava - cliphist - ddcutil - matugen - wlsunset - wl-clipboard - imagemagick - wget - ] - ++ lib.optionals (stdenvNoCC.hostPlatform.system == "x86_64-linux") [ - gpu-screen-recorder - ]; + runtimeDeps = [ + brightnessctl + cava + cliphist + ddcutil + matugen + wlsunset + wl-clipboard + imagemagick + wget + ] + ++ lib.optionals (stdenvNoCC.hostPlatform.system == "x86_64-linux") [ + gpu-screen-recorder + ]; in - stdenvNoCC.mkDerivation { - pname = "noctalia-shell"; - inherit version src; +stdenvNoCC.mkDerivation { + pname = "noctalia-shell"; + inherit version src; - nativeBuildInputs = [ - qt6.wrapQtAppsHook - ]; + nativeBuildInputs = [ + qt6.wrapQtAppsHook + ]; - buildInputs = [ - qt6.qtbase - qt6.qtmultimedia - ]; + buildInputs = [ + qt6.qtbase + qt6.qtmultimedia + ]; - installPhase = '' - mkdir -p $out/share/noctalia-shell $out/bin - cp -r . $out/share/noctalia-shell - ln -s ${quickshell}/bin/qs $out/bin/noctalia-shell - ''; + installPhase = '' + mkdir -p $out/share/noctalia-shell $out/bin + cp -r . $out/share/noctalia-shell + ln -s ${quickshell}/bin/qs $out/bin/noctalia-shell + ''; - preFixup = '' - qtWrapperArgs+=( - --prefix PATH : ${lib.makeBinPath runtimeDeps} - --add-flags "-p $out/share/noctalia-shell" - ) - ''; + preFixup = '' + qtWrapperArgs+=( + --prefix PATH : ${lib.makeBinPath runtimeDeps} + --add-flags "-p $out/share/noctalia-shell" + ) + ''; - meta = { - description = "A sleek and minimal desktop shell thoughtfully crafted for Wayland, built with Quickshell."; - homepage = "https://github.com/noctalia-dev/noctalia-shell"; - license = lib.licenses.mit; - mainProgram = "noctalia-shell"; - }; - } + meta = { + description = "A sleek and minimal desktop shell thoughtfully crafted for Wayland, built with Quickshell."; + homepage = "https://github.com/noctalia-dev/noctalia-shell"; + license = lib.licenses.mit; + mainProgram = "noctalia-shell"; + }; +} diff --git a/shell.nix b/shell.nix index 8f5bdf1f4..770041516 100644 --- a/shell.nix +++ b/shell.nix @@ -1 +1 @@ -(import {}).callPackage ./nix/shell.nix {} +(import { }).callPackage ./nix/shell.nix { }