From c57023b5673cf8a93add00f8dbdedc8e153c3f82 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Sun, 7 Jul 2024 23:00:24 -0700 Subject: [PATCH] Initial flake commit --- flake.lock | 23 +++++++++++++++++++++ flake.nix | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..404ff94 --- /dev/null +++ b/flake.lock @@ -0,0 +1,23 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 0, + "narHash": "sha256-vboIEwIQojofItm2xGCdZCzW96U85l9nDW3ifMuAIdM=", + "path": "/nix/store/wzx1ba5hqqfa23vfrvqmfmkpj25p37mr-source", + "type": "path" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..4fe1c01 --- /dev/null +++ b/flake.nix @@ -0,0 +1,59 @@ +{ + outputs = { self, nixpkgs, ... }: let + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; + inherit (builtins) genericClosure hasAttr length map; + inherit (pkgs) runCommandLocal writeText; + inherit (pkgs.lib) concatLines concatLists concatMap filter isDerivation isList mapAttrsToList; + in { + lib = rec { + drvOutputs = drv: + if hasAttr "outputs" drv + then map (output: drv.${output}) drv.outputs + else [ drv ]; + drvDeps = attrs: + mapAttrsToList (k: v: + if isDerivation v then (drvOutputs v) + else if isList v then concatMap drvOutputs (filter isDerivation v) + else [] + ) attrs; + wrap = drv: { key = drv.outPath; inherit drv; }; + buildtimeDerivations = drv0: genericClosure { + startSet = map wrap (drvOutputs drv0); + operator = obj: map wrap (concatLists (drvDeps obj.drv.drvAttrs)); + }; + drvMaintainers = drv: + if ! hasAttr "meta" drv then [] + else if ! hasAttr "maintainers" drv.meta then [] + else drv.meta.maintainers; + nobodyMaintains = drv: + if ! hasAttr "meta" drv then true + else if ! hasAttr "maintainers" drv.meta then true + else (length drv.meta.maintainers) == 0; + maintainerToString = m: "${m.name} (${m.email})"; + drvToString = drv: "${drv.name}"; + }; + bundlers."x86_64-linux" = with self.lib; { + maintainers = drv: let + deps = buildtimeDerivations drv; + drvs = map (dep: dep.drv) deps; + maintainers = concatMap drvMaintainers drvs; + maintainerNames = map maintainerToString maintainers; + maintainerNamesList = writeText "maintainers" (concatLines maintainerNames); + uniqNames = runCommandLocal "uniq-maintainers.txt" {} '' + <${maintainerNamesList} sort | uniq -c > $out + ''; + in uniqNames; + adopt = drv: let + deps = buildtimeDerivations drv; + drvs = map (dep: dep.drv) deps; + drvsNoMain = filter nobodyMaintains drvs; + drvNames = map drvToString drvsNoMain; + drvNamesList = writeText "no-maintainers" (concatLines drvNames); + uniqNames = runCommandLocal "no-maintainers.txt" {} '' + <${drvNamesList} sort | uniq -c > $out + ''; + in uniqNames; + }; + }; +}