From 7c7a3209ac08661beeca6c31222317de7361110a Mon Sep 17 00:00:00 2001 From: Sandro Date: Sun, 4 Feb 2024 15:41:39 +0100 Subject: [PATCH] Flake cleanup and make usable in a system configuration (#316) * Do not rely on the flake registry to resolve nixpkgs This can cause using the wrong nixpkgs if people have overwritten it locally * Misc cleanup * Migrate off deprecated defaultPackage/defaultApp * Don't install executable under $out/usr/bin If the flake is used in a system configuration then now executable gets linked and appears in PATH * Update flake.nix --------- Co-authored-by: b3nj5m1n <47924309+b3nj5m1n@users.noreply.github.com> --- flake.lock | 36 ++++++++++++++++++++++++++++-------- flake.nix | 27 +++++++++++---------------- 2 files changed, 39 insertions(+), 24 deletions(-) diff --git a/flake.lock b/flake.lock index 95146034..be5b7a89 100644 --- a/flake.lock +++ b/flake.lock @@ -1,12 +1,15 @@ { "nodes": { "flake-utils": { + "inputs": { + "systems": "systems" + }, "locked": { - "lastModified": 1676283394, - "narHash": "sha256-XX2f9c3iySLCw54rJ/CZs+ZK6IQy7GXNY4nSOyu2QG4=", + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", "owner": "numtide", "repo": "flake-utils", - "rev": "3db36a8b464d0c4532ba1c7dda728f4576d6d073", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", "type": "github" }, "original": { @@ -17,16 +20,18 @@ }, "nixpkgs": { "locked": { - "lastModified": 1678594102, - "narHash": "sha256-OHAHYiMWJFPNxuW/PcOMlSD2tvXnEYC1jxREBADHwwQ=", + "lastModified": 1695132891, + "narHash": "sha256-cJR9AFHmt816cW/C9necLJyOg/gsnkvEeFAfxgeM1hc=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "796b4a3c1d903c4b9270cd2548fe46f524eeb886", + "rev": "8b5ab8341e33322e5b66fb46ce23d724050f6606", "type": "github" }, "original": { - "id": "nixpkgs", - "type": "indirect" + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" } }, "root": { @@ -34,6 +39,21 @@ "flake-utils": "flake-utils", "nixpkgs": "nixpkgs" } + }, + "systems": { + "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 5a1be2c2..413dea57 100644 --- a/flake.nix +++ b/flake.nix @@ -1,6 +1,6 @@ { inputs = { - nixpkgs.url = "nixpkgs"; + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; flake-utils.url = "github:numtide/flake-utils"; }; outputs = { @@ -10,11 +10,6 @@ }: flake-utils.lib.eachDefaultSystem (system: let - runtimeDependencies = with pkgs; [ - glow - jq - findutils - ]; overlays = [ (self: super: { xdg-ninja = super.xdg-ninja.overrideAttrs (old: { @@ -25,9 +20,10 @@ ]; pkgs = import nixpkgs { inherit system overlays; }; in rec { - packages = flake-utils.lib.flattenTree { + packages = flake-utils.lib.flattenTree rec { + default = xdg-ninja; # The shell script and configurations, uses derivation from offical nixpkgs - xdg-ninja = pkgs.stdenv.mkDerivation rec { + xdg-ninja = pkgs.stdenv.mkDerivation { pname = "xdg-ninja"; version = "0.1.0"; @@ -38,10 +34,10 @@ installPhase = '' runHook preInstall - DESTDIR="$out" PREFIX="/usr" make install + DESTDIR="$out" PREFIX= make install - wrapProgram "$out/usr/bin/xdg-ninja" \ - --prefix PATH : "${pkgs.lib.makeBinPath [ pkgs.glow pkgs.jq ]}" + wrapProgram "$out/bin/xdg-ninja" \ + --prefix PATH : "${pkgs.lib.makeBinPath (with pkgs; [ glow jq findutils ])}" runHook postInstall ''; @@ -50,7 +46,6 @@ xdgnj-bin = pkgs.stdenvNoCC.mkDerivation { name = "xdgnj-bin"; version = "0.2.0.1-alpha"; - description = "Pre-built binary of the xdgnj tool for creating and editing configuration files for xdg-ninja."; src = pkgs.fetchurl { url = "https://github.com/b3nj5m1n/xdg-ninja/releases/download/v0.2.0.1/xdgnj"; sha256 = "y1BSqKQWbhCyg2sRgMsv8ivmylSUJj6XZ8o+/2oT5ns="; @@ -60,14 +55,14 @@ mkdir -p "$out/bin" install -Dm755 $src "$out/bin/xdgnj" ''; + meta.description = "Pre-built binary of the xdgnj tool for creating and editing configuration files for xdg-ninja."; }; }; - defaultPackage = packages.xdg-ninja; - apps = { - xdg-ninja = flake-utils.lib.mkApp { drv = packages.xdg-ninja; exePath = "/usr/bin/xdg-ninja"; }; + apps = rec { + default = xdg-ninja; + xdg-ninja = flake-utils.lib.mkApp { drv = packages.xdg-ninja; exePath = "/bin/xdg-ninja"; }; xdgnj-bin = flake-utils.lib.mkApp { drv = packages.xdgnj-bin; exePath = "/bin/xdgnj"; }; }; - defaultApp = apps.xdg-ninja; } ); }