From 3b80b435827b610f730998548af416fc0a0c7b1b Mon Sep 17 00:00:00 2001 From: atagen Date: Thu, 29 May 2025 23:35:29 +1000 Subject: [PATCH] chore(nix): simplify packaging and outputs --- default.nix | 12 ++++ flake.lock | 89 +++++------------------ flake.nix | 183 +++++++++++++++++------------------------------ nix/devshell.nix | 25 ------- nix/module.nix | 46 +++++++----- nix/package.nix | 124 ++++++++++++++------------------ shell.nix | 19 +++-- 7 files changed, 187 insertions(+), 311 deletions(-) create mode 100644 default.nix delete mode 100644 nix/devshell.nix diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..d6a41ce --- /dev/null +++ b/default.nix @@ -0,0 +1,12 @@ +(import ( + let + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + nodeName = lock.nodes.root.inputs.flake-compat; + in + fetchTarball { + url = + lock.nodes.${nodeName}.locked.url + or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.${nodeName}.locked.rev}.tar.gz"; + sha256 = lock.nodes.${nodeName}.locked.narHash; + } +) {src = ./.;}).defaultNix diff --git a/flake.lock b/flake.lock index 09aa0cd..5aff84f 100644 --- a/flake.lock +++ b/flake.lock @@ -1,20 +1,5 @@ { "nodes": { - "crane": { - "locked": { - "lastModified": 1748047550, - "narHash": "sha256-t0qLLqb4C1rdtiY8IFRH5KIapTY/n3Lqt57AmxEv9mk=", - "owner": "ipetkov", - "repo": "crane", - "rev": "b718a78696060df6280196a6f992d04c87a16aef", - "type": "github" - }, - "original": { - "owner": "ipetkov", - "repo": "crane", - "type": "github" - } - }, "flake-compat": { "locked": { "lastModified": 1747046372, @@ -30,24 +15,6 @@ "type": "github" } }, - "flake-parts": { - "inputs": { - "nixpkgs-lib": "nixpkgs-lib" - }, - "locked": { - "lastModified": 1743550720, - "narHash": "sha256-hIshGgKZCgWh6AYJpJmRgFdR3WUbkY04o82X05xqQiY=", - "owner": "hercules-ci", - "repo": "flake-parts", - "rev": "c621e8422220273271f52058f618c94e405bb0f5", - "type": "github" - }, - "original": { - "owner": "hercules-ci", - "repo": "flake-parts", - "type": "github" - } - }, "naersk": { "inputs": { "nixpkgs": "nixpkgs" @@ -66,6 +33,21 @@ "type": "github" } }, + "nix-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" + } + }, "nixpkgs": { "locked": { "lastModified": 1748662220, @@ -82,21 +64,6 @@ "type": "github" } }, - "nixpkgs-lib": { - "locked": { - "lastModified": 1743296961, - "narHash": "sha256-b1EdN3cULCqtorQ4QeWgLMrd5ZGOjLSLemfa00heasc=", - "owner": "nix-community", - "repo": "nixpkgs.lib", - "rev": "e4822aea2a6d1cdd36653c134cacfd64c97ff4fa", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "nixpkgs.lib", - "type": "github" - } - }, "nixpkgs_2": { "locked": { "lastModified": 1748460289, @@ -115,32 +82,10 @@ }, "root": { "inputs": { - "crane": "crane", "flake-compat": "flake-compat", - "flake-parts": "flake-parts", "naersk": "naersk", - "nixpkgs": "nixpkgs_2", - "rust-overlay": "rust-overlay" - } - }, - "rust-overlay": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1748658947, - "narHash": "sha256-F+nGITu6D7RswJlm8qCuU1PCuOSgDeAqaDKWW1n1jmQ=", - "owner": "oxalica", - "repo": "rust-overlay", - "rev": "fc82ce758cc5df6a6d5d24e75710321cdbdc787a", - "type": "github" - }, - "original": { - "owner": "oxalica", - "repo": "rust-overlay", - "type": "github" + "nix-systems": "nix-systems", + "nixpkgs": "nixpkgs_2" } } }, diff --git a/flake.nix b/flake.nix index 15ab0dd..5aa773a 100644 --- a/flake.nix +++ b/flake.nix @@ -3,135 +3,86 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; - flake-parts.url = "github:hercules-ci/flake-parts"; flake-compat.url = "github:edolstra/flake-compat"; - rust-overlay = { - url = "github:oxalica/rust-overlay"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - crane.url = "github:ipetkov/crane"; naersk.url = "github:nix-community/naersk"; + nix-systems.url = "github:nix-systems/default-linux"; }; - outputs = inputs @ { + outputs = { self, nixpkgs, - rust-overlay, - crane, naersk, - flake-parts, + nix-systems, ... - }: - flake-parts.lib.mkFlake {inherit inputs;} (let - mkRustToolchain = pkgs: - pkgs.rust-bin.stable.latest.default.override { - extensions = ["rust-src"]; - }; - in { - systems = [ - "aarch64-linux" - "x86_64-linux" - ]; - - imports = [ - ./nix/devshell.nix - ]; - - perSystem = { - system, - config, - pkgs, - lib, - ... - }: { - _module.args.pkgs = import nixpkgs { - inherit system; - overlays = [ - self.overlays.default - rust-overlay.overlays.default - ]; + }: let + forAllSystems = function: + nixpkgs.lib.genAttrs (import nix-systems) (system: function nixpkgs.legacyPackages.${system}); + mkDate = longDate: (nixpkgs.lib.concatStringsSep "-" [ + (builtins.substring 0 4 longDate) + (builtins.substring 4 2 longDate) + (builtins.substring 6 2 longDate) + ]); + in { + # Devshell + devShells = forAllSystems (pkgs: { + default = pkgs.mkShell { + packages = builtins.attrValues { + inherit + (pkgs) + cargo + clippy + rustfmt + gtk3 + gtk-layer-shell + gcc + openssl + libdbusmenu-gtk3 + libpulseaudio + libinput + libevdev + luajit + ; + inherit (pkgs.luajitPackages) lgi; }; - # Packages - packages = { - ironbar = pkgs.ironbar; - default = pkgs.ironbar; - }; - - # Apps - apps = { - ironbar = { - type = "app"; - program = lib.getExe pkgs.ironbar; - }; - default = config.apps.ironbar; - }; - }; - - flake = { - overlays.default = final: prev: let - inherit (nixpkgs) lib; - - rust = mkRustToolchain final; - - craneLib = (crane.mkLib final).overrideToolchain rust; - - naersk' = prev.callPackage naersk { - cargo = rust; - rustc = rust; - }; - - rustPlatform = prev.makeRustPlatform { - cargo = rust; - rustc = rust; - }; - - props = builtins.fromTOML (builtins.readFile ./Cargo.toml); - - mkDate = longDate: (lib.concatStringsSep "-" [ - (builtins.substring 0 4 longDate) - (builtins.substring 4 2 longDate) - (builtins.substring 6 2 longDate) - ]); - - builder = "naersk"; - in { - ironbar = let - version = - props.package.version - + "+date=" - + (mkDate (self.lastModifiedDate or "19700101")) - + "_" - + (self.shortRev or "dirty"); - in - if builder == "crane" - then - prev.callPackage ./nix/package.nix { - inherit version; - inherit rustPlatform; - builderName = builder; - builder = craneLib; - } - else if builder == "naersk" - then - prev.callPackage ./nix/package.nix { - inherit version; - inherit rustPlatform; - builderName = builder; - builder = naersk'; - } - else - prev.callPackage ./nix/package.nix { - inherit version; - inherit rustPlatform; - builderName = builder; - }; - }; - - homeManagerModules.default = import ./nix/module.nix self; + nativeBuildInputs = [ + pkgs.pkg-config + ]; }; }); + # Packages + packages = forAllSystems (pkgs: { + ironbar = let + props = builtins.fromTOML (builtins.readFile ./Cargo.toml); + version = + props.package.version + + "+date=" + + (mkDate (self.lastModifiedDate or "19700101")) + + "_" + + (self.shortRev or "dirty"); + naersk' = pkgs.callPackage naersk {}; + in + pkgs.callPackage ./nix/package.nix { + inherit version; + naersk = naersk'; + }; + + default = self.packages.${pkgs.hostPlatform.system}.ironbar; + }); + + # Apps + apps = forAllSystems (pkgs: { + ironbar = { + type = "app"; + program = pkgs.lib.getExe self.packages.${pkgs.hostPlatform.system}.ironbar; + }; + default = self.apps.ironbar; + }); + + homeManagerModules.default = import ./nix/module.nix self; + }; + nixConfig = { extra-substituters = ["https://cache.garnix.io"]; extra-trusted-public-keys = ["cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g="]; diff --git a/nix/devshell.nix b/nix/devshell.nix deleted file mode 100644 index 186f928..0000000 --- a/nix/devshell.nix +++ /dev/null @@ -1,25 +0,0 @@ -{ - perSystem = { pkgs, ... }: { - devShells.default = pkgs.mkShell { - packages = with pkgs; [ - cargo - clippy - rustfmt - gtk3 - gtk-layer-shell - gcc - openssl - libdbusmenu-gtk3 - libpulseaudio - libinput - libevdev - luajit - luajitPackages.lgi - ]; - - nativeBuildInputs = with pkgs; [ - pkg-config - ]; - }; - }; -} diff --git a/nix/module.nix b/nix/module.nix index 88582e5..a6753b7 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -7,57 +7,65 @@ self: { cfg = config.programs.ironbar; defaultIronbarPackage = self.packages.${pkgs.hostPlatform.system}.default; jsonFormat = pkgs.formats.json {}; + inherit + (lib) + types + mkOption + mkEnableOption + mkIf + getExe + ; in { options.programs.ironbar = { - enable = lib.mkEnableOption "ironbar status bar"; + enable = mkEnableOption "ironbar status bar"; - package = lib.mkOption { - type = with lib.types; package; + package = mkOption { + type = types.package; default = defaultIronbarPackage; apply = pkg: pkg.override {features = cfg.features;}; description = "The package for ironbar to use."; }; - systemd = lib.mkEnableOption "systemd service for ironbar."; + systemd = mkEnableOption "systemd service for ironbar."; - style = lib.mkOption { - type = lib.types.either (lib.types.lines) (lib.types.path); + style = mkOption { + type = types.either (types.lines) (types.path); default = ""; description = "The stylesheet to apply to ironbar."; }; - config = lib.mkOption { + config = mkOption { type = jsonFormat.type; default = {}; description = "The config to pass to ironbar."; }; - features = lib.mkOption { - type = lib.types.listOf lib.types.nonEmptyStr; + features = mkOption { + type = types.listOf types.nonEmptyStr; default = []; description = "The features to be used."; }; }; - config = lib.mkIf cfg.enable { + config = mkIf cfg.enable { home.packages = [ cfg.package ]; xdg.configFile = { - "ironbar/config.json" = lib.mkIf (cfg.config != "") { - onChange = "${lib.getExe cfg.package} reload"; + "ironbar/config.json" = mkIf (cfg.config != "") { + onChange = "${getExe cfg.package} reload"; source = jsonFormat.generate "ironbar-config" cfg.config; }; - "ironbar/style.css" = lib.mkIf (cfg.style != "") ( + "ironbar/style.css" = mkIf (cfg.style != "") ( if builtins.isPath cfg.style || lib.isStorePath cfg.style then {source = cfg.style;} else {text = cfg.style;} ); }; - systemd.user.services.ironbar = lib.mkIf cfg.systemd { + systemd.user.services.ironbar = mkIf cfg.systemd { Unit = { Description = "Systemd service for Ironbar"; Documentation = "https://github.com/JakeStanger/ironbar"; @@ -70,8 +78,8 @@ in { }; Service = { - ExecReload = "${lib.getExe cfg.package} reload"; - ExecStart = "${lib.getExe cfg.package}"; + ExecReload = "${getExe cfg.package} reload"; + ExecStart = "${getExe cfg.package}"; KillMode = "mixed"; Restart = "on-failure"; }; @@ -79,9 +87,9 @@ in { Install.WantedBy = [ config.wayland.systemd.target "tray.target" - (lib.mkIf config.wayland.windowManager.hyprland.enable "hyprland-session.target") - (lib.mkIf config.wayland.windowManager.sway.enable "sway-session.target") - (lib.mkIf config.wayland.windowManager.river.enable "river-session.target") + (mkIf config.wayland.windowManager.hyprland.enable "hyprland-session.target") + (mkIf config.wayland.windowManager.sway.enable "sway-session.target") + (mkIf config.wayland.windowManager.river.enable "river-session.target") ]; }; }; diff --git a/nix/package.nix b/nix/package.nix index c77b817..616c445 100644 --- a/nix/package.nix +++ b/nix/package.nix @@ -23,16 +23,44 @@ installShellFiles, adwaita-icon-theme, hicolor-icon-theme, - rustPlatform, lib, version ? "git", features ? [], - builderName ? "nix", - builder ? {}, + naersk, }: let hasFeature = f: features == [] || builtins.elem f features; + flags = let + noDefault = + if features == [] + then "" + else "--no-default-features"; - basePkg = rec { + featuresStr = + if features == [] + then "" + else ''-F "${builtins.concatStringsSep "," features}"''; + in [ + noDefault + featuresStr + ]; + lgi = luajitPackages.lgi; + gappsWrapperArgs = + '' + # Thumbnailers + --prefix XDG_DATA_DIRS : "${gdk-pixbuf}/share" + --prefix XDG_DATA_DIRS : "${librsvg}/share" + --prefix XDG_DATA_DIRS : "${webp-pixbuf-loader}/share" + --prefix XDG_DATA_DIRS : "${shared-mime-info}/share" + + # gtk-launch + --suffix PATH : "${lib.makeBinPath [gtk3]}" + '' + + lib.optionalString (hasFeature "cairo") '' + --prefix LUA_PATH : "./?.lua;${lgi}/share/lua/5.1/?.lua;${lgi}/share/lua/5.1/?/init.lua;${luajit}/share/lua/5.1/\?.lua;${luajit}/share/lua/5.1/?/init.lua" + --prefix LUA_CPATH : "./?.so;${lgi}/lib/lua/5.1/?.so;${luajit}/lib/lua/5.1/?.so;${luajit}/lib/lua/5.1/loadall.so" + ''; +in + naersk.buildPackage { inherit version; pname = "ironbar"; @@ -48,15 +76,18 @@ ideRelated = fs.unions [ (lib.path.append root ".idea") ]; - in fs.toSource { - inherit root; - # NOTE: can possibly filter out more - fileset = fs.difference root (fs.unions [ - nixRelated - cicdRelated - ideRelated - ]); - }; + in + fs.toSource { + inherit root; + # NOTE: can possibly filter out more + fileset = fs.difference root ( + fs.unions [ + nixRelated + cicdRelated + ideRelated + ] + ); + }; nativeBuildInputs = [ pkg-config @@ -82,27 +113,14 @@ ++ lib.optionals (hasFeature "tray") [libdbusmenu-gtk3] ++ lib.optionals (hasFeature "volume") [libpulseaudio] ++ lib.optionals (hasFeature "cairo") [luajit] - ++ lib.optionals (hasFeature "keyboard") [libinput libevdev]; + ++ lib.optionals (hasFeature "keyboard") [ + libinput + libevdev + ]; propagatedBuildInputs = [gtk3]; - lgi = luajitPackages.lgi; - - gappsWrapperArgs = - '' - # Thumbnailers - --prefix XDG_DATA_DIRS : "${gdk-pixbuf}/share" - --prefix XDG_DATA_DIRS : "${librsvg}/share" - --prefix XDG_DATA_DIRS : "${webp-pixbuf-loader}/share" - --prefix XDG_DATA_DIRS : "${shared-mime-info}/share" - - # gtk-launch - --suffix PATH : "${lib.makeBinPath [gtk3]}" - '' - + lib.optionalString (hasFeature "cairo") '' - --prefix LUA_PATH : "./?.lua;${lgi}/share/lua/5.1/?.lua;${lgi}/share/lua/5.1/?/init.lua;${luajit}/share/lua/5.1/\?.lua;${luajit}/share/lua/5.1/?/init.lua" - --prefix LUA_CPATH : "./?.so;${lgi}/lib/lua/5.1/?.so;${luajit}/lib/lua/5.1/?.so;${luajit}/lib/lua/5.1/loadall.so" - ''; + cargoBuildOptions = old: old ++ flags; preFixup = '' gappsWrapperArgs+=( @@ -119,48 +137,16 @@ passthru = { updateScript = gnome.updateScript { - packageName = pname; - attrPath = "gnome.${pname}"; + packageName = "ironbar"; + attrPath = "gnome.ironbar"; }; }; - meta = with lib; { + meta = { homepage = "https://github.com/JakeStanger/ironbar"; description = "Customisable gtk-layer-shell wlroots/sway bar written in rust."; - license = licenses.mit; - platforms = platforms.linux; + license = lib.licenses.mit; + platforms = lib.platforms.linux; mainProgram = "ironbar"; }; - }; - - flags = let - noDefault = - if features == [] - then "" - else "--no-default-features"; - - featuresStr = - if features == [] - then "" - else ''-F "${builtins.concatStringsSep "," features}"''; - in [noDefault featuresStr]; -in - if builderName == "naersk" - then builder.buildPackage (basePkg // {cargoBuildOptions = old: old ++ flags;}) - else if builderName == "crane" - then - builder.buildPackage (basePkg - // { - cargoExtraArgs = builtins.concatStringsSep " " flags; - doCheck = false; - }) - else - rustPlatform.buildRustPackage (basePkg - // { - buildNoDefaultFeatures = features != []; - - buildFeatures = features; - cargoDeps = rustPlatform.importCargoLock {lockFile = ../Cargo.lock;}; - cargoLock.lockFile = ../Cargo.lock; - cargoLock.outputHashes."stray-0.1.3" = "sha256-7mvsWZFmPWti9AiX67h6ZlWiVVRZRWIxq3pVaviOUtc="; - }) + } diff --git a/shell.nix b/shell.nix index ea7b69b..dc4e8cc 100644 --- a/shell.nix +++ b/shell.nix @@ -1,13 +1,12 @@ -(import - ( - let - lock = builtins.fromJSON (builtins.readFile ./flake.lock); - nodeName = lock.nodes.root.inputs.flake-compat; - in +(import ( + let + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + nodeName = lock.nodes.root.inputs.flake-compat; + in fetchTarball { - url = lock.nodes.${nodeName}.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.${nodeName}.locked.rev}.tar.gz"; + url = + lock.nodes.${nodeName}.locked.url + or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.${nodeName}.locked.rev}.tar.gz"; sha256 = lock.nodes.${nodeName}.locked.narHash; } - ) - { src = ./.; } -).shellNix +) {src = ./.;}).shellNix