{"id":13688092,"url":"https://github.com/jonringer/flake-v2","last_synced_at":"2025-11-07T14:30:27.230Z","repository":{"id":248307479,"uuid":"801355862","full_name":"jonringer/flake-v2","owner":"jonringer","description":"What flakes should have been","archived":false,"fork":false,"pushed_at":"2024-07-13T20:57:32.000Z","size":6,"stargazers_count":20,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-12-27T22:19:09.150Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonringer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-16T04:32:26.000Z","updated_at":"2024-10-02T19:19:10.000Z","dependencies_parsed_at":"2024-07-13T21:45:23.392Z","dependency_job_id":"af41f332-0399-450e-b95c-a08f9beba782","html_url":"https://github.com/jonringer/flake-v2","commit_stats":null,"previous_names":["jonringer/flake-v2"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonringer%2Fflake-v2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonringer%2Fflake-v2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonringer%2Fflake-v2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonringer%2Fflake-v2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonringer","download_url":"https://codeload.github.com/jonringer/flake-v2/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239533066,"owners_count":19654617,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T15:01:06.491Z","updated_at":"2025-11-07T14:30:27.170Z","avatar_url":"https://github.com/jonringer.png","language":null,"funding_links":[],"categories":["Others"],"sub_categories":[],"readme":"## Flake Schema redefined\n\nThis document is to propose a less awkward way to do flake evaluation.\n\n### Current problems with existing flake schema\n\n- Embedded system in attr paths (e.g. `packages.x86_64-linux.default`)\n- Hard to combine non-system specific items with system specific items (e.g. overlays vs packages)\n- \"Diamond dependency issues\" when bringing libraries from many flakes (each has an opinionated dependency tree)\n\n## Proposed Solution\n\n- Make overlays a hard requirement for composition\n- Split up outputs, some specific to a system, and other are more generalized (e.g. overlays, NixOS modules)\n\n## Example potential flake structure.\n\n```nix\n{\n\n  description = \"Example better flake\";\n\n  inputs = {\n    nixpkgs.url = \"github:nixos/nixpkgs/unstable\";\n  };\n\n  overlays = {\n    default = import ./nix/overlay.nix;\n  };\n\n  # Attrset of modules\n  nixosModules = import ./nixos;\n\n  nixosConfigurations = { self }: {\n    default = self.inputs.nixpkgs.lib.nixosSystem {\n      modules = [ self.nixosModules.default ];\n    };\n  };\n\n  pkgsConfig = { allowUnfree = true; cudaSupport = true; };\n  pkgsOverlays = { self, overlays }: [\n    self.inputs.foo.overlays.default\n    self.overlays.default\n  ];\n\n  # Optional explicit import of nixpkgs, allows for further customization\n  pkgsForSystem = { self, system }:\n    import self.inputs.nixpkgs {\n      inherit system;\n      config = self.pkgsConfig;\n      overlays = self.pkgsOverlays;\n    };\n\n  outputs = { pkgs, ... }: with pkgs; {\n    formatter = nixpkgs-fmt;\n\n    checks.default = myPackage;\n\n    packages.default = myPackage;\n\n    # Instead of using { type = app; program = \u003cstore path\u003e;}, just use \u003cstore path\u003e\n    app.default = myPackage;\n    app.other = \"${myPackage}/bin/other-bin\";\n\n    devShells.default = mkShell {\n      inputsFrom = [\n        myPackage\n      ];\n      nativeBuildInputs = [\n        cmake-lint\n      ] ++ pkgs.lib.optionals stdenv.isLinux [\n        gdb\n      ];\n    };\n  };\n\n  # These can just import a whole directory from a path\n  templates.default = ./templates/default;\n}\n```\n\n## Minimal Example\n```nix\n{\n  description = \"Minimal better flake\";\n\n  inputs.nixpkgs.url = \"github:nixos/nixpkgs/unstable\";\n\n  # Overlay defines myPackage\n  overlays.default = final: prev: {\n    myPackage = final.callPackage ./package.nix { };\n  };\n\n  outputs = { pkgs }: with pkgs; {\n    packages.default = myPackage;\n    devShells.default = mkShell { inputsFrom = [ myPackage ]; };\n  };\n}\n```\n\nThe evaluation of these results would roughly be:\n```nix\n# The ? here is that these could be optionally imported if defined\nflake = let\n  # Initial import with unknown attrs defined, inputs would also need to be resolved as part of this \"import\"\n  raw = import ./flake.nix;\n  # Evaluate enough to get a nixpkgs import\n  pkgsConfig = if raw ? pkgsConfig then pkgsConfig { self = raw; } else { };\n  pkgsOverlays = if raw ? pkgsOverlays then pkgsOverlays { self = raw; } else [ ];\n  # Replace pkgsConfig and pkgsOverlays functions with their arguments applied results\n  callRawFlake = callPackageWith (raw // { inherit pkgsConfig pkgsOverlays; self = raw; });\n\n  mkFlake = {\n    self,\n    pkgsConfig,\n    pkgsOverlays,\n    # Could be defined by user, but if not, do an expected import\n    pkgsForSystem ? { self, system }: import self.inputs.nixpkgs { config = pkgsConfig; overlays = pkgsOverlays;);\n  }: let\n    pkgs = pkgsForSystem { inherit self; system = builtins.getCurrentSystem; };\n    # TODO: nixosConfigurations and other attrs would optinally need to be called if they're functions and present\n  in raw.outputs pkgs // { inherit pkgsConfig pkgsOverlays; };\n\n  # Create self fixed point, and pass as flake output\n  final = raw // (callRawFlake mkFlake) // { self = final; };\nin\n  final\n```\n\nTo change the system, usage of the --system argument would be made\n```bash\nnix eval --system aarch64-linux .#myPackages.drvPath\n```\n\n### How were the problems solved?\n\n- Embedded system in attr paths (e.g. `packages.x86_64-linux.default`)\n  - Make system selection implicit in the structure, passed through --system flag\n- Hard to combine non-system specific items with system specific items (e.g. overlays vs packages)\n  - non-system specific items now have their own dedicated top-level attribute.\n- \"Diamond dependency issues\" when bringing libraries from many flakes (each has an opinionated dependency tree)\n  - Usage of overlays to give a single pkgs instance avoids the \"1,000 glibc\" and diamnond dependency issues.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonringer%2Fflake-v2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonringer%2Fflake-v2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonringer%2Fflake-v2/lists"}