diff --git a/flake.lock b/flake.lock index 8002003..cde706f 100644 --- a/flake.lock +++ b/flake.lock @@ -1,9 +1,66 @@ { "nodes": { + "crane": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "nixpkgs": [ + "nixpkgs" + ], + "rust-overlay": "rust-overlay" + }, + "locked": { + "lastModified": 1688772518, + "narHash": "sha256-ol7gZxwvgLnxNSZwFTDJJ49xVY5teaSvF7lzlo3YQfM=", + "owner": "ipetkov", + "repo": "crane", + "rev": "8b08e96c9af8c6e3a2b69af5a7fa168750fcf88e", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flake-utils": { "inputs": { "systems": "systems" }, + "locked": { + "lastModified": 1687709756, + "narHash": "sha256-Y5wKlQSkgEK2weWdOu4J3riRd+kV/VCgHsqLNTTWQ/0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "dbabf0ca0c0c4bce6ea5eaf65af5cb694d2082c7", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, "locked": { "lastModified": 1681202837, "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", @@ -18,13 +75,44 @@ "type": "github" } }, + "naersk": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1688534083, + "narHash": "sha256-/bI5vsioXscQTsx+Hk9X5HfweeNZz/6kVKsbdqfwW7g=", + "owner": "nix-community", + "repo": "naersk", + "rev": "abca1fb7a6cfdd355231fc220c3d0302dbb4369a", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "naersk", + "type": "github" + } + }, "nixpkgs": { "locked": { - "lastModified": 1688049487, - "narHash": "sha256-100g4iaKC9MalDjUW9iN6Jl/OocTDtXdeAj7pEGIRh4=", + "lastModified": 1687412861, + "narHash": "sha256-Z/g0wbL68C+mSGerYS2quv9FXQ1RRP082cAC0Bh4vcs=", + "path": "/nix/store/s1z7nb9n6r5n0r34fabp6yybwkbr8mjk-source", + "rev": "e603dc5f061ca1d8a19b3ede6a8cf9c9fcba6cdc", + "type": "path" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1690179384, + "narHash": "sha256-+arbgqFTAtoeKtepW9wCnA0njCOyoiDFyl0Q0SBSOtE=", "owner": "nixos", "repo": "nixpkgs", - "rev": "4bc72cae107788bf3f24f30db2e2f685c9298dc9", + "rev": "b12803b6d90e2e583429bb79b859ca53c348b39a", "type": "github" }, "original": { @@ -36,23 +124,50 @@ }, "root": { "inputs": { - "nixpkgs": "nixpkgs", - "rust-overlay": "rust-overlay" + "crane": "crane", + "naersk": "naersk", + "nixpkgs": "nixpkgs_2", + "rust-overlay": "rust-overlay_2" } }, "rust-overlay": { "inputs": { - "flake-utils": "flake-utils", + "flake-utils": [ + "crane", + "flake-utils" + ], + "nixpkgs": [ + "crane", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1688351637, + "narHash": "sha256-CLTufJ29VxNOIZ8UTg0lepsn3X03AmopmaLTTeHDCL4=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "f9b92316727af9e6c7fee4a761242f7f46880329", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "rust-overlay_2": { + "inputs": { + "flake-utils": "flake-utils_2", "nixpkgs": [ "nixpkgs" ] }, "locked": { - "lastModified": 1688092301, - "narHash": "sha256-NTgT955DzXWVjHsuBn1t2K0x4hUghY7uE1jG2nGL5R4=", + "lastModified": 1690252178, + "narHash": "sha256-9oEz822bvbHobfCUjJLDor2BqW3I5tycIauzDlzOALY=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "4c31223801dd0f28ac15d60f2e5ddbd4d51ce17a", + "rev": "8d64353ca827002fb8459e44d49116c78d868eba", "type": "github" }, "original": { @@ -75,6 +190,21 @@ "repo": "default", "type": "github" } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 3ce3dee..5097350 100644 --- a/flake.nix +++ b/flake.nix @@ -6,11 +6,18 @@ url = "github:oxalica/rust-overlay"; inputs.nixpkgs.follows = "nixpkgs"; }; + crane = { + url = "github:ipetkov/crane"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + naersk.url = "github:nix-community/naersk"; }; outputs = { self, nixpkgs, rust-overlay, + crane, + naersk, ... }: let inherit (nixpkgs) lib; @@ -31,6 +38,11 @@ in { overlays.default = final: prev: let rust = mkRustToolchain final; + craneLib = (crane.mkLib final).overrideToolchain rust; + naersk' = prev.callPackage naersk { + cargo = rust; + rustc = rust; + }; rustPlatform = prev.makeRustPlatform { cargo = rust; @@ -42,11 +54,33 @@ (builtins.substring 4 2 longDate) (builtins.substring 6 2 longDate) ]); + builder = "naersk"; in { - ironbar = prev.callPackage ./nix/default.nix { + ironbar = let version = props.package.version + "+date=" + (mkDate (self.lastModifiedDate or "19700101")) + "_" + (self.shortRev or "dirty"); - inherit rustPlatform; - }; + in + if builder == "crane" + then + prev.callPackage ./nix/default.nix { + inherit version; + inherit rustPlatform; + builderName = builder; + builder = craneLib; + } + else if builder == "naersk" + then + prev.callPackage ./nix/default.nix { + inherit version; + inherit rustPlatform; + builderName = builder; + builder = naersk'; + } + else + prev.callPackage ./nix/default.nix { + inherit version; + inherit rustPlatform; + builderName = builder; + }; }; packages = genSystems ( system: let diff --git a/nix/default.nix b/nix/default.nix index 238ef46..731e7ac 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -19,49 +19,77 @@ lib, version ? "git", features ? [], -}: -rustPlatform.buildRustPackage rec { - inherit version; - pname = "ironbar"; - src = builtins.path { - name = "ironbar"; - path = lib.cleanSource ../.; - }; - buildNoDefaultFeatures = - if features == [] - then false - else true; - buildFeatures = features; - cargoDeps = rustPlatform.importCargoLock { - lockFile = ../Cargo.lock; - }; - cargoLock.lockFile = ../Cargo.lock; - cargoLock.outputHashes."stray-0.1.3" = "sha256-7mvsWZFmPWti9AiX67h6ZlWiVVRZRWIxq3pVaviOUtc="; - nativeBuildInputs = [pkg-config wrapGAppsHook gobject-introspection]; - buildInputs = [gtk3 gdk-pixbuf glib gtk-layer-shell glib-networking shared-mime-info gnome.adwaita-icon-theme hicolor-icon-theme gsettings-desktop-schemas libxkbcommon openssl]; - propagatedBuildInputs = [ - gtk3 - ]; - preFixup = '' - 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" - ) - ''; - passthru = { - updateScript = gnome.updateScript { - packageName = pname; - attrPath = "gnome.${pname}"; + builderName ? "nix", + builder ? {}, +}: let + basePkg = rec { + inherit version; + pname = "ironbar"; + src = builtins.path { + name = "ironbar"; + path = lib.cleanSource ../.; + }; + nativeBuildInputs = [pkg-config wrapGAppsHook gobject-introspection]; + buildInputs = [gtk3 gdk-pixbuf glib gtk-layer-shell glib-networking shared-mime-info gnome.adwaita-icon-theme hicolor-icon-theme gsettings-desktop-schemas libxkbcommon openssl]; + propagatedBuildInputs = [ + gtk3 + ]; + preFixup = '' + 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" + ) + ''; + passthru = { + updateScript = gnome.updateScript { + packageName = pname; + attrPath = "gnome.${pname}"; + }; + }; + meta = with lib; { + homepage = "https://github.com/JakeStanger/ironbar"; + description = "Customisable gtk-layer-shell wlroots/sway bar written in rust."; + license = licenses.mit; + platforms = platforms.linux; + mainProgram = "ironbar"; }; }; - meta = with lib; { - homepage = "https://github.com/JakeStanger/ironbar"; - description = "Customisable gtk-layer-shell wlroots/sway bar written in rust."; - license = licenses.mit; - platforms = 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 + // { + cargoOptions = old: old ++ flags; + }) + else if builderName == "crane" + then + builder.buildPackage (basePkg + // { + cargoExtraArgs = builtins.concatStringsSep " " flags; + doCheck = false; + }) + else + rustPlatform.buildRustPackage (basePkg + // { + buildNoDefaultFeatures = + if features == [] + then false + else true; + buildFeatures = features; + cargoDeps = rustPlatform.importCargoLock {lockFile = ../Cargo.lock;}; + cargoLock.lockFile = ../Cargo.lock; + cargoLock.outputHashes."stray-0.1.3" = "sha256-7mvsWZFmPWti9AiX67h6ZlWiVVRZRWIxq3pVaviOUtc="; + })