Compare commits

..

35 commits
main ... main

Author SHA1 Message Date
Ilya K f425f32a62 Rename nix-doc to lix-doc here too
Fixes build
2024-04-08 11:15:34 +03:00
jade 93ce1e3f5d Merge pull request 'overlay: fix builds of Lix after c21d11ac0' (#12) from qyriad/nixos-module:fixes/python-dep into main
Reviewed-on: #12
2024-04-06 04:30:25 +00:00
Qyriad 1b35b90445 overlay: fix builds of Lix after c21d11ac0
lix-project/lix/c21d11ac094d4f39215dba6763fcabc62341def4 added a direct
build dependency on Python.
2024-04-05 22:20:24 -06:00
jade 9515bc250a Merge pull request 'overlay: support nix-doc integration into Lix' (#11) from feature/nix-doc into main
Reviewed-on: #11
2024-04-03 22:48:05 +00:00
Lunaphied 54cc0918d4 overlay: support nix-doc integration into Lix 2024-04-03 15:55:27 -06:00
jade 2714f7ac02 Merge pull request 'Add LICENSE' (#10) from jade/license into main
Reviewed-on: #10
2024-04-03 20:08:18 +00:00
jade 48055468d5 Add LICENSE 2024-04-02 13:21:56 -07:00
jade a428fa24ae probably fix cross compilation 2024-04-02 00:41:06 -07:00
jade 9c691a4185 Merge pull request 'fix: pin nurl to upstream nix' (#9) from mweinelt/nixos-module:nurl-pin into main
Reviewed-on: #9
2024-03-29 07:16:53 +00:00
hexa 600fc154e4
fix: pin nurl to upstream nix
nix-init depends on nurl, so they need to use the same nix for nix-init
to not be rebuilt.
2024-03-29 02:27:19 +01:00
eldritch horrors 280c404856 flake.lock: update 2024-03-28 18:32:40 +01:00
eldritch horrors eabed5a04f fix: add cmake and toml11 to inputs
toml11 is needed anyway, cmake is only needed for meson. meson isn't
needed right now but let's not have this cause problems *again* soon
2024-03-28 18:32:00 +01:00
jade 5d64b01d02 Merge pull request 'fix: pin nix-init to upstream nix' (#8) from mweinelt/nixos-module:nix-init-pin into main
Reviewed-on: #8
2024-03-27 08:07:07 +00:00
hexa 7afd8fbb0d
fix: pin nix-init to upstream nix 2024-03-27 05:54:26 +01:00
jade 5d2b325d3a flake.lock: Update
Flake lock file updates:

• Updated input 'lix':
    'git+ssh://git@git.lix.systems/lix-project/lix.git?ref=refs/heads/main&rev=66ccc93eeded1ab77281600bd41d6b0d8d8bf43a' (2024-03-25)
  → 'git+ssh://git@git.lix.systems/lix-project/lix.git?ref=refs/heads/main&rev=0be766c12de6badbbfa4fb9f76b6688b04d81059' (2024-03-25)
2024-03-25 13:45:09 -07:00
jade 1062d3c1ff Add version suffix in nixos module 2024-03-25 13:44:56 -07:00
jade f8b5d0bc9c flake.lock: Update
Flake lock file updates:

• Updated input 'lix':
    'git+ssh://git@git.lix.systems/lix-project/lix.git?ref=refs/heads/main&rev=d26eccebfc1f0d3f5b77e781ffc6455f05f8f90c' (2024-03-24)
  → 'git+ssh://git@git.lix.systems/lix-project/lix.git?ref=refs/heads/main&rev=66ccc93eeded1ab77281600bd41d6b0d8d8bf43a' (2024-03-25)
2024-03-24 21:32:14 -07:00
Qyriad adbbecb518 Merge pull request 'Add gitignore' (#6) from emilytrau/nixos-module:emilytrau/gitignore into main
Reviewed-on: #6
2024-03-25 03:03:56 +00:00
Emily Trau ebdf6e66ae Add gitignore 2024-03-25 13:57:03 +11:00
jade 30a7b8f7c8 Update lix and add system profile 2024-03-24 17:17:53 -07:00
jade 41990c5d80 Add system profile 2024-03-24 17:14:18 -07: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 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 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
10 changed files with 120 additions and 486 deletions

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": 1726560853,
"narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=",
"lastModified": 1709126324,
"narHash": "sha256-q6EQdSeUZOG26WelxqkmR7kArjgWCdw5sfJVHPH/7j8=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a",
"rev": "d465f4819400de7c8d874d50b982301f28a84605",
"type": "github"
},
"original": {
@ -20,11 +35,11 @@
},
"flakey-profile": {
"locked": {
"lastModified": 1712898590,
"narHash": "sha256-FhGIEU93VHAChKEXx905TSiPZKga69bWl1VB37FK//I=",
"lastModified": 1711325813,
"narHash": "sha256-ygJR5VikyCfK0CUJHboOKJVr6s9HQ1RXcvFEFnv+KIk=",
"owner": "lf-",
"repo": "flakey-profile",
"rev": "243c903fd8eadc0f63d205665a92d4df91d42d9d",
"rev": "3b32c4a71f89b874fe0be2dc125eacb9c3473204",
"type": "github"
},
"original": {
@ -36,24 +51,26 @@
"lix": {
"flake": false,
"locked": {
"lastModified": 1727712632,
"narHash": "sha256-7kaZRZCWG8PmxwIDTVKjJo3VtAGDun7mqfAMlucQbdQ=",
"rev": "a16ceb9411c57993d811c6bebb517742fe3d34e3",
"type": "tarball",
"url": "https://git.lix.systems/api/v1/repos/lix-project/lix/archive/a16ceb9411c57993d811c6bebb517742fe3d34e3.tar.gz?rev=a16ceb9411c57993d811c6bebb517742fe3d34e3"
"lastModified": 1712180067,
"narHash": "sha256-XU32CuKt0wXB8Ws5P3pZFMlYIMVx9om1GycYpITAwZ0=",
"ref": "refs/heads/main",
"rev": "89c31953c58d8089c85ae7ab43a5c59bb0f9f69b",
"revCount": 15311,
"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": 1727634051,
"narHash": "sha256-S5kVU7U82LfpEukbn/ihcyNt2+EvG7Z5unsKW9H/yFA=",
"lastModified": 1709703039,
"narHash": "sha256-6hqgQ8OK6gsMu1VtcGKBxKQInRLHtzulDo9Z5jxHEFY=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "06cf0e1da4208d3766d898b7fdab6513366d45b9",
"rev": "9df3e30ce24fd28c7b3e2de0d986769db5d6225d",
"type": "github"
},
"original": {
@ -65,6 +82,7 @@
},
"root": {
"inputs": {
"flake-compat": "flake-compat",
"flake-utils": "flake-utils",
"flakey-profile": "flakey-profile",
"lix": "lix",

View file

@ -1,66 +1,31 @@
{
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.flake-compat.url = "git+ssh://git@git.lix.systems/lix-project/flake-compat";
inputs.flakey-profile.url = "github:lf-/flakey-profile";
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
{
let versionSuffix = "pre${builtins.substring 0 8 lix.lastModifiedDate}-${lix.shortRev}";
in {
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 versionSuffix; };
overlays.default = import ./overlay.nix { inherit lix versionSuffix; };
} // flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlays.default ];
};
linux64BitSystems = [
"x86_64-linux"
"aarch64-linux"
];
inherit (pkgs) lib;
in
{
inherit pkgs;
packages = {
default = pkgs.nix;
inherit (pkgs) nix-doc nix-eval-jobs;
};
packages.default = pkgs.nixVersions.nix_2_18;
packages.nix-doc = pkgs.nix-doc;
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;
inherit (pkgs) nixos-option;
} // lib.optionalAttrs (lib.elem system linux64BitSystems) {
# wrongMajor intentionally not included here since it is expected to fail
inherit (self.nixosTests.${system}) it-builds;
};
});
}

View file

@ -1,127 +1,74 @@
{ lix, versionSuffix ? "" }:
final: prev:
let
lixPackageFromSource = final.callPackage (lix + "/package.nix") ({
inherit versionSuffix;
stdenv = final.clangStdenv;
});
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 should receive CppNix since they may link to it or otherwise
# cause problems (or even just silly mass-rebuilds) if we give them Lix
overridelist_upstream = [
"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"; })
];
})
);
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;
# It is not enough to *just* throw whatever the default nix version is at
# anything in the "don't give lix" list, we have to *also* ensure that we
# give whatever upstream version as specified in the callPackage invocation.
#
# Unfortunately I don't think there is any actual way to directly query that,
# so we instead do something extremely evil and guess which version it
# probably was. This code is not generalizable to arbitrary derivations, so
# it will hopefully not make us cry, at least.
useCppNixOverlay =
lib.genAttrs overridelist_upstream (
name:
if (lib.functionArgs prev.${name}.override ? "nix") then
let
# Get the two common inputs of a derivation/package.
inputs = prev.${name}.buildInputs ++ prev.${name}.nativeBuildInputs;
nixDependency = lib.findFirst
(drv: (drv.pname or "") == "nix")
final.nixVersions.stable_upstream # default to stable nix if nix is not an input
inputs;
nixMajor = lib.versions.major (nixDependency.version or "");
nixMinor = lib.versions.minor (nixDependency.version or "");
nixAttr = "nix_${nixMajor}_${nixMinor}";
finalNix = final.nixVersions.${nixAttr};
in
prev.${name}.override {
nix = finalNix;
}
else prev.${name}
);
overlay = useCppNixOverlay // {
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);
nixVersions = prev.nixVersions // {
stable = final.lix;
stable_upstream = prev.nixVersions.stable;
};
nix-eval-jobs = (prev.nix-eval-jobs.override {
# lix
nix = final.lix;
}).overrideAttrs (old:
let src = final.lix-sources.nix-eval-jobs;
in {
version = "2.92.0-lix-${builtins.substring 0 7 src.rev}";
# FIXME: should this be patches instead?
inherit src;
mesonBuildType = "debugoptimized";
ninjaFlags = old.ninjaFlags or [ ] ++ [ "-v" ];
}
);
nix-doc = prev.callPackage ./nix-doc/package.nix { withPlugin = false; };
};
# Internal nix-doc used by Lix.
lix-doc = final.callPackage (lix + "/lix-doc/package.nix") { };
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
{
nixVersions = prev.nixVersions // rec {
# 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}";
# We only include CMake so that Meson can locate toml11, which only ships CMake dependency metadata.
dontUseCmakeConfigure = true;
patches = [ ];
buildInputs = old.buildInputs or [ ] ++ [
final.toml11
lix-doc
];
nativeBuildInputs = old.nativeBuildInputs or [ ] ++ [
final.buildPackages.cmake
# FIXME: we don't know why this was not being picked up properly when
# included in nativeCheckInputs.
final.buildPackages.git
final.buildPackages.python3
];
});
stable = nix_2_18;
nix_2_18_upstream = prev.nixVersions.nix_2_18;
};
# force these onto upstream so we are not regularly rebuilding electron
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;
};
nixos-option = prev.nixos-option.override {
nix = final.nixVersions.nix_2_18_upstream;
};
nix-doc = prev.callPackage ./nix-doc/package.nix { withPlugin = false; };
nix-init = prev.nix-init.override {
nix = final.nixVersions.nix_2_18_upstream;
};
nurl = prev.nurl.override {
nix = final.nixVersions.nix_2_18_upstream;
};
}

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,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"
}