From 7da9a17d4e7930dd486aca0fff0a29b656cb0e3e Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar <3998+srid@users.noreply.github.com> Date: Fri, 17 Oct 2025 07:54:28 -0400 Subject: [PATCH] Remove flake-parts dependency One less input in flake.lock --- flake.lock | 37 -------------- flake.nix | 140 +++++++++++++++++++++++++++-------------------------- 2 files changed, 71 insertions(+), 106 deletions(-) diff --git a/flake.lock b/flake.lock index 0f2060d..1b07d7c 100644 --- a/flake.lock +++ b/flake.lock @@ -1,44 +1,7 @@ { "nodes": { - "flake-parts": { - "inputs": { - "nixpkgs-lib": "nixpkgs-lib" - }, - "locked": { - "lastModified": 1693611461, - "narHash": "sha256-aPODl8vAgGQ0ZYFIRisxYG5MOGSkIczvu2Cd8Gb9+1Y=", - "owner": "hercules-ci", - "repo": "flake-parts", - "rev": "7f53fdb7bdc5bb237da7fefef12d099e4fd611ca", - "type": "github" - }, - "original": { - "owner": "hercules-ci", - "repo": "flake-parts", - "type": "github" - } - }, - "nixpkgs-lib": { - "locked": { - "dir": "lib", - "lastModified": 1693471703, - "narHash": "sha256-0l03ZBL8P1P6z8MaSDS/MvuU8E75rVxe5eE1N6gxeTo=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "3e52e76b70d5508f3cec70b882a29199f4d1ee85", - "type": "github" - }, - "original": { - "dir": "lib", - "owner": "NixOS", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, "root": { "inputs": { - "flake-parts": "flake-parts", "systems": "systems" } }, diff --git a/flake.nix b/flake.nix index e85739d..c14d903 100644 --- a/flake.nix +++ b/flake.nix @@ -1,82 +1,84 @@ { inputs = { - flake-parts.url = "github:hercules-ci/flake-parts"; # The systems to build for. If empty, build for current system. systems.url = "github:srid/empty"; flake = { }; }; outputs = inputs: - inputs.flake-parts.lib.mkFlake { inherit inputs; } { - systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ]; - perSystem = { self', pkgs, lib, system, ... }: { - _module.args.pkgs = import inputs.flake.inputs.nixpkgs { inherit system; }; - packages = - let - build-systems = - let systems = import inputs.systems; - in if systems == [ ] then [ system ] else systems; - shouldBuildOn = s: lib.elem s build-systems; - getSystem = cfg: - cfg.pkgs.stdenv.hostPlatform.system; - configForCurrentSystem = cfg: - shouldBuildOn (getSystem cfg); - # Given a flake output key, how to get the buildable derivation for - # any of its attr values? - flakeSchema = { - perSystem = { - # -> [ path ] - lookupFlake = k: flake: - lib.flip builtins.map build-systems (sys: - lib.attrByPath [ k sys ] { } flake - ); - getDrv = { - packages = _: x: [ x ]; - checks = _: x: [ x ]; - devShells = _: x: [ x ]; - apps = _: app: [ app.program ]; - legacyPackages = k: v: - if k == "homeConfigurations" - then - lib.mapAttrsToList (_: cfg: cfg.activationPackage) v - else [ ]; - }; - }; - flake = { - lookupFlake = k: flake: [ (lib.attrByPath [ k ] { } flake) ]; - getDrv = { - nixosConfigurations = _: cfg: - lib.optional (configForCurrentSystem cfg) cfg.config.system.build.toplevel; - darwinConfigurations = _: cfg: - lib.optional (configForCurrentSystem cfg) cfg.config.system.build.toplevel; - }; + let + allSystems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ]; + forAllSystems = f: builtins.listToAttrs (map (system: { name = system; value = f system; }) allSystems); + in + { + packages = forAllSystems (system: + let + pkgs = import inputs.flake.inputs.nixpkgs { inherit system; }; + lib = pkgs.lib; + build-systems = + let systems = import inputs.systems; + in if systems == [ ] then [ system ] else systems; + shouldBuildOn = s: lib.elem s build-systems; + getSystem = cfg: + cfg.pkgs.stdenv.hostPlatform.system; + configForCurrentSystem = cfg: + shouldBuildOn (getSystem cfg); + # Given a flake output key, how to get the buildable derivation for + # any of its attr values? + flakeSchema = { + perSystem = { + # -> [ path ] + lookupFlake = k: flake: + lib.flip builtins.map build-systems (sys: + lib.attrByPath [ k sys ] { } flake + ); + getDrv = { + packages = _: x: [ x ]; + checks = _: x: [ x ]; + devShells = _: x: [ x ]; + apps = _: app: [ app.program ]; + legacyPackages = k: v: + if k == "homeConfigurations" + then + lib.mapAttrsToList (_: cfg: cfg.activationPackage) v + else [ ]; }; }; - paths = - lib.flip lib.mapAttrsToList flakeSchema (_: lvlSchema: - lib.flip lib.mapAttrsToList lvlSchema.getDrv (kind: getDrv: - builtins.concatMap - (attr: lib.mapAttrsToList getDrv attr) - (lvlSchema.lookupFlake kind inputs.flake) - ) - ); - nameForStorePath = path: - if builtins.typeOf path == "set" - then path.pname or path.name or null - else null; - result = rec { - outPaths = lib.lists.flatten paths; - # Indexed by the path's unique name - # Paths without such a name will be ignored. Hence, you must rely on `out_paths` for comprehensive list of outputs. - byName = lib.foldl' (acc: path: - let name = nameForStorePath path; - in if name == null then acc else acc // { "${name}" = path; } - ) { } outPaths; + flake = { + lookupFlake = k: flake: [ (lib.attrByPath [ k ] { } flake) ]; + getDrv = { + nixosConfigurations = _: cfg: + lib.optional (configForCurrentSystem cfg) cfg.config.system.build.toplevel; + darwinConfigurations = _: cfg: + lib.optional (configForCurrentSystem cfg) cfg.config.system.build.toplevel; + }; }; - in - rec { - json = pkgs.writeText "devour-output.json" (builtins.toJSON result); - default = pkgs.writeText "devour-output" (lib.strings.concatLines result.outPaths); }; - }; + paths = + lib.flip lib.mapAttrsToList flakeSchema (_: lvlSchema: + lib.flip lib.mapAttrsToList lvlSchema.getDrv (kind: getDrv: + builtins.concatMap + (attr: lib.mapAttrsToList getDrv attr) + (lvlSchema.lookupFlake kind inputs.flake) + ) + ); + nameForStorePath = path: + if builtins.typeOf path == "set" + then path.pname or path.name or null + else null; + result = rec { + outPaths = lib.lists.flatten paths; + # Indexed by the path's unique name + # Paths without such a name will be ignored. Hence, you must rely on `out_paths` for comprehensive list of outputs. + byName = lib.foldl' (acc: path: + let name = nameForStorePath path; + in if name == null then acc else acc // { "${name}" = path; } + ) { } outPaths; + }; + in + rec { + json = pkgs.writeText "devour-output.json" (builtins.toJSON result); + default = pkgs.writeText "devour-output" (lib.strings.concatLines result.outPaths); + } + ); }; }