migrate from niv to npins (#991)

This commit is contained in:
Valentin Gagarin 2024-06-03 09:50:23 +02:00 committed by GitHub
parent a792a25bb0
commit bfa0c7de86
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 327 additions and 407 deletions

View File

@ -1,14 +1,13 @@
{ inputs ? import ./nix/inputs.nix
, system ? builtins.currentSystem
,
}:
let
pkgs = import inputs.nixpkgs."23.05" {
{
inputs ? import ./nix/inputs.nix,
system ? builtins.currentSystem,
pkgs ? import inputs.nixpkgs."23.05" {
config = { };
overlays = [ (import ./nix/overlay.nix) ];
inherit system;
};
},
}:
let
lib = pkgs.lib;
releases = import ./nix/releases.nix { inherit lib inputs system; };
@ -118,7 +117,7 @@ in
devmode
update-nix-releases
update-nixpkgs-releases
pkgs.niv
pkgs.npins
pkgs.python310.pkgs.black
pkgs.vale
pkgs.netlify-cli

View File

@ -1,13 +1,11 @@
# An abstraction over the different source pins in this directory
{
# The main niv pins, these are without any standard names:
# The main npins sources, these are without any standard names:
# {
# <name> = <source>;
# }
main = import ./sources.nix {
sourcesFile = ./sources.json;
};
main = import ../npins { };
# Sources for Nix releases, the attribute name is the release version.
# These are done specially because updating these is non-trivial.
@ -26,11 +24,10 @@
) (builtins.fromJSON (builtins.readFile ./nix-versions.json));
# Sources for Nixpkgs releases, the attribute name is the release name.
# These can be updated with the standard niv tooling, but are tracked separately to avoid having to filter them out during processing.
# These can be updated with the standard npins tooling, but are tracked separately to avoid having to filter them out during processing.
# See ./update-nixpkgs-releases.nix
nixpkgs =
import ./sources.nix {
sourcesFile = ./nixpkgs-versions.json;
};
nixpkgs = import ../npins {
json = ./sources.json;
};
}

View File

@ -1,134 +0,0 @@
{
"18.09": {
"branch": "nixos-18.09",
"description": "Nix Packages collection & NixOS",
"homepage": "",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "a7e559a5504572008567383c3dc8e142fa7a8633",
"sha256": "16j95q58kkc69lfgpjkj76gw5sx8rcxwi3civm0mlfaxxyw9gzp6",
"type": "tarball",
"url": "https://github.com/nixos/nixpkgs/archive/a7e559a5504572008567383c3dc8e142fa7a8633.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"19.03": {
"branch": "nixos-19.03",
"description": "Nix Packages collection & NixOS",
"homepage": "",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "34c7eb7545d155cc5b6f499b23a7cb1c96ab4d59",
"sha256": "11z6ajj108fy2q5g8y4higlcaqncrbjm3dnv17pvif6avagw4mcb",
"type": "tarball",
"url": "https://github.com/nixos/nixpkgs/archive/34c7eb7545d155cc5b6f499b23a7cb1c96ab4d59.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"19.09": {
"branch": "nixos-19.09",
"description": "Nix Packages collection & NixOS",
"homepage": "",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "75f4ba05c63be3f147bcc2f7bd4ba1f029cedcb1",
"sha256": "157c64220lf825ll4c0cxsdwg7cxqdx4z559fdp7kpz0g6p8fhhr",
"type": "tarball",
"url": "https://github.com/nixos/nixpkgs/archive/75f4ba05c63be3f147bcc2f7bd4ba1f029cedcb1.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"20.03": {
"branch": "nixos-20.03",
"description": "Nix Packages collection & NixOS",
"homepage": "",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "1db42b7fe3878f3f5f7a4f2dc210772fd080e205",
"sha256": "05k9y9ki6jhaqdhycnidnk5zrdzsdammbk5lsmsbz249hjhhgcgh",
"type": "tarball",
"url": "https://github.com/nixos/nixpkgs/archive/1db42b7fe3878f3f5f7a4f2dc210772fd080e205.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"20.09": {
"branch": "nixos-20.09",
"description": "Nix Packages collection & NixOS",
"homepage": "",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "1c1f5649bb9c1b0d98637c8c365228f57126f361",
"sha256": "0f2nvdijyxfgl5kwyb4465pppd5vkhqxddx6v40k2s0z9jfhj0xl",
"type": "tarball",
"url": "https://github.com/nixos/nixpkgs/archive/1c1f5649bb9c1b0d98637c8c365228f57126f361.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"21.05": {
"branch": "nixos-21.05",
"description": "Nix Packages collection & NixOS",
"homepage": "",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "022caabb5f2265ad4006c1fa5b1ebe69fb0c3faf",
"sha256": "12q00nbd7fb812zchbcnmdg3pw45qhxm74hgpjmshc2dfmgkjh4n",
"type": "tarball",
"url": "https://github.com/nixos/nixpkgs/archive/022caabb5f2265ad4006c1fa5b1ebe69fb0c3faf.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"21.11": {
"branch": "nixos-21.11",
"description": "Nix Packages collection & NixOS",
"homepage": "",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "eabc38219184cc3e04a974fe31857d8e0eac098d",
"sha256": "04ffwp2gzq0hhz7siskw6qh9ys8ragp7285vi1zh8xjksxn1msc5",
"type": "tarball",
"url": "https://github.com/nixos/nixpkgs/archive/eabc38219184cc3e04a974fe31857d8e0eac098d.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"22.05": {
"branch": "nixos-22.05",
"description": "Nix Packages collection & NixOS",
"homepage": "",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "380be19fbd2d9079f677978361792cb25e8a3635",
"sha256": "154x9swf494mqwi4z8nbq2f0sp8pwp4fvx51lqzindjfbb9yxxv5",
"type": "tarball",
"url": "https://github.com/nixos/nixpkgs/archive/380be19fbd2d9079f677978361792cb25e8a3635.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"22.11": {
"branch": "nixos-22.11",
"description": "Nix Packages collection & NixOS",
"homepage": "",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "ea4c80b39be4c09702b0cb3b42eab59e2ba4f24b",
"sha256": "1xi53rlslcprybsvrmipm69ypd3g3hr7wkxvzc73ag8296yclyll",
"type": "tarball",
"url": "https://github.com/nixos/nixpkgs/archive/ea4c80b39be4c09702b0cb3b42eab59e2ba4f24b.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"23.05": {
"branch": "nixos-23.05",
"description": "Nix Packages collection & NixOS",
"homepage": "",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "70bdadeb94ffc8806c0570eb5c2695ad29f0e421",
"sha256": "05cbl1k193c9la9xhlz4y6y8ijpb2mkaqrab30zij6z4kqgclsrd",
"type": "tarball",
"url": "https://github.com/nixos/nixpkgs/archive/70bdadeb94ffc8806c0570eb5c2695ad29f0e421.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"23.11": {
"branch": "nixos-23.11",
"description": "Nix Packages collection & NixOS",
"homepage": "",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "219951b495fc2eac67b1456824cc1ec1fd2ee659",
"sha256": "065jy7qivlbdqmbvd7r9h97b23f21axmc4r7sqmq2h0j82rmymxv",
"type": "tarball",
"url": "https://github.com/nixos/nixpkgs/archive/219951b495fc2eac67b1456824cc1ec1fd2ee659.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
}
}

View File

@ -1,26 +1,150 @@
{
"nixpkgs-rolling": {
"branch": "nixpkgs-unstable",
"description": "Nix Packages collection & NixOS",
"homepage": "",
"pins": {
"18.09": {
"type": "Git",
"repository": {
"type": "GitHub",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "e976fa8f49c35cf28496301a1ef2aa23ad576b56",
"sha256": "1kq9wkwaf4kfv2p29jdqwfkbadmx1isbkaryqcrrjah4wskwa1rw",
"type": "tarball",
"url": "https://github.com/nixos/nixpkgs/archive/e976fa8f49c35cf28496301a1ef2aa23ad576b56.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
"repo": "nixpkgs"
},
"branch": "nixos-18.09",
"revision": "a7e559a5504572008567383c3dc8e142fa7a8633",
"url": "https://github.com/nixos/nixpkgs/archive/a7e559a5504572008567383c3dc8e142fa7a8633.tar.gz",
"hash": "16j95q58kkc69lfgpjkj76gw5sx8rcxwi3civm0mlfaxxyw9gzp6"
},
"poetry2nix": {
"branch": "master",
"description": "Convert poetry projects to nix automagically [maintainer=@adisbladis] ",
"homepage": "",
"owner": "nix-community",
"repo": "poetry2nix",
"rev": "fe0dcb4c9b44162a385f1170895fe6a392ed71b5",
"sha256": "0cxccm7hzcmizhbg79rdqimjndin98waibw824cmgzwwqkyzl9lv",
"type": "tarball",
"url": "https://github.com/nix-community/poetry2nix/archive/fe0dcb4c9b44162a385f1170895fe6a392ed71b5.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
"19.03": {
"type": "Git",
"repository": {
"type": "GitHub",
"owner": "nixos",
"repo": "nixpkgs"
},
"branch": "nixos-19.03",
"revision": "34c7eb7545d155cc5b6f499b23a7cb1c96ab4d59",
"url": "https://github.com/nixos/nixpkgs/archive/34c7eb7545d155cc5b6f499b23a7cb1c96ab4d59.tar.gz",
"hash": "11z6ajj108fy2q5g8y4higlcaqncrbjm3dnv17pvif6avagw4mcb"
},
"19.09": {
"type": "Git",
"repository": {
"type": "GitHub",
"owner": "nixos",
"repo": "nixpkgs"
},
"branch": "nixos-19.09",
"revision": "75f4ba05c63be3f147bcc2f7bd4ba1f029cedcb1",
"url": "https://github.com/nixos/nixpkgs/archive/75f4ba05c63be3f147bcc2f7bd4ba1f029cedcb1.tar.gz",
"hash": "157c64220lf825ll4c0cxsdwg7cxqdx4z559fdp7kpz0g6p8fhhr"
},
"20.03": {
"type": "Git",
"repository": {
"type": "GitHub",
"owner": "nixos",
"repo": "nixpkgs"
},
"branch": "nixos-20.03",
"revision": "1db42b7fe3878f3f5f7a4f2dc210772fd080e205",
"url": "https://github.com/nixos/nixpkgs/archive/1db42b7fe3878f3f5f7a4f2dc210772fd080e205.tar.gz",
"hash": "05k9y9ki6jhaqdhycnidnk5zrdzsdammbk5lsmsbz249hjhhgcgh"
},
"20.09": {
"type": "Git",
"repository": {
"type": "GitHub",
"owner": "nixos",
"repo": "nixpkgs"
},
"branch": "nixos-20.09",
"revision": "1c1f5649bb9c1b0d98637c8c365228f57126f361",
"url": "https://github.com/nixos/nixpkgs/archive/1c1f5649bb9c1b0d98637c8c365228f57126f361.tar.gz",
"hash": "0f2nvdijyxfgl5kwyb4465pppd5vkhqxddx6v40k2s0z9jfhj0xl"
},
"21.05": {
"type": "Git",
"repository": {
"type": "GitHub",
"owner": "nixos",
"repo": "nixpkgs"
},
"branch": "nixos-21.05",
"revision": "022caabb5f2265ad4006c1fa5b1ebe69fb0c3faf",
"url": "https://github.com/nixos/nixpkgs/archive/022caabb5f2265ad4006c1fa5b1ebe69fb0c3faf.tar.gz",
"hash": "12q00nbd7fb812zchbcnmdg3pw45qhxm74hgpjmshc2dfmgkjh4n"
},
"21.11": {
"type": "Git",
"repository": {
"type": "GitHub",
"owner": "nixos",
"repo": "nixpkgs"
},
"branch": "nixos-21.11",
"revision": "eabc38219184cc3e04a974fe31857d8e0eac098d",
"url": "https://github.com/nixos/nixpkgs/archive/eabc38219184cc3e04a974fe31857d8e0eac098d.tar.gz",
"hash": "04ffwp2gzq0hhz7siskw6qh9ys8ragp7285vi1zh8xjksxn1msc5"
},
"22.05": {
"type": "Git",
"repository": {
"type": "GitHub",
"owner": "nixos",
"repo": "nixpkgs"
},
"branch": "nixos-22.05",
"revision": "380be19fbd2d9079f677978361792cb25e8a3635",
"url": "https://github.com/nixos/nixpkgs/archive/380be19fbd2d9079f677978361792cb25e8a3635.tar.gz",
"hash": "154x9swf494mqwi4z8nbq2f0sp8pwp4fvx51lqzindjfbb9yxxv5"
},
"22.11": {
"type": "Git",
"repository": {
"type": "GitHub",
"owner": "nixos",
"repo": "nixpkgs"
},
"branch": "nixos-22.11",
"revision": "ea4c80b39be4c09702b0cb3b42eab59e2ba4f24b",
"url": "https://github.com/nixos/nixpkgs/archive/ea4c80b39be4c09702b0cb3b42eab59e2ba4f24b.tar.gz",
"hash": "1xi53rlslcprybsvrmipm69ypd3g3hr7wkxvzc73ag8296yclyll"
},
"23.05": {
"type": "Git",
"repository": {
"type": "GitHub",
"owner": "nixos",
"repo": "nixpkgs"
},
"branch": "nixos-23.05",
"revision": "70bdadeb94ffc8806c0570eb5c2695ad29f0e421",
"url": "https://github.com/nixos/nixpkgs/archive/70bdadeb94ffc8806c0570eb5c2695ad29f0e421.tar.gz",
"hash": "05cbl1k193c9la9xhlz4y6y8ijpb2mkaqrab30zij6z4kqgclsrd"
},
"23.11": {
"type": "Git",
"repository": {
"type": "GitHub",
"owner": "nixos",
"repo": "nixpkgs"
},
"branch": "nixos-23.11",
"revision": "a62e6edd6d5e1fa0329b8653c801147986f8d446",
"url": "https://github.com/nixos/nixpkgs/archive/a62e6edd6d5e1fa0329b8653c801147986f8d446.tar.gz",
"hash": "1v2yywgvd1npixjn571rrs6ijqpnzm4svf3yr2xc9n7bswla5ad1"
},
"24.05": {
"type": "Git",
"repository": {
"type": "GitHub",
"owner": "nixos",
"repo": "nixpkgs"
},
"branch": "nixos-24.05",
"revision": "805a384895c696f802a9bf5bf4720f37385df547",
"url": "https://github.com/nixos/nixpkgs/archive/805a384895c696f802a9bf5bf4720f37385df547.tar.gz",
"hash": "1q7y5ygr805l5axcjhn0rn3wj8zrwbrr0c6a8xd981zh8iccmx0p"
}
},
"version": 3
}

View File

@ -1,192 +0,0 @@
# This file has been generated by Niv.
let
#
# The fetchers. fetch_<type> fetches specs of type <type>.
#
fetch_file = pkgs: name: spec:
if spec.builtin or true then
builtins_fetchurl { inherit (spec) url sha256; name = "source"; }
else
pkgs.fetchurl { inherit (spec) url sha256; name = "source"; };
fetch_tarball = pkgs: name: spec:
if spec.builtin or true then
builtins_fetchTarball { name = "source"; inherit (spec) url sha256; }
else
pkgs.fetchzip { name = "source"; inherit (spec) url sha256; };
fetch_git = name: spec:
let
ref =
spec.ref or (
if spec ? branch then "refs/heads/${spec.branch}" else
if spec ? tag then "refs/tags/${spec.tag}" else
abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!"
);
submodules = spec.submodules or false;
submoduleArg =
let
nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0;
emptyArgWithWarning =
if submodules
then
builtins.trace
(
"The niv input \"${name}\" uses submodules "
+ "but your nix's (${builtins.nixVersion}) builtins.fetchGit "
+ "does not support them"
)
{ }
else { };
in
if nixSupportsSubmodules
then { inherit submodules; }
else emptyArgWithWarning;
in
builtins.fetchGit
({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg);
fetch_local = spec: spec.path;
fetch_builtin-tarball = name: throw
''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`.
$ niv modify ${name} -a type=tarball -a builtin=true'';
fetch_builtin-url = name: throw
''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`.
$ niv modify ${name} -a type=file -a builtin=true'';
#
# Various helpers
#
# https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695
sanitizeName = name:
(
concatMapStrings (s: if builtins.isList s then "-" else s)
(
builtins.split "[^[:alnum:]+._?=-]+"
((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name)
)
);
# The set of packages used when specs are fetched using non-builtins.
mkPkgs = sources: system:
let
sourcesNixpkgs =
import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; };
hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath;
hasThisAsNixpkgsPath = <nixpkgs> == ./.;
in
if builtins.hasAttr "nixpkgs" sources
then sourcesNixpkgs
else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then
import <nixpkgs> { }
else
abort
''
Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
add a package called "nixpkgs" to your sources.json.
'';
# The actual fetching function.
fetch = pkgs: name: spec:
if ! builtins.hasAttr "type" spec then
abort "ERROR: niv spec ${name} does not have a 'type' attribute"
else if spec.type == "file" then fetch_file pkgs name spec
else if spec.type == "tarball" then fetch_tarball pkgs name spec
else if spec.type == "git" then fetch_git name spec
else if spec.type == "local" then fetch_local spec
else if spec.type == "builtin-tarball" then fetch_builtin-tarball name
else if spec.type == "builtin-url" then fetch_builtin-url name
else
abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}";
# If the environment variable NIV_OVERRIDE_${name} is set, then use
# the path directly as opposed to the fetched source.
replace = name: drv:
let
saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name;
ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}";
in
if ersatz == "" then drv else
# this turns the string into an actual Nix path (for both absolute and
# relative paths)
if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}";
# Ports of functions for older nix versions
# a Nix version of mapAttrs if the built-in doesn't exist
mapAttrs = builtins.mapAttrs or (
f: set: with builtins;
listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set))
);
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295
range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1);
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257
stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1));
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269
stringAsChars = f: s: concatStrings (map f (stringToCharacters s));
concatMapStrings = f: list: concatStrings (map f list);
concatStrings = builtins.concatStringsSep "";
# https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331
optionalAttrs = cond: as: if cond then as else { };
# fetchTarball version that is compatible between all the versions of Nix
builtins_fetchTarball = { url, name ? null, sha256 }@attrs:
let
inherit (builtins) lessThan nixVersion fetchTarball;
in
if lessThan nixVersion "1.12" then
fetchTarball ({ inherit url; } // (optionalAttrs (name != null) { inherit name; }))
else
fetchTarball attrs;
# fetchurl version that is compatible between all the versions of Nix
builtins_fetchurl = { url, name ? null, sha256 }@attrs:
let
inherit (builtins) lessThan nixVersion fetchurl;
in
if lessThan nixVersion "1.12" then
fetchurl ({ inherit url; } // (optionalAttrs (name != null) { inherit name; }))
else
fetchurl attrs;
# Create the final "sources" from the config
mkSources = config:
mapAttrs
(
name: spec:
if builtins.hasAttr "outPath" spec
then
abort
"The values in sources.json should not have an 'outPath' attribute"
else
spec // { outPath = replace name (fetch config.pkgs name spec); }
)
config.sources;
# The "config" used by the fetchers
mkConfig =
{ sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null
, sources ? if sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile)
, system ? builtins.currentSystem
, pkgs ? mkPkgs sources system
}: rec {
# The sources, i.e. the attribute set of spec name to spec
inherit sources;
# The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers
inherit pkgs;
};
in
mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); }

View File

@ -1,20 +1,20 @@
{ writeShellApplication
, git
, niv
, npins
, nix
, ripgrep
, coreutils
, jq
}:
# add or update Nixpkgs releases using `niv`
# add or update Nixpkgs releases using `npins`
writeShellApplication {
name = "update-nixpkgs-releases";
runtimeInputs = [ git niv nix ripgrep jq coreutils ];
runtimeInputs = [ git npins nix ripgrep jq coreutils ];
text = ''
echo >&2 "Updating rolling"
niv update nixpkgs-rolling
npins update nixpkgs-rolling
echo >&2 "Updating stable releases"
niv -s nix/nixpkgs-versions.json update
npins -d nix update
echo >&2 "Adding any new releases"
# get release branches
@ -23,8 +23,8 @@ writeShellApplication {
| sort --reverse --version-sort \
| while read -r version; do
if ! jq -e --arg version "$version" 'has($ARGS.named.version)' nix/nixpkgs-versions.json >/dev/null; then
niv -s nix/nixpkgs-versions.json add nixos/nixpkgs -n "$version" -b "nixos-$version"
if ! jq -e --arg version "$version" 'has($ARGS.named.version)' nix/sources.json >/dev/null; then
npins -d nix add --name "$version" github nixos nixpkgs --branch "nixos-$version"
fi
done
'';

81
npins/default.nix Normal file
View File

@ -0,0 +1,81 @@
# Generated by npins. Do not modify; will be overwritten regularly
{ json ? ./sources.json }:
let
data = builtins.fromJSON (builtins.readFile json);
version = data.version;
mkSource =
spec:
assert spec ? type;
let
path =
if spec.type == "Git" then
mkGitSource spec
else if spec.type == "GitRelease" then
mkGitSource spec
else if spec.type == "PyPi" then
mkPyPiSource spec
else if spec.type == "Channel" then
mkChannelSource spec
else
builtins.throw "Unknown source type ${spec.type}";
in
spec // { outPath = path; };
mkGitSource =
{
repository,
revision,
url ? null,
hash,
branch ? null,
...
}:
assert repository ? type;
# At the moment, either it is a plain git repository (which has an url), or it is a GitHub/GitLab repository
# In the latter case, there we will always be an url to the tarball
if url != null then
(builtins.fetchTarball {
inherit url;
sha256 = hash; # FIXME: check nix version & use SRI hashes
})
else
assert repository.type == "Git";
let
urlToName =
url: rev:
let
matched = builtins.match "^.*/([^/]*)(\\.git)?$" repository.url;
short = builtins.substring 0 7 rev;
appendShort = if (builtins.match "[a-f0-9]*" rev) != null then "-${short}" else "";
in
"${if matched == null then "source" else builtins.head matched}${appendShort}";
name = urlToName repository.url revision;
in
builtins.fetchGit {
url = repository.url;
rev = revision;
inherit name;
# hash = hash;
};
mkPyPiSource =
{ url, hash, ... }:
builtins.fetchurl {
inherit url;
sha256 = hash;
};
mkChannelSource =
{ url, hash, ... }:
builtins.fetchTarball {
inherit url;
sha256 = hash;
};
in
if version == 3 then
builtins.mapAttrs (_: mkSource) data.pins
else
throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`"

30
npins/sources.json Normal file
View File

@ -0,0 +1,30 @@
{
"pins": {
"nixpkgs-rolling": {
"type": "Git",
"repository": {
"type": "GitHub",
"owner": "nixos",
"repo": "nixpkgs"
},
"branch": "nixpkgs-unstable",
"revision": "6132b0f6e344ce2fe34fc051b72fb46e34f668e0",
"url": "https://github.com/nixos/nixpkgs/archive/6132b0f6e344ce2fe34fc051b72fb46e34f668e0.tar.gz",
"hash": "0xh6fmkn2p8ivwqymb9gymfz07lw16fycyipgiydhxzgx6y9j7gd"
},
"poetry2nix": {
"type": "Git",
"repository": {
"type": "GitHub",
"owner": "nix-community",
"repo": "poetry2nix"
},
"branch": "master",
"revision": "fe0dcb4c9b44162a385f1170895fe6a392ed71b5",
"url": "https://github.com/nix-community/poetry2nix/archive/fe0dcb4c9b44162a385f1170895fe6a392ed71b5.tar.gz",
"hash": "0cxccm7hzcmizhbg79rdqimjndin98waibw824cmgzwwqkyzl9lv"
}
},
"version": 3
}

View File

@ -1,45 +1,48 @@
(dependency-management-niv)=
# Automatically managing remote sources with niv
(dependency-management-npins)=
# Automatically managing remote sources with `npins`
The Nix language can be used to describe dependencies between files managed by Nix.
Nix expressions themselves can depend on remote sources, and there are multiple ways to specify their origin, as shown in [](pinning-nixpkgs).
For more automation around handling remote sources, set up [niv](https://github.com/nmattia/niv/) in your project:
For more automation around handling remote sources, set up [`npins`](https://github.com/andir/npins/) in your project:
```shell-session
$ nix-shell -p niv --run "niv init --nixpkgs nixos/nixpkgs --nixpkgs-branch nixos-23.11"
$ nix-shell -p npins --run "npins init --bare; npins add github nixos nixpkgs --branch nixos-23.11"
```
This command will fetch the latest revision of the Nixpkgs 23.11 release branch.
In the current directory it will generate `nix/sources.json`, which will contain a pinned reference to the obtained revision.
It will also create `nix/sources.nix`, which exposes those dependencies as an attribute set.
In the current directory it will generate `npins/sources.json`, which will contain a pinned reference to the obtained revision.
It will also create `npins/default.nix`, which exposes those dependencies as an attribute set.
Import the generated `nix/sources.nix` as the default value for the argument to the function in `default.nix` and use it to refer to the Nixpkgs source directory:
Import the generated `npins/default.nix` as the default value for the argument to the function in `default.nix` and use it to refer to the Nixpkgs source directory:
```nix
{ sources ? import ./nix/sources.nix }:
let
pkgs = import sources.nixpkgs {};
build = pkgs.hello;
in {
inherit build;
{
sources ? import ./npins,
system ? builtins.currentSystem,
pkgs ? import sources.nixpkgs { inherit system; config = {}; overlays = []; },
}:
{
package = pkgs.hello;
}
```
`nix-build` will call the top-level function with the empty attribute set `{}`, or with the attributes passed via [`--arg`](https://nixos.org/manual/nix/stable/command-ref/nix-build#opt-arg) or [`--argstr`](https://nixos.org/manual/nix/stable/command-ref/nix-build#opt-argstr).
This pattern allows [overriding remote sources](overriding-sources-niv) programmatically.
This pattern allows [overriding remote sources](overriding-sources-npins) programmatically.
Add niv to the development environment for your project to have it readily available:
Add `npins` to the development environment for your project to have it readily available:
```diff
{ sources ? import ./nix/sources.nix }:
let
pkgs = import sources.nixpkgs {};
build = pkgs.hello;
in {
inherit build;
{
sources ? import ./npins,
system ? builtins.currentSystem,
pkgs ? import sources.nixpkgs { inherit system; config = {}; overlays = []; },
}:
-{
+rec {
package = pkgs.hello;
+ shell = pkgs.mkShellNoCC {
+ inputsFrom = [ build ];
+ inputsFrom = [ package ];
+ packages = with pkgs; [
+ niv
+ ];
@ -55,7 +58,7 @@ Also add a `shell.nix` to enter that environment more conveniently:
See [](./sharing-dependencies) for details, and note that here you have to pass an empty attribute set to the imported expression, since `default.nix` now contains a function.
(overriding-sources-niv)=
(overriding-sources-npins)=
## Overriding sources
As an example, we will use the previously created expression with an older version of Nixpkgs.
@ -66,13 +69,14 @@ Enter the development environment, create a new directory, and set up niv with a
$ nix-shell
[nix-shell]$ mkdir old
[nix-shell]$ cd old
[nix-shell]$ niv init --nixpkgs nixos/nixpkgs --nixpkgs-branch 21.11
[nix-shell]$ npins init --bare
[nix-shell]$ npins add github nixos nixpkgs --branch nixos-21.11
```
Create a file `default.nix` in the new directory, and import the original one with the `sources` just created.
```nix
import ../default.nix { sources = import ./nix/sources.nix; }
import ../default.nix { sources = import ./npins; }
```
This will result in a different version being built:
@ -86,15 +90,28 @@ hello (GNU Hello) 2.10
Sources can also be overridden on the command line:
```shell-session
nix-build .. -A build --arg sources 'import ./nix/sources.nix'
nix-build .. -A build --arg sources 'import ./npins'
```
Check the built-in help for details:
## Migrating from `niv`
A previous version of this guide recommended using [`niv`](https://github.com/nmattia/niv/), which is not maintained anymore.
If you have a project using `niv`, import remote source definitions into `npins`:
```shell-session
niv --help
npins import-niv
```
:::{warning}
All the imported entries will be updated, so they won't necessarily point to the same commits as before!
:::
## Next steps
- Check the built-in help for more information:
```shell-session
npins --help
```
- For more details and examples of the different ways to specify remote sources, see [](pinning-nixpkgs).

View File

@ -7,6 +7,6 @@
add-binary-cache.md
Automatic environments <direnv>
sharing-dependencies.md
dependency-management.md
Managing remote sources <./dependency-management.md>
Python development environment <./python-environment.md>
```

View File

@ -5,8 +5,7 @@
In various Nix examples, you'll often see references to [\<nixpkgs>](https://github.com/NixOS/nixpkgs), as follows.
```nix
{ pkgs ? import <nixpkgs> {}
}:
{ pkgs ? import <nixpkgs> {} }:
...
```
@ -39,4 +38,4 @@ When choosing a commit, it is recommended to follow either
## Next steps
- For more examples and details of the different ways to pin `nixpkgs`, see {ref}`ref-pinning-nixpkgs`.
- [](dependency-management-niv)
- [](dependency-management-npins)

View File

@ -85,13 +85,12 @@ In addition to the included file, this also prints its [file type](https://nixos
## Example project
To further experiment with the library, make a sample project.
Create a new directory, enter it,
and set up `niv` to pin the Nixpkgs dependency:
Create a new directory, enter it, and set up `npins` to pin the Nixpkgs dependency:
```shell-session
$ mkdir fileset
$ cd fileset
$ nix-shell -p niv --run "niv init --nixpkgs nixos/nixpkgs --nixpkgs-branch nixos-23.11"
$ nix-shell -p npins --run "npins init --bare; npins add github nixos nixpkgs --branch nixos-23.11"
```
Then create a `default.nix` file with the following contents: