Compare commits
1 commit
main
...
bollu/patc
Author | SHA1 | Date | |
---|---|---|---|
d15b535f38 |
18
README.md
18
README.md
|
@ -1,13 +1,16 @@
|
|||
# flake-compat
|
||||
|
||||
## Introduction
|
||||
|
||||
**[Nix Flakes: Using flakes project from a legacy Nix.](https://nixos.wiki/wiki/Flakes#Using_flakes_project_from_a_legacy_Nix)**
|
||||
|
||||
## Usage
|
||||
|
||||
To use, add the following to your `flake.nix`:
|
||||
|
||||
```nix
|
||||
inputs.flake-compat = {
|
||||
url = "git+https://git.lix.systems/lix-project/flake-compat";
|
||||
# Optional:
|
||||
url = github:edolstra/flake-compat;
|
||||
flake = false;
|
||||
};
|
||||
```
|
||||
|
@ -17,13 +20,10 @@ Afterwards, create a `default.nix` file containing the following:
|
|||
```nix
|
||||
(import
|
||||
(
|
||||
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;
|
||||
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;
|
||||
}
|
||||
)
|
||||
{ src = ./.; }
|
||||
|
|
59
default.nix
59
default.nix
|
@ -33,7 +33,6 @@ 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;
|
||||
|
@ -63,17 +62,8 @@ 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 inputs.
|
||||
# FIXME: add Mercurial, tarball inputs.
|
||||
throw "flake input has unsupported input type '${info.type}'";
|
||||
|
||||
callFlake4 = flakeSrc: locks:
|
||||
|
@ -104,22 +94,7 @@ let
|
|||
then
|
||||
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;
|
||||
};
|
||||
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");
|
||||
|
@ -164,9 +139,7 @@ let
|
|||
|
||||
subdir = if key == lockFile.root then "" else node.locked.dir or "";
|
||||
|
||||
outPath = sourceInfo + ((if subdir == "" then "" else "/") + subdir);
|
||||
|
||||
flake = import (outPath + "/flake.nix");
|
||||
flake = import (sourceInfo + (if subdir != "" then "/" else "") + subdir + "/flake.nix");
|
||||
|
||||
inputs = builtins.mapAttrs
|
||||
(inputName: inputSpec: allNodes.${resolveInput inputSpec})
|
||||
|
@ -193,21 +166,7 @@ let
|
|||
|
||||
outputs = flake.outputs (inputs // { self = result; });
|
||||
|
||||
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";
|
||||
};
|
||||
|
||||
result = outputs // sourceInfo // { inherit inputs; inherit outputs; inherit sourceInfo; };
|
||||
in
|
||||
if node.flake or true then
|
||||
assert builtins.isFunction flake.outputs;
|
||||
|
@ -228,15 +187,11 @@ let
|
|||
|
||||
in
|
||||
rec {
|
||||
inputs = result.inputs // { self = result; };
|
||||
|
||||
defaultNix =
|
||||
(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 {});
|
||||
result
|
||||
// (if result ? defaultPackage.${system} then { default = result.defaultPackage.${system}; } 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 {});
|
||||
// (if result ? devShell.${system} then { default = result.devShell.${system}; } else {});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue