A helper to use flakes from stable Nix.
Based on original work in
since none of those seem to be actively maintained.
This library also exposes:
fetchTree: Polyfill for the experimentalbuiltins.fetchTreegetFlake: Polyfill for the experimentalbuiltins.getFlakedatetime-from-timestamp: A converter from Unix timestamps to Gregorian date and time, ported from Howard Hinnant'schrono-Compatible Low-Level Date Algorithmspad: The legendarypadfunction
- Separately managing development dependencies to reduce closure size for flake consumers
- Gradually migrating away from flakes
- Offering a first-class experience for users of stable Nix
In default.nix obtain the flake-inputs library and use sources flake.lock:
# default.nix
let
inherit (import (fetchTarball "https://github.com/fricklerhandwerk/flake-inputs/tarball/4.0"))
import-flake
;
inherit (import-flake {
src = ./.;
}) inputs;
in
{
system ? builtins.currentSystem,
config ? { },
overlays ? [ ],
...
}@args:
let
pkgs = import inputs.nixpkgs ({ inherit system config overlays; } // args);
in
{
packages = {
inherit (pkgs) cowsay lolcat;
};
}
In flake.nix use attributes from default.nix for outputs:
# flake.nix
{
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs =
{ flake-utils, ... }@inputs:
flake-utils.lib.eachDefaultSystem (
system:
import ./default.nix { inherit system; };
);
}Keep using the inputs attribute to specify sources, and nix flake update to pull the latest versions.
Obtain flake-inputs and some arbitrary project that is very inconvenient to evaluate from stable Nix:
nix-shell -p npins --run "
npins init --bare
npins add github fricklerhandwerk flake-inputs --at 4.0
npins add github nixos nix --branch 2.29-maintenance
"In default.nix import the flake with load-flake from the flake-inputs library:
# default.nix
let
sources = import ./npins;
in
{
flake-inputs ? sources.flake-inputs,
nix ? sources.nix,
}:
let
inherit (import flake-inputs) load-flake;
in
(load-flake nix).packages.${builtins.currentSystem}.default
Realise the derivation from a substituter to demonstrate that it works as intended:
nix-build --no-out-link