Compare commits
38 commits
jtojnar/fr
...
main
Author | SHA1 | Date | |
---|---|---|---|
|
5adafc5bfb | ||
|
87e36b9f18 | ||
|
1be18e491b | ||
|
baa7aa7bd0 | ||
![]() |
0f9255e01c | ||
![]() |
5a16547d46 | ||
![]() |
4f910c9827 | ||
![]() |
7ae5ae625a | ||
![]() |
e1262c7073 | ||
|
bc5e257a8d | ||
![]() |
2bf43d60c7 | ||
![]() |
6256b599c8 | ||
![]() |
c30381e188 | ||
![]() |
e654cc30bf | ||
![]() |
5717e26155 | ||
![]() |
92556b8539 | ||
![]() |
bcb80df051 | ||
![]() |
35bb57c0c8 | ||
|
43bfa87aa2 | ||
![]() |
009399224d | ||
![]() |
6f56392cc4 | ||
![]() |
b4a34015c6 | ||
![]() |
246e885130 | ||
![]() |
64a525ee38 | ||
![]() |
913e1270ff | ||
![]() |
aee797a673 | ||
![]() |
3b935d922d | ||
![]() |
b7547d3eed | ||
![]() |
b640d1826b | ||
![]() |
12c64ca55c | ||
|
4112a081ef | ||
![]() |
bef1b74164 | ||
|
14dbada01f | ||
|
2cb6b2d577 | ||
![]() |
c6f3b63532 | ||
![]() |
99f1c2157f | ||
![]() |
8812d6d109 | ||
|
a2fd0358b1 |
20
COPYING
Normal file
20
COPYING
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
Copyright (c) 2020-2021 Eelco Dolstra and the flake-compat contributors
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
a copy of this software and associated documentation files (the
|
||||||
|
"Software"), to deal in the Software without restriction, including
|
||||||
|
without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be
|
||||||
|
included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
41
README.md
Normal file
41
README.md
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
# flake-compat
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
> [!WARNING]
|
||||||
|
> During the Lix private beta period during which Forgejo is private, this
|
||||||
|
> requires configuring netrc in Lix for the tarball download to work.
|
||||||
|
>
|
||||||
|
> Your netrc should look something like so:
|
||||||
|
> ```
|
||||||
|
> machine git.lix.systems login YOUR-USERNAME password SOME-PERSONAL-ACCESS-TOKEN-REPO-READ
|
||||||
|
> ```
|
||||||
|
>
|
||||||
|
> We are terribly sorry for the UX for this being very bad
|
||||||
|
> ([issue](https://git.lix.systems/lix-project/lix/issues/254)).
|
||||||
|
|
||||||
|
To use, add the following to your `flake.nix`:
|
||||||
|
|
||||||
|
<!-- FIXME: this can use the standard non-api archive url when we are
|
||||||
|
un-privated -->
|
||||||
|
|
||||||
|
```nix
|
||||||
|
inputs.flake-compat.url = "https://git.lix.systems/api/v1/repos/lix-project/flake-compat/archive/main.tar.gz";
|
||||||
|
```
|
||||||
|
|
||||||
|
Afterwards, create a `default.nix` file containing the following:
|
||||||
|
|
||||||
|
```nix
|
||||||
|
(import
|
||||||
|
(
|
||||||
|
let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
|
||||||
|
fetchTarball {
|
||||||
|
url = lock.nodes.flake-compat.locked.url;
|
||||||
|
sha256 = lock.nodes.flake-compat.locked.narHash;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
{ src = ./.; }
|
||||||
|
).defaultNix
|
||||||
|
```
|
||||||
|
|
||||||
|
If you would like a `shell.nix` file, create one containing the above, replacing `defaultNix` with `shellNix`.
|
92
default.nix
92
default.nix
|
@ -16,7 +16,11 @@ let
|
||||||
fetchTree =
|
fetchTree =
|
||||||
info:
|
info:
|
||||||
if info.type == "github" then
|
if info.type == "github" then
|
||||||
{ outPath = fetchTarball "https://api.${info.host or "github.com"}/repos/${info.owner}/${info.repo}/tarball/${info.rev}";
|
{ 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;
|
rev = info.rev;
|
||||||
shortRev = builtins.substring 0 7 info.rev;
|
shortRev = builtins.substring 0 7 info.rev;
|
||||||
lastModified = info.lastModified;
|
lastModified = info.lastModified;
|
||||||
|
@ -29,28 +33,47 @@ let
|
||||||
({ url = info.url; }
|
({ url = info.url; }
|
||||||
// (if info ? rev then { inherit (info) rev; } else {})
|
// (if info ? rev then { inherit (info) rev; } else {})
|
||||||
// (if info ? ref then { inherit (info) ref; } else {})
|
// (if info ? ref then { inherit (info) ref; } else {})
|
||||||
|
// (if info ? submodules then { inherit (info) submodules; } else {})
|
||||||
);
|
);
|
||||||
rev = info.rev;
|
|
||||||
shortRev = builtins.substring 0 7 info.rev;
|
|
||||||
lastModified = info.lastModified;
|
lastModified = info.lastModified;
|
||||||
lastModifiedDate = formatSecondsSinceEpoch info.lastModified;
|
lastModifiedDate = formatSecondsSinceEpoch info.lastModified;
|
||||||
narHash = info.narHash;
|
narHash = info.narHash;
|
||||||
}
|
} // (if info ? rev then {
|
||||||
|
rev = info.rev;
|
||||||
|
shortRev = builtins.substring 0 7 info.rev;
|
||||||
|
} else {
|
||||||
|
})
|
||||||
else if info.type == "path" then
|
else if info.type == "path" then
|
||||||
{ outPath = builtins.path { path = info.path; };
|
{ outPath = builtins.path { path = info.path; };
|
||||||
narHash = info.narHash;
|
narHash = info.narHash;
|
||||||
}
|
}
|
||||||
else if info.type == "tarball" then
|
else if info.type == "tarball" then
|
||||||
{ outPath = fetchTarball info.url;
|
{ outPath =
|
||||||
narHash = info.narHash;
|
fetchTarball
|
||||||
|
({ inherit (info) url; }
|
||||||
|
// (if info ? narHash then { sha256 = info.narHash; } else {})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
else if info.type == "gitlab" then
|
else if info.type == "gitlab" then
|
||||||
{ inherit (info) rev narHash lastModified;
|
{ inherit (info) rev narHash lastModified;
|
||||||
outPath = fetchTarball "https://${info.host or "gitlab.com"}/api/v4/projects/${info.owner}%2F${info.repo}/repository/archive.tar.gz?sha=${info.rev}";
|
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 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;
|
shortRev = builtins.substring 0 7 info.rev;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
# FIXME: add Mercurial, tarball inputs.
|
# FIXME: add Mercurial inputs.
|
||||||
throw "flake input has unsupported input type '${info.type}'";
|
throw "flake input has unsupported input type '${info.type}'";
|
||||||
|
|
||||||
callFlake4 = flakeSrc: locks:
|
callFlake4 = flakeSrc: locks:
|
||||||
|
@ -78,15 +101,32 @@ let
|
||||||
# tree is a valid git repository.
|
# tree is a valid git repository.
|
||||||
tryFetchGit = src:
|
tryFetchGit = src:
|
||||||
if isGit && !isShallow
|
if isGit && !isShallow
|
||||||
then builtins.fetchGit src
|
then
|
||||||
else { outPath = src; };
|
let res = builtins.fetchGit src;
|
||||||
|
in if res.rev == "0000000000000000000000000000000000000000" then removeAttrs res ["rev" "shortRev"] else res
|
||||||
|
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
|
# NB git worktrees have a file for .git, so we don't check the type of .git
|
||||||
isGit = builtins.pathExists (src + "/.git");
|
isGit = builtins.pathExists (src + "/.git");
|
||||||
isShallow = builtins.pathExists (src + "/.git/shallow");
|
isShallow = builtins.pathExists (src + "/.git/shallow");
|
||||||
|
|
||||||
in
|
in
|
||||||
(if src ? outPath then src else tryFetchGit src)
|
{ lastModified = 0; lastModifiedDate = formatSecondsSinceEpoch 0; }
|
||||||
// { 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.
|
# Format number of seconds in the Unix epoch as %Y%m%d%H%M%S.
|
||||||
formatSecondsSinceEpoch = t:
|
formatSecondsSinceEpoch = t:
|
||||||
|
@ -124,7 +164,9 @@ let
|
||||||
|
|
||||||
subdir = if key == lockFile.root then "" else node.locked.dir or "";
|
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
|
inputs = builtins.mapAttrs
|
||||||
(inputName: inputSpec: allNodes.${resolveInput inputSpec})
|
(inputName: inputSpec: allNodes.${resolveInput inputSpec})
|
||||||
|
@ -151,7 +193,21 @@ let
|
||||||
|
|
||||||
outputs = flake.outputs (inputs // { self = result; });
|
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
|
in
|
||||||
if node.flake or true then
|
if node.flake or true then
|
||||||
assert builtins.isFunction flake.outputs;
|
assert builtins.isFunction flake.outputs;
|
||||||
|
@ -173,10 +229,12 @@ let
|
||||||
in
|
in
|
||||||
rec {
|
rec {
|
||||||
defaultNix =
|
defaultNix =
|
||||||
result
|
(builtins.removeAttrs result ["__functor"])
|
||||||
// (if result ? defaultPackage.${system} then { default = result.defaultPackage.${system}; } else {});
|
// (if result ? defaultPackage.${system} then { default = result.defaultPackage.${system}; } else {})
|
||||||
|
// (if result ? packages.${system}.default then { default = result.packages.${system}.default; } else {});
|
||||||
|
|
||||||
shellNix =
|
shellNix =
|
||||||
defaultNix
|
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