lib: mkOfflineFlakeLock init
copied from the clan-core-flake module I plan to re-use this function to improve the clan test framework to allow cli execution
This commit is contained in:
@@ -51,6 +51,11 @@ lib.fix (clanLib: {
|
|||||||
jsonschema = import ./jsonschema { inherit lib; };
|
jsonschema = import ./jsonschema { inherit lib; };
|
||||||
facts = import ./facts.nix { inherit lib; };
|
facts = import ./facts.nix { inherit lib; };
|
||||||
|
|
||||||
|
# flakes
|
||||||
|
flakes = clanLib.callLib ./flakes.nix {
|
||||||
|
clan-core = self;
|
||||||
|
};
|
||||||
|
|
||||||
# deprecated
|
# deprecated
|
||||||
# remove when https://git.clan.lol/clan/clan-core/pulls/3212 is implemented
|
# remove when https://git.clan.lol/clan/clan-core/pulls/3212 is implemented
|
||||||
inherit (self.inputs.nix-select.lib) select;
|
inherit (self.inputs.nix-select.lib) select;
|
||||||
|
|||||||
40
lib/flakes.nix
Normal file
40
lib/flakes.nix
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
{
|
||||||
|
lib,
|
||||||
|
clan-core,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
{
|
||||||
|
# A flake lock for offline use.
|
||||||
|
# All flake inputs are locked to an existing store path
|
||||||
|
mkOfflineFlakeLock =
|
||||||
|
flakePath:
|
||||||
|
let
|
||||||
|
flakeLock = lib.importJSON (flakePath + "/flake.lock");
|
||||||
|
flakeInputs = builtins.removeAttrs clan-core.inputs [ "self" ];
|
||||||
|
inputsToPaths =
|
||||||
|
flakeLock:
|
||||||
|
flakeLock
|
||||||
|
// {
|
||||||
|
nodes =
|
||||||
|
flakeLock.nodes
|
||||||
|
// (lib.flip lib.mapAttrs flakeInputs (
|
||||||
|
name: _:
|
||||||
|
# remove follows and let 'nix flake lock' re-compute it later
|
||||||
|
# (lib.removeAttrs flakeLock.nodes.${name} ["inputs"])
|
||||||
|
flakeLock.nodes.${name}
|
||||||
|
// {
|
||||||
|
locked = {
|
||||||
|
inherit (flakeLock.nodes.${name}.locked) narHash;
|
||||||
|
lastModified =
|
||||||
|
# lol, nixpkgs has a different timestamp on the fs???
|
||||||
|
if name == "nixpkgs" then 0 else 1;
|
||||||
|
path = "${clan-core.inputs.${name}}";
|
||||||
|
type = "path";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
));
|
||||||
|
};
|
||||||
|
lockAttrs = inputsToPaths flakeLock;
|
||||||
|
in
|
||||||
|
builtins.toFile "offline-flake.lock" (builtins.toJSON lockAttrs);
|
||||||
|
}
|
||||||
@@ -1,47 +1,15 @@
|
|||||||
{ self, inputs, ... }:
|
{ self, ... }:
|
||||||
|
let
|
||||||
|
inherit (self.clanLib.flakes)
|
||||||
|
mkOfflineFlakeLock
|
||||||
|
;
|
||||||
|
in
|
||||||
{
|
{
|
||||||
perSystem =
|
perSystem =
|
||||||
{
|
{
|
||||||
lib,
|
|
||||||
pkgs,
|
pkgs,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
|
||||||
# A flake lock for offline use.
|
|
||||||
# All flake inputs are locked to an existing store path
|
|
||||||
clanCoreLockFile =
|
|
||||||
clanCore:
|
|
||||||
let
|
|
||||||
flakeLock = lib.importJSON (clanCore + "/flake.lock");
|
|
||||||
flakeInputs = builtins.removeAttrs inputs [ "self" ];
|
|
||||||
flakeLockVendoredDeps =
|
|
||||||
flakeLock:
|
|
||||||
flakeLock
|
|
||||||
// {
|
|
||||||
nodes =
|
|
||||||
flakeLock.nodes
|
|
||||||
// (lib.flip lib.mapAttrs flakeInputs (
|
|
||||||
name: _:
|
|
||||||
# remove follows and let 'nix flake lock' re-compute it later
|
|
||||||
# (lib.removeAttrs flakeLock.nodes.${name} ["inputs"])
|
|
||||||
flakeLock.nodes.${name}
|
|
||||||
// {
|
|
||||||
locked = {
|
|
||||||
inherit (flakeLock.nodes.${name}.locked) narHash;
|
|
||||||
lastModified =
|
|
||||||
# lol, nixpkgs has a different timestamp on the fs???
|
|
||||||
if name == "nixpkgs" then 0 else 1;
|
|
||||||
path = "${inputs.${name}}";
|
|
||||||
type = "path";
|
|
||||||
};
|
|
||||||
}
|
|
||||||
));
|
|
||||||
};
|
|
||||||
clanCoreLock = flakeLockVendoredDeps flakeLock;
|
|
||||||
clanCoreLockFile = builtins.toFile "clan-core-flake.lock" (builtins.toJSON clanCoreLock);
|
|
||||||
in
|
|
||||||
clanCoreLockFile;
|
|
||||||
in
|
|
||||||
{
|
{
|
||||||
packages.clan-core-flake =
|
packages.clan-core-flake =
|
||||||
let
|
let
|
||||||
@@ -65,7 +33,7 @@
|
|||||||
export NIX_STORE_DIR=$HOME
|
export NIX_STORE_DIR=$HOME
|
||||||
cp -r ${clanCore} $out
|
cp -r ${clanCore} $out
|
||||||
chmod +w -R $out
|
chmod +w -R $out
|
||||||
cp ${clanCoreLockFile clanCore} $out/flake.lock
|
cp ${mkOfflineFlakeLock clanCore} $out/flake.lock
|
||||||
nix flake lock $out --extra-experimental-features 'nix-command flakes'
|
nix flake lock $out --extra-experimental-features 'nix-command flakes'
|
||||||
clanCoreHash=$(nix hash path ${clanCore} --extra-experimental-features 'nix-command')
|
clanCoreHash=$(nix hash path ${clanCore} --extra-experimental-features 'nix-command')
|
||||||
'';
|
'';
|
||||||
|
|||||||
Reference in New Issue
Block a user