Compare commits

..

15 commits

Author SHA1 Message Date
Raito Bezarius c2dd091bf0 debug! debug! try to print the prefetch-yarn-deps stuff
Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-03-18 23:32:53 +01:00
jade f173ccc0aa put prerelease info in the version 2024-03-18 14:26:45 -07:00
jade 4d09a927b0 bump lix to a non bork version 2024-03-18 13:18:23 -07:00
jade 7278990b5a fix: make the boehm patch content addressed to avoid rebuilds 2024-03-18 13:16:48 -07:00
jade 8b7315c5b9 nix-doc: disable plugin since it is broken by Lix API changes
We don't intend to fix the API changes in nix-doc, because we should be
able to kill nix-doc in like a week?
2024-03-16 16:30:31 -07:00
jade e61b27f3f6 Merge pull request 'Switch to the replicated forgejo, and bump lix to head' (#2) from ktemkin/nixos-module:change_url into main
Reviewed-on: #2
2024-03-09 00:30:16 -07:00
Kate Temkin ff76ec73c9 flake.lock: Update
Flake lock file updates:

• Updated input 'lix':
    'git+ssh://gerrit.lix.systems:2022/lix?ref=refs/heads/main&rev=eac76dbe90ad1ceade863744739246e9b6abaa90' (2024-03-08)
  → 'git+ssh://git@git.lix.systems/lix-project/lix.git?ref=refs/heads/main&rev=896e525681bbf696c330af4e51c5e161d3818350' (2024-03-09)
2024-03-09 00:24:17 -07:00
Kate Temkin c88abb52dc lix: switch to forgejo (replicated) clone addr 2024-03-09 00:23:44 -07:00
Raito Bezarius 89ccd6e015 fix: pin nixos-option to upstream
Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-03-09 02:27:21 +01:00
jade 7083c47d04 Merge pull request 'feat: introduce our own flake-compat' (#1) from flake-compat into main
Reviewed-on: #1
2024-03-08 18:11:31 -07:00
Raito Bezarius d2b5d0a958 feat: introduce our own flake-compat
Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-03-09 01:48:11 +01:00
Jade Lovelace a312274b08 fake version 2024-03-08 00:10:56 -08:00
Jade Lovelace 5ca6ed5690 fix git-requiring tests 2024-03-08 00:05:25 -08:00
Jade Lovelace c4615ccc7f fix version 2024-03-07 23:49:29 -08:00
Jade Lovelace 9ed607358a update lix 2024-03-07 23:43:21 -08:00
14 changed files with 107 additions and 521 deletions

2
.gitignore vendored
View file

@ -1,2 +0,0 @@
result
result-*

19
LICENSE
View file

@ -1,19 +0,0 @@
MIT License
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 (including the next
paragraph) 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.

View file

@ -1,79 +0,0 @@
# Lix NixOS module
See the [official installation guide][install-guide] for details on usage of
release versions.
[install-guide]: https://lix.systems/install/
See the [beta guide][beta-guide] for a setup guide on how to use HEAD:
[beta-guide]: https://wiki.lix.systems/link/1
## What does this do?
This is an overlay wrapped in a NixOS module that will replace CppNix with Lix
in nixpkgs. This is useful so that `nixos-rebuild`, `nix-direnv` and similar
will use Lix.
Optionally, it can build Lix from source.
## Versioning with Lix
The version of this overlay should match the major Lix version, *and* if
running HEAD, it should be the latest available version of the overlay.
Changes breaking the overlay are shamelessly done on HEAD, and we expect people
doing such changes to have prepared corresponding fix commits to make to the
overlay immediately after submitting their changes. If your build randomly
broke when updating HEAD, try updating your overlay.
The version of Lix pinned in this flake's `flake.lock` is a version of Lix
that is expected to work, however if running HEAD, it can be assumed to work
with HEAD as well if both `lix-nixos-module` and `lix` are the latest version.
## Common pitfalls
Various flake frameworks such as flake-parts and snowfall (and possibly Colmena
in the future if they do a similar optimization) manage overlays separately
from NixOS, since they provide `pkgs` pre-imported to NixOS. This saves a
couple of seconds of evaluation time and resources, but it means that the NixOS
option `nixpkgs.overlays` **is completely ignored** on these frameworks.
If you are using such a framework, add `overlays.default` to the overlays list
for said framework.
## Flake structure and usage
The flake here has two inputs of note:
- `nixpkgs`, *which is unused for most people*. It is purely used for `checks`
in developing `lix-nixos-module` itself.
The installation instructions make it `follows` to make `flake.lock` less
confusing, but it is nonetheless unused.
- `lix`, which determines the version of Lix to do source builds for, if doing
source builds.
These are the most relevant outputs for most people:
- `nixosModules.lixFromNixpkgs` - uses Lix from nixpkgs and installs the
overlay to use Lix on a NixOS system. This is only useful for a stable
version of Lix, and cannot be used for running HEAD.
- `nixosModules.default` - uses Lix from source and installs the overlay to use
Lix on a NixOS system.
- `overlays.lixFromNixpkgs` - overlay to use Lix from nixpkgs in place of Nix.
- `overlays.default` - overlay to use Lix from source in place of Nix.
## Non-flake usage
Import `module.nix` or `overlay.nix` as desired, with the arguments `lix`
(derivation-like attribute set with the Lix sources, or `null` to use Lix from
nixpkgs) and `versionSuffix` (optional string).
It's desirable to also include a `versionSuffix` like the following while
building HEAD from source, to have `nix --version` include date and commit
information. To get such metadata, it depends on which pinning system is in
use, but `builtins.fetchGit` will provide the necessary metadata for the
following to work:
```
versionSuffix = "pre${builtins.substring 0 8 lix.lastModifiedDate}-${lix.shortRev or lix.dirtyShortRev}";
```

10
default.nix Normal file
View file

@ -0,0 +1,10 @@
(import
(
let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
fetchTarball {
url = lock.nodes.flake-compat.locked.url or "https://git.lix.systems/lix-project/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
)
{ src = ./.; }
).defaultNix

View file

@ -1,15 +1,30 @@
{
"nodes": {
"flake-compat": {
"locked": {
"lastModified": 1696426674,
"narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
"ref": "refs/heads/master",
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"revCount": 57,
"type": "git",
"url": "ssh://git@git.lix.systems/lix-project/flake-compat"
},
"original": {
"type": "git",
"url": "ssh://git@git.lix.systems/lix-project/flake-compat"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"lastModified": 1709126324,
"narHash": "sha256-q6EQdSeUZOG26WelxqkmR7kArjgWCdw5sfJVHPH/7j8=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"rev": "d465f4819400de7c8d874d50b982301f28a84605",
"type": "github"
},
"original": {
@ -18,42 +33,29 @@
"type": "github"
}
},
"flakey-profile": {
"locked": {
"lastModified": 1712898590,
"narHash": "sha256-FhGIEU93VHAChKEXx905TSiPZKga69bWl1VB37FK//I=",
"owner": "lf-",
"repo": "flakey-profile",
"rev": "243c903fd8eadc0f63d205665a92d4df91d42d9d",
"type": "github"
},
"original": {
"owner": "lf-",
"repo": "flakey-profile",
"type": "github"
}
},
"lix": {
"flake": false,
"locked": {
"lastModified": 1723511168,
"narHash": "sha256-XDcqLVPcsMhORerIPuQ1XNALtDvG6QRA2dKyNrccXyg=",
"rev": "f9a3bf6ccccf8ac6b1604c1a2980e3a565ae4f44",
"type": "tarball",
"url": "https://git.lix.systems/api/v1/repos/lix-project/lix/archive/f9a3bf6ccccf8ac6b1604c1a2980e3a565ae4f44.tar.gz?rev=f9a3bf6ccccf8ac6b1604c1a2980e3a565ae4f44"
"lastModified": 1710788611,
"narHash": "sha256-nBiCx4mfntmJNv1MxVS3KmDeFzusxWC4ZdwKCT4noQw=",
"ref": "refs/heads/main",
"rev": "f256e3c5c69c7aa658ff6e8fd9c05063a1e9ace6",
"revCount": 15196,
"type": "git",
"url": "ssh://git@git.lix.systems/lix-project/lix.git"
},
"original": {
"type": "tarball",
"url": "https://git.lix.systems/lix-project/lix/archive/main.tar.gz"
"type": "git",
"url": "ssh://git@git.lix.systems/lix-project/lix.git"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1723175592,
"narHash": "sha256-M0xJ3FbDUc4fRZ84dPGx5VvgFsOzds77KiBMW/mMTnI=",
"lastModified": 1709703039,
"narHash": "sha256-6hqgQ8OK6gsMu1VtcGKBxKQInRLHtzulDo9Z5jxHEFY=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "5e0ca22929f3342b19569b21b2f3462f053e497b",
"rev": "9df3e30ce24fd28c7b3e2de0d986769db5d6225d",
"type": "github"
},
"original": {
@ -65,8 +67,8 @@
},
"root": {
"inputs": {
"flake-compat": "flake-compat",
"flake-utils": "flake-utils",
"flakey-profile": "flakey-profile",
"lix": "lix",
"nixpkgs": "nixpkgs"
}

View file

@ -1,34 +1,18 @@
{
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
inputs.lix = {
url = "https://git.lix.systems/lix-project/lix/archive/main.tar.gz";
url = "git+ssh://git@git.lix.systems/lix-project/lix.git";
flake = false;
};
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.flakey-profile.url = "github:lf-/flakey-profile";
inputs.flake-compat.url = "git+ssh://git@git.lix.systems/lix-project/flake-compat";
outputs = inputs@{ self, nixpkgs, lix, flake-utils, flakey-profile, ... }:
let
lixVersionJson = builtins.fromJSON (builtins.readFile (lix + "/version.json"));
versionSuffix = nixpkgs.lib.optionalString (!lixVersionJson.official_release)
"-pre${builtins.substring 0 8 lix.lastModifiedDate}-${lix.shortRev or lix.dirtyShortRev}";
in
{
outputs = inputs@{ self, nixpkgs, lix, flake-utils, ... }: {
inherit inputs;
nixosModules = {
# Use a locally built Lix
default = import ./module.nix { inherit lix versionSuffix; };
# Use Lix from nixpkgs
lixFromNixpkgs = import ./module.nix { lix = null; };
};
overlays = {
# Use a locally built Lix
default = import ./overlay.nix { inherit lix versionSuffix; };
# Use Lix from nixpkgs
lixFromNixpkgs = import ./overlay.nix { lix = null; };
nixosModules.default = import ./module.nix { inherit lix; };
overlays.default = import ./overlay.nix {
inherit lix;
versionSuffix = "pre${builtins.substring 0 8 lix.lastModifiedDate}-${lix.shortRev}";
};
} // flake-utils.lib.eachDefaultSystem (system:
let
@ -36,30 +20,10 @@
inherit system;
overlays = [ self.overlays.default ];
};
linux64BitSystems = [
"x86_64-linux"
"aarch64-linux"
];
inherit (pkgs) lib;
in
{
inherit pkgs;
packages = {
default = pkgs.nixVersions.nix_2_18;
inherit (pkgs) nix-doc nix-eval-jobs;
};
packages.system-profile = import ./system-profile.nix { inherit pkgs flakey-profile; };
nixosTests = pkgs.recurseIntoAttrs (pkgs.callPackage ./test-nixos.nix { inherit pkgs; lix-module = self.nixosModules.default; });
checks = {
inherit (self.packages.${system}) default nix-eval-jobs;
} // lib.optionalAttrs (lib.elem system linux64BitSystems) {
# wrongMajor intentionally not included here since it is expected to fail
inherit (self.nixosTests.${system}) it-builds;
};
packages.default = pkgs.nixVersions.nix_2_18;
packages.nix-doc = pkgs.nix-doc;
});
}

View file

@ -1,5 +1,5 @@
{ lix, versionSuffix ? "" }:
{ lix }:
{ pkgs, config, ... }:
{
nixpkgs.overlays = [ (import ./overlay.nix { inherit lix versionSuffix; }) ];
nixpkgs.overlays = [ (import ./overlay.nix { inherit lix; }) ];
}

View file

@ -1,105 +1,52 @@
{ lix, versionSuffix ? "" }:
final: prev:
let
# This is kind of scary to not override the nix version to pretend to be
# 2.18 since nixpkgs can introduce new breakage in its Nix unstable CLI
# usage.
# https://github.com/nixos/nixpkgs/blob/6afb255d976f85f3359e4929abd6f5149c323a02/nixos/modules/config/nix.nix#L121
lixPackageFromSource = final.callPackage (lix + "/package.nix") ({
inherit versionSuffix;
});
boehmgc-patched = ((final.boehmgc.override {
enableLargeConfig = true;
}).overrideAttrs (o: {
patches = (o.patches or [ ]) ++ [
# for clown reasons this version is newer than the one in lix, we should
# fix this and update our nixpkgs pin
(prev.path + "/pkgs/tools/package-management/nix/patches/boehmgc-coroutine-sp-fallback.patch")
# These packages depend on Nix features that Lix does not support
overridelist_2_18 = [
"attic-client"
"devenv"
"nix-du"
"nix-init"
"nix-prefetch-git"
"nixos-option"
"nurl"
"prefetch-yarn-deps" # force these onto upstream so we are not regularly rebuilding electron
# https://github.com/ivmai/bdwgc/pull/586
(builtins.path { path = lix + "/boehmgc-traceable_allocator-public.diff"; name = "boehmgc-traceable_allocator-public.patch"; })
];
override_2_18 = prev.lib.genAttrs overridelist_2_18 (
name: prev.${name}.override {
nix = final.nixVersions.nix_2_18_upstream;
}
})
);
inherit (prev) lib;
csi = builtins.fromJSON ''"\u001b"'';
orange = "${csi}[35;1m";
normal = "${csi}[0m";
warning = ''
${orange}warning${normal}: You have the lix overlay included into a nixpkgs import twice,
perhaps due to the NixOS module being included twice, or because of using
pkgs.nixos and also including it in imports, or perhaps some unknown
machinations of a complicated flake library.
This is completely harmless since we have no-op'd the second one if you are
seeing this message, but it would be a small style improvement to fix
it :)
P.S. If you had some hack to fix nixos-option build failures in your
configuration, that was caused by including an older version of the lix
overlay twice, which is now mitigated if you see this message, so you can
delete that.
P.P.S. This Lix has super catgirl powers.
'';
wrongMajorWarning = ''
${orange}warning${normal}: This Lix NixOS module is being built against a Lix with a
major version (got ${lixPackageToUse.version}) other than the one the
module was designed for (expecting ${supportedLixMajor}). Some downstream
packages like nix-eval-jobs may be broken by this. Consider using a
matching version of the Lix NixOS module to the version of Lix you are
using.
'';
maybeWarnDuplicate = x: if final.lix-overlay-present > 1 then builtins.trace warning x else x;
versionJson = builtins.fromJSON (builtins.readFile ./version.json);
supportedLixMajor = lib.versions.majorMinor versionJson.version;
lixPackageToUse = if lix != null then lixPackageFromSource else prev.lix;
# Especially if using Lix from nixpkgs, it is plausible that the overlay
# could be used against the wrong Lix major version and cause confusing build
# errors. This is a simple safeguard to put in at least something that might be seen.
maybeWarnWrongMajor = x: if !(lib.hasPrefix supportedLixMajor lixPackageToUse.version) then builtins.trace wrongMajorWarning x else x;
overlay = override_2_18 // {
lix-overlay-present = 1;
# used for things that one wouldn't necessarily want to update, but we
# nevertheless shove it in the overlay and fixed-point it in case one *does*
# want to do that.
lix-sources = import ./pins.nix;
lix = maybeWarnWrongMajor (maybeWarnDuplicate lixPackageToUse);
in
{
nixVersions = prev.nixVersions // rec {
nix_2_18 = final.lix;
# FIXME: do something less scuffed
nix_2_18 = (prev.nixVersions.nix_2_18.override { boehmgc = boehmgc-patched; }).overrideAttrs (old: {
src = lix;
# FIXME: fake version so that nixpkgs will not try to use nix config >_>
version = "2.18.3-lix${versionSuffix}";
VERSION_SUFFIX = "-lix${versionSuffix}";
patches = [ ];
# FIXME: we don't know why this was not being picked up properly when
# included in nativeCheckInputs.
nativeBuildInputs = old.nativeBuildInputs or [ ] ++ [ final.git ];
});
stable = nix_2_18;
nix_2_18_upstream = prev.nixVersions.nix_2_18;
};
nix-eval-jobs = (prev.nix-eval-jobs.override {
# lix
nix = final.nixVersions.nix_2_18;
}).overrideAttrs (old:
let src = final.lix-sources.nix-eval-jobs;
in {
version = "2.92.0-lix-${builtins.substring 0 7 src.rev}";
# force these onto upstream so we are not regularly rebuilding electron
prefetch-yarn-deps = (final.lib.trace "overriding: ${toString (builtins.attrNames prev.prefetch-yarn-deps)}" prev.prefetch-yarn-deps).override {
nix = final.nixVersions.nix_2_18_upstream;
};
prefetch-npm-deps = prev.prefetch-npm-deps.override {
nix = final.nixVersions.nix_2_18_upstream;
};
nix-prefetch-git = prev.nix-prefetch-git.override {
nix = final.nixVersions.nix_2_18_upstream;
};
# FIXME: should this be patches instead?
inherit src;
mesonBuildType = "debugoptimized";
ninjaFlags = old.ninjaFlags or [ ] ++ [ "-v" ];
}
);
nixos-option = prev.nixos-option.override {
nix = final.nixVersions.nix_2_18_upstream;
};
nix-doc = prev.callPackage ./nix-doc/package.nix { withPlugin = false; };
};
in
# Make the overlay idempotent, since flakes passing nixos modules around by
# value and many other things make it way too easy to include the overlay
# twice
if (prev ? lix-overlay-present) then { lix-overlay-present = 2; } else overlay
}

View file

@ -1 +0,0 @@
{"nix-eval-jobs": {"kind": "tarball", "rev": "f8869bdcca7c1d5aaf37de3da3a4176811279a57", "nar_hash": "sha256-F/RvI9chHywnckEqHO1ggjzCayknhDnnl2kNnnVXpWg=", "locked_url": "https://git.lix.systems/api/v1/repos/lix-project/nix-eval-jobs/archive/f8869bdcca7c1d5aaf37de3da3a4176811279a57.tar.gz?rev=f8869bdcca7c1d5aaf37de3da3a4176811279a57", "url": "https://git.lix.systems/lix-project/nix-eval-jobs/archive/main.tar.gz"}}

View file

@ -1,26 +0,0 @@
# this is a custom pinning tool, written because npins doesn't have narHash
# compatible output for git inputs, and also doesn't support the Nix immutable
# tarball protocol
let
pins = builtins.fromJSON (builtins.readFile ./pins.json);
fetchPin = args@{ kind, ... }:
if kind == "git" then
builtins.fetchGit
{
name = "source";
url = args.url;
ref = args.ref;
rev = args.rev;
narHash = args.nar_hash;
}
else if kind == "tarball" then
args // {
outPath = builtins.fetchTarball {
name = "source";
url = args.locked_url;
sha256 = args.nar_hash;
};
}
else builtins.throw "unsupported input type ${kind}";
in
builtins.mapAttrs (_: fetchPin) pins

View file

@ -1,10 +0,0 @@
{ pkgs, flakey-profile }:
flakey-profile.lib.mkProfile {
inherit pkgs;
paths = with pkgs; [
cacert
nix
];
name = "system-profile";
extraSwitchArgs = [ "--profile" "/nix/var/nix/profiles/default" ];
}

View file

@ -1,32 +0,0 @@
{ pkgs, nixos, lix-module }:
let
pkgs' = import pkgs.path {
inherit (pkgs) system;
};
configs = {
it-builds = nixos ({ ... }: {
imports = [ lix-module ];
documentation.enable = false;
fileSystems."/".device = "ignore-root-device";
boot.loader.grub.enable = false;
system.stateVersion = "24.05";
});
# Intentionally provoke the wrong major version.
# Does assume that the module is one major ahead of the release; the main
# purpose here is a manual testing fixture.
wrongMajor = pkgs'.nixos ({ ... }: {
imports = [ (import ./module.nix { lix = null; }) ];
documentation.enable = false;
fileSystems."/".device = "ignore-root-device";
boot.loader.grub.enable = false;
system.stateVersion = "24.05";
});
};
in
{
inherit configs;
it-builds = configs.it-builds.config.system.build.toplevel;
wrongMajor = configs.wrongMajor.config.system.build.toplevel;
}

View file

@ -1,165 +0,0 @@
#!/usr/bin/env nix-shell
#!nix-shell -i python3 -p 'python3.withPackages (ps: [ ps.requests ])'
"""
Updates pins in this repo to their latest version.
This is a custom pinning tool, written because npins doesn't have narHash
compatible output for git inputs (it is not SRI), and also doesn't support the
Nix immutable tarball protocol which we would like to use when we become public.
"""
import subprocess
import tempfile
from pathlib import Path
import re
import dataclasses
from typing import Literal
import urllib.parse
import json
# https://stackoverflow.com/a/51286749
class DataclassJSONEncoder(json.JSONEncoder):
def default(self, o):
if dataclasses.is_dataclass(o):
return dataclasses.asdict(o)
return super().default(o)
@dataclasses.dataclass
class PinSerialized:
kind: str
rev: str | None
nar_hash: str
@dataclasses.dataclass
class GitPinSerialized(PinSerialized):
kind: Literal['git']
url: str
rev: str
ref: str
@dataclasses.dataclass
class TarballPinSerialized(PinSerialized):
kind: Literal['tarball']
locked_url: str
url: str
class PinSpec:
def do_pin(self) -> dict[str, str]:
raise ValueError('unimplemented')
@dataclasses.dataclass
class GitPinSpec(PinSpec):
url: str
branch: str
def do_pin(self) -> GitPinSerialized:
return lock_git(self.url, self.branch)
@dataclasses.dataclass
class TarballPinSpec(PinSpec):
url: str
def do_pin(self) -> TarballPinSerialized:
return lock_tarball(self.url)
@dataclasses.dataclass
class LinkHeader:
url: str
rev: str | None
LINK_HEADER_RE = re.compile(r'<(?P<url>.*)>; rel="immutable"')
def parse_link_header(header) -> LinkHeader | None:
matched = LINK_HEADER_RE.match(header)
if not matched:
return None
url = matched.group('url')
parsed_url = urllib.parse.urlparse(url)
parsed_qs = urllib.parse.parse_qs(parsed_url.query)
return LinkHeader(url=url, rev=next(iter(parsed_qs.get('rev', [])), None))
def lock_tarball(url) -> TarballPinSerialized:
"""
Prefetches a tarball using the Nix immutable tarball protocol
"""
import requests
resp = requests.get(url)
with tempfile.TemporaryDirectory() as td:
td = Path(td)
proc = subprocess.Popen(["tar", "-C", td, "-xvzf", "-"],
stdin=subprocess.PIPE)
assert proc.stdin
for chunk in resp.iter_content(64 * 1024):
proc.stdin.write(chunk)
proc.stdin.close()
if proc.wait() != 0:
raise RuntimeError("untarring failed")
children = list(td.iterdir())
# FIXME: allow different tarball structures
assert len(children) == 1
child = children[0].rename(children[0].parent.joinpath('source'))
sri_hash = subprocess.check_output(
["nix-hash", "--type", "sha256", "--sri", child]).decode().strip()
path = subprocess.check_output(
["nix-store", "--add-fixed", "--recursive", "sha256",
child]).decode().strip()
link_info = parse_link_header(resp.headers['Link'])
print(sri_hash, path)
return TarballPinSerialized(kind='tarball',
nar_hash=sri_hash,
locked_url=link_info.url if link_info else url,
rev=link_info.rev if link_info else None,
url=url)
def lock_git(url, branch) -> GitPinSerialized:
url_escaped = json.dumps(url)
ref_escaped = json.dumps(branch)
data = json.loads(
subprocess.check_output([
"nix", "eval", "--impure", "--json", "--expr",
f"builtins.removeAttrs (builtins.fetchGit {{ url = {url_escaped}; ref = {ref_escaped}; }}) [ \"outPath\" ]"
]).strip())
return GitPinSerialized(kind='git',
url=url,
rev=data['rev'],
ref=branch,
nar_hash=data['narHash'])
PINS = {
'nix-eval-jobs':
TarballPinSpec('https://git.lix.systems/lix-project/nix-eval-jobs/archive/main.tar.gz')
}
def main():
output = {}
for (name, pin) in PINS.items():
output[name] = pin.do_pin()
print(output)
with open('pins.json', 'w') as fh:
json.dump(output, fh, cls=DataclassJSONEncoder)
if __name__ == '__main__':
main()

View file

@ -1,3 +0,0 @@
{
"version": "2.92.0-dev"
}