Compare commits
34 commits
bollu/patc
...
main
Author | SHA1 | Date | |
---|---|---|---|
jade | fe7f6ec62b | ||
Charles Hall | e44e6cf654 | ||
Charles Hall | 8c1dda128e | ||
Charles Hall | 6327d063de | ||
Charles Hall | 1fadfb6600 | ||
jade | 33a2aba01c | ||
Charles Hall | 127c86e1d4 | ||
jade | 5adafc5bfb | ||
jade | 87e36b9f18 | ||
jade | 1be18e491b | ||
Rebecca Turner | baa7aa7bd0 | ||
0f9255e01c | |||
5a16547d46 | |||
4f910c9827 | |||
7ae5ae625a | |||
e1262c7073 | |||
Robert Hensing | bc5e257a8d | ||
2bf43d60c7 | |||
6256b599c8 | |||
c30381e188 | |||
e654cc30bf | |||
5717e26155 | |||
92556b8539 | |||
bcb80df051 | |||
35bb57c0c8 | |||
Robert Hensing | 43bfa87aa2 | ||
009399224d | |||
6f56392cc4 | |||
b4a34015c6 | |||
246e885130 | |||
64a525ee38 | |||
913e1270ff | |||
aee797a673 | |||
3b935d922d |
14
README.md
14
README.md
|
@ -6,7 +6,8 @@ To use, add the following to your `flake.nix`:
|
|||
|
||||
```nix
|
||||
inputs.flake-compat = {
|
||||
url = github:edolstra/flake-compat;
|
||||
url = "git+https://git.lix.systems/lix-project/flake-compat";
|
||||
# Optional:
|
||||
flake = false;
|
||||
};
|
||||
```
|
||||
|
@ -16,10 +17,13 @@ Afterwards, create a `default.nix` file containing the following:
|
|||
```nix
|
||||
(import
|
||||
(
|
||||
let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
|
||||
fetchTarball {
|
||||
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
|
||||
sha256 = lock.nodes.flake-compat.locked.narHash;
|
||||
let
|
||||
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
|
||||
inherit (lock.nodes.flake-compat.locked) narHash rev url;
|
||||
in
|
||||
builtins.fetchTarball {
|
||||
url = "${url}/archive/${rev}.tar.gz";
|
||||
sha256 = narHash;
|
||||
}
|
||||
)
|
||||
{ src = ./.; }
|
||||
|
|
59
default.nix
59
default.nix
|
@ -33,6 +33,7 @@ let
|
|||
({ 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;
|
||||
|
@ -62,8 +63,17 @@ let
|
|||
);
|
||||
shortRev = builtins.substring 0 7 info.rev;
|
||||
}
|
||||
else if info.type == "sourcehut" then
|
||||
{ inherit (info) rev narHash lastModified;
|
||||
outPath =
|
||||
fetchTarball
|
||||
({ url = "https://${info.host or "git.sr.ht"}/${info.owner}/${info.repo}/archive/${info.rev}.tar.gz"; }
|
||||
// (if info ? narHash then { sha256 = info.narHash; } else {})
|
||||
);
|
||||
shortRev = builtins.substring 0 7 info.rev;
|
||||
}
|
||||
else
|
||||
# FIXME: add Mercurial, tarball inputs.
|
||||
# FIXME: add Mercurial inputs.
|
||||
throw "flake input has unsupported input type '${info.type}'";
|
||||
|
||||
callFlake4 = flakeSrc: locks:
|
||||
|
@ -94,7 +104,22 @@ let
|
|||
then
|
||||
let res = builtins.fetchGit src;
|
||||
in if res.rev == "0000000000000000000000000000000000000000" then removeAttrs res ["rev" "shortRev"] else res
|
||||
else { outPath = src; };
|
||||
else {
|
||||
outPath =
|
||||
# Massage `src` into a store path.
|
||||
if builtins.isPath src
|
||||
then
|
||||
if dirOf (toString src) == builtins.storeDir
|
||||
# `builtins.storePath` is not available in pure-eval mode.
|
||||
&& builtins ? currentSystem
|
||||
then
|
||||
# If it's already a store path, don't copy it again.
|
||||
builtins.storePath src
|
||||
else
|
||||
"${src}"
|
||||
else
|
||||
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");
|
||||
|
@ -139,7 +164,9 @@ let
|
|||
|
||||
subdir = if key == lockFile.root then "" else node.locked.dir or "";
|
||||
|
||||
flake = import (sourceInfo + (if subdir != "" then "/" else "") + subdir + "/flake.nix");
|
||||
outPath = sourceInfo + ((if subdir == "" then "" else "/") + subdir);
|
||||
|
||||
flake = import (outPath + "/flake.nix");
|
||||
|
||||
inputs = builtins.mapAttrs
|
||||
(inputName: inputSpec: allNodes.${resolveInput inputSpec})
|
||||
|
@ -166,7 +193,21 @@ let
|
|||
|
||||
outputs = flake.outputs (inputs // { self = result; });
|
||||
|
||||
result = outputs // sourceInfo // { inherit inputs; inherit outputs; inherit sourceInfo; };
|
||||
result =
|
||||
outputs
|
||||
# We add the sourceInfo attribute for its metadata, as they are
|
||||
# relevant metadata for the flake. However, the outPath of the
|
||||
# sourceInfo does not necessarily match the outPath of the flake,
|
||||
# as the flake may be in a subdirectory of a source.
|
||||
# This is shadowed in the next //
|
||||
// sourceInfo
|
||||
// {
|
||||
# This shadows the sourceInfo.outPath
|
||||
inherit outPath;
|
||||
|
||||
inherit inputs; inherit outputs; inherit sourceInfo; _type = "flake";
|
||||
};
|
||||
|
||||
in
|
||||
if node.flake or true then
|
||||
assert builtins.isFunction flake.outputs;
|
||||
|
@ -187,11 +228,15 @@ let
|
|||
|
||||
in
|
||||
rec {
|
||||
inputs = result.inputs // { self = result; };
|
||||
|
||||
defaultNix =
|
||||
result
|
||||
// (if result ? defaultPackage.${system} then { default = result.defaultPackage.${system}; } else {});
|
||||
(builtins.removeAttrs result ["__functor"])
|
||||
// (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 ? devShell.${system} then { default = result.devShell.${system}; } else {})
|
||||
// (if result ? devShells.${system}.default then { default = result.devShells.${system}.default; } else {});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue