diff --git a/default.nix b/default.nix index 3fc972bc..d5145f2a 100644 --- a/default.nix +++ b/default.nix @@ -4,7 +4,7 @@ let import ( let - lock = builtins.fromJSON (builtins.readFile ./flake.lock); + lock = builtins.fromJSON (builtins.readFile ./dev-flake/flake.lock); in fetchTarball { url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; @@ -14,3 +14,8 @@ let {src = ./.;}; in flake.defaultNix + # allow overriding inputs + // { + __functor = defaultNix: inputs: defaultNix.overrideInputs inputs; + } + diff --git a/modules/default.nix b/dev-flake/default.nix similarity index 88% rename from modules/default.nix rename to dev-flake/default.nix index 94ad99c9..3fc972bc 100644 --- a/modules/default.nix +++ b/dev-flake/default.nix @@ -1,5 +1,5 @@ # This file provides backward compatibility to nix < 2.4 clients -inputs: let +let flake = import ( @@ -13,4 +13,4 @@ inputs: let ) {src = ./.;}; in - flake.defaultNix.overrideInputs inputs + flake.defaultNix diff --git a/dev-flake/flake.lock b/dev-flake/flake.lock new file mode 100644 index 00000000..25a7aaa5 --- /dev/null +++ b/dev-flake/flake.lock @@ -0,0 +1,205 @@ +{ + "nodes": { + "devshell": { + "flake": false, + "locked": { + "lastModified": 1663445644, + "narHash": "sha256-+xVlcK60x7VY1vRJbNUEAHi17ZuoQxAIH4S4iUFUGBA=", + "owner": "numtide", + "repo": "devshell", + "rev": "e3dc3e21594fe07bdb24bdf1c8657acaa4cb8f66", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1695612854, + "narHash": "sha256-QPe1fENhAB4l/N04FulgItq1rfcpQMttGZzikV7h3iI=", + "owner": "nix-community", + "repo": "flake-compat", + "rev": "ad8d6af6aa8a14851a60bd00927f42b9798544ea", + "type": "github" + }, + "original": { + "owner": "nix-community", + "ref": "pull/4/head", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1675933616, + "narHash": "sha256-/rczJkJHtx16IFxMmAWu5nNYcSXNg1YYXTHoGjLrLUA=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "47478a4a003e745402acf63be7f9a092d51b83d7", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1689068808, + "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nix-github-actions": { + "inputs": { + "nixpkgs": [ + "nix-unit", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1688870561, + "narHash": "sha256-4UYkifnPEw1nAzqqPOTL2MvWtm3sNGw1UTYTalkTcGY=", + "owner": "nix-community", + "repo": "nix-github-actions", + "rev": "165b1650b753316aa7f1787f3005a8d2da0f5301", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nix-github-actions", + "type": "github" + } + }, + "nix-unit": { + "inputs": { + "flake-parts": [ + "flake-parts" + ], + "nix-github-actions": "nix-github-actions", + "nixpkgs": [ + "nixpkgs" + ], + "treefmt-nix": "treefmt-nix" + }, + "locked": { + "lastModified": 1694670962, + "narHash": "sha256-HvMq0TJGYSx37zHm4j2d+JUZx4/6X7xKEt/0DeCiwjQ=", + "owner": "adisbladis", + "repo": "nix-unit", + "rev": "3ed2378bddad85257fc508a291408f9ed9673d01", + "type": "github" + }, + "original": { + "owner": "adisbladis", + "repo": "nix-unit", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1696604326, + "narHash": "sha256-YXUNI0kLEcI5g8lqGMb0nh67fY9f2YoJsILafh6zlMo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "87828a0e03d1418e848d3dd3f3014a632e4a4f64", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-unstable", + "type": "indirect" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1646153636, + "narHash": "sha256-AlWHMzK+xJ1mG267FdT8dCq/HvLCA6jwmx2ZUy5O8tY=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "b6bc0b21e1617e2b07d8205e7fae7224036dfa4b", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "devshell": "devshell", + "flake-compat": "flake-compat", + "flake-parts": "flake-parts", + "nix-unit": "nix-unit", + "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "nix-unit", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1689620039, + "narHash": "sha256-BtNwghr05z7k5YMdq+6nbue+nEalvDepuA7qdQMAKoQ=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "719c2977f958c41fa60a928e2fbc50af14844114", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/dev-flake/flake.nix b/dev-flake/flake.nix new file mode 100644 index 00000000..531a050b --- /dev/null +++ b/dev-flake/flake.nix @@ -0,0 +1,51 @@ +{ + description = "Flake containing inputs/outputs not intended for overriding by the end-user"; + + nixConfig = { + extra-trusted-public-keys = "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="; + extra-substituters = "https://nix-community.cachix.org"; + }; + + inputs = { + nixpkgs.url = "nixpkgs/nixos-unstable"; + + flake-parts.url = "github:hercules-ci/flake-parts"; + flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs"; + + flake-compat.url = "github:nix-community/flake-compat/pull/4/head"; + flake-compat.flake = false; + + pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix"; + pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs"; + + nix-unit.url = "github:adisbladis/nix-unit"; + nix-unit.inputs.nixpkgs.follows = "nixpkgs"; + nix-unit.inputs.flake-parts.follows = "flake-parts"; + + devshell = { + url = "github:numtide/devshell"; + flake = false; + }; + }; + + outputs = { + self, + devshell, + flake-parts, + nixpkgs, + pre-commit-hooks, + ... + } @ inputs: + flake-parts.lib.mkFlake {inherit inputs;} { + imports = [ + ../modules/flake-parts/all-modules.nix + ../pkgs/fetchPipMetadata/flake-module.nix + ]; + systems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + }; +} diff --git a/examples/repo-flake-pdm/flake.nix b/examples/repo-flake-pdm/flake.nix index aa7bfd78..9586e30f 100644 --- a/examples/repo-flake-pdm/flake.nix +++ b/examples/repo-flake-pdm/flake.nix @@ -2,7 +2,7 @@ description = "My flake with dream2nix packages"; inputs = { - dream2nix.url = "github:nix-community/dream2nix?dir=modules"; + dream2nix.url = "github:nix-community/dream2nix"; nixpkgs.follows = "dream2nix/nixpkgs"; }; diff --git a/examples/repo/default.nix b/examples/repo/default.nix index 1edac055..1724ff8b 100644 --- a/examples/repo/default.nix +++ b/examples/repo/default.nix @@ -4,9 +4,9 @@ url = "https://github.com/nix-community/dream2nix/tarball/main"; # sha256 = ""; }, - pkgs ? import (import dream2nixSource).inputs.nixpkgs {}, + pkgs ? import (import dream2nixSource {}).inputs.nixpkgs {}, }: let - dream2nix = import dream2nixSource; + dream2nix = import dream2nixSource {}; # all packages defined inside ./packages/ packages = dream2nix.lib.importPackages { projectRoot = ./.; diff --git a/flake-compat.nix b/flake-compat.nix deleted file mode 100644 index f994e9e2..00000000 --- a/flake-compat.nix +++ /dev/null @@ -1,298 +0,0 @@ -# Compatibility function to allow flakes to be used by -# non-flake-enabled Nix versions. Given a source tree containing a -# 'flake.nix' and 'flake.lock' file, it fetches the flake inputs and -# calls the flake's 'outputs' function. It then returns an attrset -# containing 'defaultNix' (to be used in 'default.nix'), 'shellNix' -# (to be used in 'shell.nix'). -{ - src, - system ? builtins.currentSystem or "unknown-system", -}: let - lockFilePath = src + "/flake.lock"; - - lockFile = builtins.fromJSON (builtins.readFile lockFilePath); - - fetchTree = info: - if info.type == "github" - then { - outPath = - fetchTarball - ( - {url = "https://api.${info.host or "github.com"}/repos/${info.owner}/${info.repo}/tarball/${info.rev}";} - // ( - if info ? narHash - then {sha256 = info.narHash;} - else {} - ) - ); - rev = info.rev; - shortRev = builtins.substring 0 7 info.rev; - lastModified = info.lastModified; - lastModifiedDate = formatSecondsSinceEpoch info.lastModified; - narHash = info.narHash; - } - else if info.type == "git" - then - { - outPath = - builtins.fetchGit - ( - {url = info.url;} - // ( - if info ? rev - then {inherit (info) rev;} - else {} - ) - // ( - if info ? ref - then {inherit (info) ref;} - else {} - ) - // ( - if info ? submodules - then {inherit (info) submodules;} - else {} - ) - ); - lastModified = info.lastModified; - lastModifiedDate = formatSecondsSinceEpoch info.lastModified; - narHash = info.narHash; - } - // ( - if info ? rev - then { - rev = info.rev; - shortRev = builtins.substring 0 7 info.rev; - } - else { - } - ) - else if info.type == "path" - then { - outPath = builtins.path {path = info.path;}; - narHash = info.narHash; - } - else if info.type == "tarball" - then { - outPath = - fetchTarball - ( - {inherit (info) url;} - // ( - if info ? narHash - then {sha256 = info.narHash;} - else {} - ) - ); - } - else if info.type == "gitlab" - then { - inherit (info) rev narHash lastModified; - outPath = - fetchTarball - ( - {url = "https://${info.host or "gitlab.com"}/api/v4/projects/${info.owner}%2F${info.repo}/repository/archive.tar.gz?sha=${info.rev}";} - // ( - if info ? narHash - then {sha256 = info.narHash;} - else {} - ) - ); - shortRev = builtins.substring 0 7 info.rev; - } - else - # FIXME: add Mercurial, tarball inputs. - throw "flake input has unsupported input type '${info.type}'"; - - callFlake4 = flakeSrc: locks: let - flake = import (flakeSrc + "/flake.nix"); - - inputs = builtins.mapAttrs (n: v: - if v.flake or true - then callFlake4 (fetchTree (v.locked // v.info)) v.inputs - else fetchTree (v.locked // v.info)) - locks; - - outputs = flakeSrc // (flake.outputs (inputs // {self = outputs;})); - in - assert flake.edition == 201909; outputs; - - callLocklessFlake = flakeSrc: let - flake = import (flakeSrc + "/flake.nix"); - outputs = flakeSrc // (flake.outputs {self = outputs;}); - in - outputs; - - rootSrc = let - # Try to clean the source tree by using fetchGit, if this source - # tree is a valid git repository. - tryFetchGit = src: - if isGit && !isShallow - then let - res = builtins.fetchGit src; - in - if res.rev == "0000000000000000000000000000000000000000" - then removeAttrs res ["rev" "shortRev"] - else res - else {outPath = src;}; - # NB git worktrees have a file for .git, so we don't check the type of .git - isGit = builtins.pathExists (src + "/.git"); - isShallow = builtins.pathExists (src + "/.git/shallow"); - in - { - lastModified = 0; - lastModifiedDate = formatSecondsSinceEpoch 0; - } - // ( - if src ? outPath - then src - else tryFetchGit src - ); - - # Format number of seconds in the Unix epoch as %Y%m%d%H%M%S. - formatSecondsSinceEpoch = t: let - rem = x: y: x - x / y * y; - days = t / 86400; - secondsInDay = rem t 86400; - hours = secondsInDay / 3600; - minutes = (rem secondsInDay 3600) / 60; - seconds = rem t 60; - - # Courtesy of https://stackoverflow.com/a/32158604. - z = days + 719468; - era = - ( - if z >= 0 - then z - else z - 146096 - ) - / 146097; - doe = z - era * 146097; - yoe = (doe - doe / 1460 + doe / 36524 - doe / 146096) / 365; - y = yoe + era * 400; - doy = doe - (365 * yoe + yoe / 4 - yoe / 100); - mp = (5 * doy + 2) / 153; - d = doy - (153 * mp + 2) / 5 + 1; - m = - mp - + ( - if mp < 10 - then 3 - else -9 - ); - y' = - y - + ( - if m <= 2 - then 1 - else 0 - ); - - pad = s: - if builtins.stringLength s < 2 - then "0" + s - else s; - in "${toString y'}${pad (toString m)}${pad (toString d)}${pad (toString hours)}${pad (toString minutes)}${pad (toString seconds)}"; - - allNodes = - builtins.mapAttrs - ( - key: node: let - sourceInfo = - if key == lockFile.root - then rootSrc - else fetchTree (node.info or {} // removeAttrs node.locked ["dir"]); - - subdir = - if key == lockFile.root - then "" - else node.locked.dir or ""; - - flake = import (sourceInfo - + ( - if subdir != "" - then "/" - else "" - ) - + subdir - + "/flake.nix"); - - inputs = - builtins.mapAttrs - (inputName: inputSpec: allNodes.${resolveInput inputSpec}) - (node.inputs or {}); - - # Resolve a input spec into a node name. An input spec is - # either a node name, or a 'follows' path from the root - # node. - resolveInput = inputSpec: - if builtins.isList inputSpec - then getInputByPath lockFile.root inputSpec - else inputSpec; - - # Follow an input path (e.g. ["dwarffs" "nixpkgs"]) from the - # root node, returning the final node. - getInputByPath = nodeName: path: - if path == [] - then nodeName - else - getInputByPath - # Since this could be a 'follows' input, call resolveInput. - (resolveInput lockFile.nodes.${nodeName}.inputs.${builtins.head path}) - (builtins.tail path); - - outputs = flake.outputs (inputs // {self = result;}); - - result = - outputs - // sourceInfo - // { - inherit inputs; - inherit outputs; - inherit sourceInfo; - }; - in - if node.flake or true - then assert builtins.isFunction flake.outputs; result - else sourceInfo - ) - lockFile.nodes; - - result = - if !(builtins.pathExists lockFilePath) - then callLocklessFlake rootSrc - else if lockFile.version == 4 - then callFlake4 rootSrc (lockFile.inputs) - else if lockFile.version >= 5 && lockFile.version <= 7 - then allNodes.${lockFile.root} - else throw "lock file '${lockFilePath}' has unsupported version ${toString lockFile.version}"; -in rec { - # expose flake inputs - inherit (result) inputs; - - defaultNix = - result - // ( - if result ? defaultPackage.${system} - then {default = result.defaultPackage.${system};} - else {} - ) - // ( - if result ? packages.${system}.default - then {default = result.packages.${system}.default;} - else {} - ); - - shellNix = - defaultNix - // ( - if result ? devShell.${system} - then {default = result.devShell.${system};} - else {} - ) - // ( - if result ? devShells.${system}.default - then {default = result.devShells.${system}.default;} - else {} - ); -} diff --git a/flake.lock b/flake.lock index f3f0aed0..0f74258c 100644 --- a/flake.lock +++ b/flake.lock @@ -1,200 +1,83 @@ { "nodes": { - "devshell": { - "flake": false, - "locked": { - "lastModified": 1663445644, - "narHash": "sha256-+xVlcK60x7VY1vRJbNUEAHi17ZuoQxAIH4S4iUFUGBA=", - "owner": "numtide", - "repo": "devshell", - "rev": "e3dc3e21594fe07bdb24bdf1c8657acaa4cb8f66", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "devshell", - "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-parts": { - "inputs": { - "nixpkgs-lib": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1675933616, - "narHash": "sha256-/rczJkJHtx16IFxMmAWu5nNYcSXNg1YYXTHoGjLrLUA=", - "owner": "hercules-ci", - "repo": "flake-parts", - "rev": "47478a4a003e745402acf63be7f9a092d51b83d7", - "type": "github" - }, - "original": { - "owner": "hercules-ci", - "repo": "flake-parts", - "type": "github" - } - }, - "flake-utils": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1689068808, - "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "nix-github-actions": { - "inputs": { - "nixpkgs": [ - "nix-unit", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1688870561, - "narHash": "sha256-4UYkifnPEw1nAzqqPOTL2MvWtm3sNGw1UTYTalkTcGY=", - "owner": "nix-community", - "repo": "nix-github-actions", - "rev": "165b1650b753316aa7f1787f3005a8d2da0f5301", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "nix-github-actions", - "type": "github" - } - }, - "nix-unit": { - "inputs": { - "flake-parts": [ - "flake-parts" - ], - "nix-github-actions": "nix-github-actions", - "nixpkgs": [ - "nixpkgs" - ], - "treefmt-nix": "treefmt-nix" - }, - "locked": { - "lastModified": 1694670962, - "narHash": "sha256-HvMq0TJGYSx37zHm4j2d+JUZx4/6X7xKEt/0DeCiwjQ=", - "owner": "adisbladis", - "repo": "nix-unit", - "rev": "3ed2378bddad85257fc508a291408f9ed9673d01", - "type": "github" - }, - "original": { - "owner": "adisbladis", - "repo": "nix-unit", - "type": "github" - } - }, "nixpkgs": { "locked": { - "lastModified": 1696604326, - "narHash": "sha256-YXUNI0kLEcI5g8lqGMb0nh67fY9f2YoJsILafh6zlMo=", + "lastModified": 1695837737, + "narHash": "sha256-KcqmJ5hNacLuE7fkz5586kp/vt4NLo6+Prq3DMgrxpQ=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "87828a0e03d1418e848d3dd3f3014a632e4a4f64", + "rev": "517501bcf14ae6ec47efd6a17dda0ca8e6d866f9", "type": "github" }, "original": { - "id": "nixpkgs", - "ref": "nixos-unstable", - "type": "indirect" + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" } }, - "pre-commit-hooks": { + "purescript-overlay": { "inputs": { - "flake-utils": "flake-utils", "nixpkgs": [ "nixpkgs" - ] + ], + "slimlock": "slimlock" }, "locked": { - "lastModified": 1646153636, - "narHash": "sha256-AlWHMzK+xJ1mG267FdT8dCq/HvLCA6jwmx2ZUy5O8tY=", - "owner": "cachix", - "repo": "pre-commit-hooks.nix", - "rev": "b6bc0b21e1617e2b07d8205e7fae7224036dfa4b", + "lastModified": 1696022621, + "narHash": "sha256-eMjFmsj2G1E0Q5XiibUNgFjTiSz0GxIeSSzzVdoN730=", + "owner": "thomashoneyman", + "repo": "purescript-overlay", + "rev": "047c7933abd6da8aa239904422e22d190ce55ead", "type": "github" }, "original": { - "owner": "cachix", - "repo": "pre-commit-hooks.nix", + "owner": "thomashoneyman", + "repo": "purescript-overlay", + "type": "github" + } + }, + "pyproject-nix": { + "flake": false, + "locked": { + "lastModified": 1694075710, + "narHash": "sha256-B2EzHfVwk6RlW6KGXh/85DkffI8QIaD7ugm119Xz5Hs=", + "owner": "adisbladis", + "repo": "pyproject.nix", + "rev": "c66dab8e7bce2a13c10baeebfe8fe63c51df62c3", + "type": "github" + }, + "original": { + "owner": "adisbladis", + "repo": "pyproject.nix", "type": "github" } }, "root": { "inputs": { - "devshell": "devshell", - "flake-compat": "flake-compat", - "flake-parts": "flake-parts", - "nix-unit": "nix-unit", "nixpkgs": "nixpkgs", - "pre-commit-hooks": "pre-commit-hooks" + "purescript-overlay": "purescript-overlay", + "pyproject-nix": "pyproject-nix" } }, - "systems": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } - }, - "treefmt-nix": { + "slimlock": { "inputs": { "nixpkgs": [ - "nix-unit", + "purescript-overlay", "nixpkgs" ] }, "locked": { - "lastModified": 1689620039, - "narHash": "sha256-BtNwghr05z7k5YMdq+6nbue+nEalvDepuA7qdQMAKoQ=", - "owner": "numtide", - "repo": "treefmt-nix", - "rev": "719c2977f958c41fa60a928e2fbc50af14844114", + "lastModified": 1688610262, + "narHash": "sha256-Wg0ViDotFWGWqKIQzyYCgayeH8s4U1OZcTiWTQYdAp4=", + "owner": "thomashoneyman", + "repo": "slimlock", + "rev": "b5c6cdcaf636ebbebd0a1f32520929394493f1a6", "type": "github" }, "original": { - "owner": "numtide", - "repo": "treefmt-nix", + "owner": "thomashoneyman", + "repo": "slimlock", "type": "github" } } diff --git a/flake.nix b/flake.nix index 7985ca4b..69259bdc 100644 --- a/flake.nix +++ b/flake.nix @@ -1,55 +1,52 @@ { - description = "A framework for 2nix tools"; - - nixConfig = { - extra-trusted-public-keys = "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="; - extra-substituters = "https://nix-community.cachix.org"; - }; + description = "Simplified nix packaging for various programming language ecosystems"; inputs = { - nixpkgs.url = "nixpkgs/nixos-unstable"; + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - flake-parts.url = "github:hercules-ci/flake-parts"; - flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs"; + pyproject-nix.url = "github:adisbladis/pyproject.nix"; + pyproject-nix.flake = false; - flake-compat.url = "github:edolstra/flake-compat"; - flake-compat.flake = false; - - pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix"; - pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs"; - - nix-unit.url = "github:adisbladis/nix-unit"; - nix-unit.inputs.nixpkgs.follows = "nixpkgs"; - nix-unit.inputs.flake-parts.follows = "flake-parts"; - - devshell = { - url = "github:numtide/devshell"; - flake = false; - }; + purescript-overlay.url = "github:thomashoneyman/purescript-overlay"; + purescript-overlay.inputs.nixpkgs.follows = "nixpkgs"; }; - outputs = { - self, - devshell, - flake-parts, - nixpkgs, - pre-commit-hooks, - ... - } @ inputs: - flake-parts.lib.mkFlake {inherit inputs;} { - imports = [ - ./modules/flake-parts/all-modules.nix - ./pkgs/fetchPipMetadata/flake-module.nix - ]; - systems = [ - "x86_64-linux" - "aarch64-linux" - "x86_64-darwin" - "aarch64-darwin" - ]; - flake.lib = import ./lib { - inherit (inputs.nixpkgs) lib; - dream2nix = inputs.self; - }; - }; + outputs = inputs: let + inherit + (builtins) + mapAttrs + readDir + ; + + inherit + (inputs.nixpkgs.lib) + filterAttrs + mapAttrs' + removeSuffix + ; + + devFlake = import ./dev-flake; + + modulesDir = ./modules; + + moduleKinds = + filterAttrs (_: type: type == "directory") (readDir modulesDir); + + mapModules = kind: + mapAttrs' + (fn: _: { + name = removeSuffix ".nix" fn; + value = modulesDir + "/${kind}/${fn}"; + }) + (readDir (modulesDir + "/${kind}")); + in{ + inherit + (devFlake) + checks + devShells + lib + packages + ; + modules = mapAttrs (kind: _: mapModules kind) moduleKinds; + }; } diff --git a/modules/flake-parts/checks.nix-unit.nix b/modules/flake-parts/checks.nix-unit.nix index 5b0c5255..04702442 100644 --- a/modules/flake-parts/checks.nix-unit.nix +++ b/modules/flake-parts/checks.nix-unit.nix @@ -7,8 +7,8 @@ system, ... }: let - modulesFlake = import "${self}/modules" {}; - inputs = lib.mapAttrs (name: input: "${input.outPath}") modulesFlake.inputs; + dream2nixFlake = import ../../. {}; + inputs = lib.mapAttrs (name: input: "${input.outPath}") dream2nixFlake.inputs; inputsFile = builtins.toFile "inputs.json" (builtins.toJSON inputs); in lib.optionalAttrs (system == "x86_64-linux") { @@ -21,7 +21,7 @@ } '' export NIX_PATH=nixpkgs=${pkgs.path} export HOME=$(realpath .) - for test in ${self}/tests/nix-unit/*; do + for test in ${../..}/tests/nix-unit/*; do if [ -f "$test" ]; then continue fi diff --git a/modules/flake-parts/core-modules.nix b/modules/flake-parts/core-modules.nix index e88db4a4..7dafa6bf 100644 --- a/modules/flake-parts/core-modules.nix +++ b/modules/flake-parts/core-modules.nix @@ -20,7 +20,7 @@ removeSuffix ; - path = self + "/modules/dream2nix/core"; + path = ../dream2nix/core; dirs = filterAttrs (name: _: name != "default.nix") (readDir path); diff --git a/modules/flake-parts/examples.nix b/modules/flake-parts/examples.nix index 686b34ac..3e3ef6fd 100644 --- a/modules/flake-parts/examples.nix +++ b/modules/flake-parts/examples.nix @@ -18,10 +18,10 @@ readDir ; - packageCategories = readDir (self + "/examples/packages"); + packageCategories = readDir (../../examples/packages); readExamples = dirName: let - examplesPath = self + /examples/packages + "/${dirName}"; + examplesPath = ../../examples/packages + "/${dirName}"; examples = readDir examplesPath; in flip mapAttrs examples @@ -39,16 +39,16 @@ in self'; - importFlakeSmall = flakeFile: let - self' = (import flakeFile).outputs { - dream2nix = modulesFlake; - nixpkgs = inputs.nixpkgs; - self = self'; - }; - in - self'; + # importFlakeSmall = flakeFile: let + # self' = (import flakeFile).outputs { + # dream2nix = dream2nixFlake; + # nixpkgs = inputs.nixpkgs; + # self = self'; + # }; + # in + # self'; - modulesFlake = import (self + /modules) {}; + # dream2nixFlake = import (../../.) {}; # Type: [ {${name} = {module, packagePath} ] allExamplesList = mapAttrsToList (dirName: _: readExamples dirName) packageCategories; @@ -71,9 +71,9 @@ in { // { # add repo templates repo.description = "Dream2nix repo without flakes"; - repo.path = self + /examples/repo; + repo.path = ../../examples/repo; repo-flake.description = "Dream2nix repo with flakes"; - repo-flake.path = self + /examples/repo-flake; + repo-flake.path = ../../examples/repo-flake; }; perSystem = { @@ -95,16 +95,19 @@ in { ( (lib.mapAttrs (_: flakeFile: getPackage flakeFile) allExamples) // { - example-repo = - (import (self + /examples/repo) { - dream2nixSource = self; - inherit pkgs; - }) - .hello; + example-repo = let + imported = + (import (../../examples/repo) { + dream2nixSource = ../..; + inherit pkgs; + }) + .hello; + in + imported; example-repo-flake = - (importFlake (self + /examples/repo-flake/flake.nix)).packages.${system}.hello; - example-repo-flake-pdm = - (importFlakeSmall (self + /examples/repo-flake-pdm/flake.nix)).packages.${system}.my-project; + (importFlake (../../examples/repo-flake/flake.nix)).packages.${system}.hello; + # example-repo-flake-pdm = + # (importFlakeSmall (../../examples/repo-flake-pdm/flake.nix)).packages.${system}.my-project; } ); diff --git a/modules/flake-parts/site/default.nix b/modules/flake-parts/site/default.nix index cba0d8fa..46eae7a5 100644 --- a/modules/flake-parts/site/default.nix +++ b/modules/flake-parts/site/default.nix @@ -94,7 +94,7 @@ } < SUMMARY.md.orig > src/SUMMARY.md mkdir -p ./theme - cp ${self + /modules/dream2nix/core/docs/theme/favicon.png} ./theme/favicon.png + cp ${../../dream2nix/core/docs/theme/favicon.png} ./theme/favicon.png mkdir -p src/options for f in ${config.packages.generated-docs}/*.html; do diff --git a/modules/flake-parts/website.nix b/modules/flake-parts/website.nix index 12c902f7..a8c62a8d 100644 --- a/modules/flake-parts/website.nix +++ b/modules/flake-parts/website.nix @@ -42,8 +42,8 @@ (lib.strings.escapeNixIdentifier name) ]; intro = - if lib.pathExists (self + /modules/dream2nix/${name}/README.md) - then lib.readFile (self + /modules/dream2nix/${name}/README.md) + if lib.pathExists (../dream2nix/${name}/README.md) + then lib.readFile (../dream2nix/${name}/README.md) else ""; baseUrl = "https://github.com/nix-community/dream2nix/blob/master"; separateEval = true; diff --git a/modules/flake.nix b/modules/flake.nix deleted file mode 100644 index 4862bf37..00000000 --- a/modules/flake.nix +++ /dev/null @@ -1,77 +0,0 @@ -{ - description = "(modules only) dream2nix: Automate reproducible packaging for various language ecosystems"; - - inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - - flake-compat.url = "github:nix-community/flake-compat/pull/4/head"; - flake-compat.flake = false; - - pyproject-nix.url = "github:adisbladis/pyproject.nix"; - pyproject-nix.flake = false; - - purescript-overlay.url = "github:thomashoneyman/purescript-overlay"; - purescript-overlay.inputs.nixpkgs.follows = "nixpkgs"; - }; - - outputs = _: let - modulesDir = ./.; - - inherit - (builtins) - attrNames - concatMap - listToAttrs - mapAttrs - readDir - stringLength - substring - ; - - nameValuePair = name: value: {inherit name value;}; - - filterAttrs = - # Predicate taking an attribute name and an attribute value, which returns `true` to include the attribute, or `false` to exclude the attribute. - pred: - # The attribute set to filter - set: - listToAttrs (concatMap (name: let - v = set.${name}; - in - if pred name v - then [(nameValuePair name v)] - else []) (attrNames set)); - - moduleKinds = - filterAttrs (_: type: type == "directory") (readDir modulesDir); - - mapAttrs' = - # A function, given an attribute's name and value, returns a new `nameValuePair`. - f: - # Attribute set to map over. - set: - listToAttrs (map (attr: f attr set.${attr}) (attrNames set)); - - removeSuffix = - # Suffix to remove if it matches - suffix: - # Input string - str: (let - sufLen = stringLength suffix; - sLen = stringLength str; - in - if sufLen <= sLen && suffix == substring (sLen - sufLen) sufLen str - then substring 0 (sLen - sufLen) str - else str); - - mapModules = kind: - mapAttrs' - (fn: _: { - name = removeSuffix ".nix" fn; - value = modulesDir + "/${kind}/${fn}"; - }) - (readDir (modulesDir + "/${kind}")); - in { - modules = mapAttrs (kind: _: mapModules kind) moduleKinds; - }; -}