Skip to content

Add support for apk builds in snapshot release #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/cache/** linguist-generated=true
25 changes: 11 additions & 14 deletions .github/workflows/update-hashes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,24 @@ jobs:
echo "GIT_AUTHOR_EMAIL=<github-actions[bot]@users.noreply.github.com>" >> $GITHUB_ENV
echo "GIT_COMMITTER_NAME=github-actions[bot]" >> $GITHUB_ENV
echo "GIT_COMMITTER_EMAIL=<github-actions[bot]@users.noreply.github.com>" >> $GITHUB_ENV
- name: Update all hashes
shell: bash
run: |
git rm hashes/*.nix
nix run .#generate-all-hashes
git add hashes/*.nix
git commit -m "hashes: update"
- name: Update latest release
shell: bash
run: |
nix run .#generate-latest-release
git add latest-release.nix
nix run .#list-releases -- -u
git add cache
git commit -m "latest-release: update" || true
- name: Update all hashes
shell: bash
run: |
git rm -r hashes || true
git rm -r cache || true
nix run .#generate-all-hashes -- -ur
git add cache
git commit -m "hashes: update"
- name: Cache OpenWrt profile information
shell: bash
run: |
git rm cached-profiles/*
mkdir -p cached-profiles
nix build -vL .#cached-profiles
cp -L result/*.nix cached-profiles/
git add cached-profiles
git rm -r cached-profiles || true
git commit -m "cached-profiles: update" || true
- name: Push changes
uses: ad-m/github-push-action@master
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/result*
/cache/**/*.tmp
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ in
## Refreshing hashes

**downloads.openwrt.org** appears to be never at rest. That's why we
update the [hashes subdirectory](./hashes/) daily with [a Github
update the [cache subdirectory](./cache/) daily with [a Github
action.](https://github.com/astro/nix-openwrt-imagebuilder/actions/workflows/update-hashes.yml)

If you still encounter `hash mismatch in fixed-output derivation` in
between these updates, update them yourself:

```bash
nix run .#generate-hashes $(sed -e 's/"//g' latest-release.nix)
nix run .#release2nix -- $(nix run .#list-versions -- -l)
```

If your `flake.nix` has this project in its `inputs`, then you can
Expand Down
49 changes: 49 additions & 0 deletions apk-tools.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{ lib, stdenv, fetchFromGitLab, meson, ninja, pkg-config, scdoc
, openssl, zlib, zstd
, luaSupport ? stdenv.hostPlatform == stdenv.buildPlatform, lua
, pythonSupport ? stdenv.hostPlatform == stdenv.buildPlatform, python3
}:

stdenv.mkDerivation (finalAttrs: {
pname = "apk-tools";
version = "3.0.0_rc4";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As soon as we have the proper release, we want to upstream this into nixpkgs.


src = fetchFromGitLab {
domain = "gitlab.alpinelinux.org";
owner = "alpine";
repo = "apk-tools";
rev = "v${finalAttrs.version}";
hash = "sha256-qMQD32o0PyXeBHaTj13XGlFby0LNVa5g2AfO9quDY5Q=";
};

nativeBuildInputs = [ meson ninja pkg-config scdoc ]
++ lib.optionals luaSupport [ lua lua.pkgs.lua-zlib ]
++ lib.optionals pythonSupport [ python3 ];
buildInputs = [ openssl zlib zstd scdoc ]
++ lib.optional luaSupport lua
++ lib.optional pythonSupport python3;
strictDeps = true;

mesonFlags = [
(lib.mesonEnable "lua" luaSupport)
(lib.mesonOption "lua_version" "") # used for name of lua exe
(lib.mesonEnable "python" pythonSupport)
(lib.mesonEnable "tests" (finalAttrs.doCheck or false))
];

env.NIX_CFLAGS_COMPILE = toString [
"-Wno-error=unused-result"
"-Wno-error=deprecated-declarations"
];

enableParallelBuilding = true;

meta = with lib; {
homepage = "https://gitlab.alpinelinux.org/alpine/apk-tools";
description = "Alpine Package Keeper";
maintainers = with maintainers; [ ];
license = licenses.gpl2Only;
platforms = platforms.linux;
mainProgram = "apk";
};
})
115 changes: 59 additions & 56 deletions builder.nix
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
{ pkgs ? import <nixpkgs> {}
, lib ? pkgs.lib
, openwrtLib ? import ./openwrt-lib.nix { inherit lib; }
, stdenv ? pkgs.stdenv
, fetchurl ? pkgs.fetchurl
, writeScript ? pkgs.writeScript
, callPackages2nix ? pkgs.callPackages2nix
# OpenWRT release
, release ? import ./latest-release.nix
, release ? openwrtLib.latestRelease
# OpenWRT target
, target
# Hardware model
, profile
, variant ? "generic"
# Checksum of the `sha256sums` file
, sha256 ?
(
import ./hashes/${release}.nix
).targets.${target}.${variant}.sha256
# Manually specify packages' arch for OpenWRT<19 releases without profiles.json
, packagesArch ?
(
import ./hashes/${release}.nix
).targets.${target}.${variant}.packagesArch
# Checksum of a feed's `Packages` file
, feedsSha256 ?
(
import ./hashes/${release}.nix
).packages.${packagesArch}
# Attrset where key is kmodsTarget and value is checksum of `Packages` file. Required for OpenWRT >=24
, kmodsSha256 ? {}
, packagesArch ? throw "packagesArch must be given for OpenWRT<19 releases"
, cachePath ? openwrtLib.getCachePath release
# Extra OpenWRT packages (can be prefixed with "-")
, packages ? []
# Include extra files
Expand All @@ -37,73 +29,80 @@
} @ args:

let
inherit (pkgs) lib;

maybeKmodsSha256 = lib.optionalAttrs (lib.versionAtLeast release "24") (
if kmodsSha256 != { }
then kmodsSha256
else (import ./hashes/${release}.nix).kmods.${target}.${variant} or (builtins.throw "Failed to load Kmods hashes for ${target}/${variant}!")
);

cache = import ./cached-packages.nix { inherit openwrtLib release target variant packagesArch cachePath; };
inherit (import ./files.nix {
inherit pkgs release target variant sha256 feedsSha256 packagesArch;
kmodsSha256 = maybeKmodsSha256;
}) variantFiles profiles expandDeps corePackages packagesByFeed allPackages;
inherit lib fetchurl callPackages2nix openwrtLib cache;
}) expandDeps corePackages packagesByFeed allPackages;

requiredPackages = profiles.default_packages or (
requiredPackages = cache.profiles.default_packages or (
builtins.attrNames packagesByFeed.base
++ builtins.attrNames corePackages
) ++ profiles.profiles.${profile}.device_packages or []
) ++ cache.profiles.profiles.${profile}.device_packages or []
++ packages;
allRequiredPackages = expandDeps allPackages requiredPackages;
imageBuilderPrefix = "openwrt-imagebuilder-${if release == "snapshot" then "" else "${release}-"}";

extraArgs = builtins.removeAttrs args [
depsArgs = [
"pkgs"
"lib"
"openwrtLib"
"stdenv"
"fetchurl"
"writeScript"
];
configArgs = [
"release"
"target"
"profile"
"variant"
"sha256"
"packagesArch"
"feedsSha256"
"kmodsSha256"
"packages"
"files"
"disabledServices"
"extraImageName"
"rootFsPartSize"
];
drvArgs = [
"passthru"
];
extraArgs = builtins.removeAttrs args (depsArgs ++ configArgs ++ drvArgs);
in

pkgs.stdenv.mkDerivation ({
stdenv.mkDerivation ({
name = lib.concatStringsSep "-" ([
"openwrt" release
] ++ lib.optional (extraImageName != null) extraImageName
++ [ target variant profile ]);

src =
let
inherit (pkgs.stdenv.hostPlatform) uname;
baseFileName = "${imageBuilderPrefix}${target}-${variant}.${uname.system}-${uname.processor}";
possibleFileNames = builtins.map (extension: "${baseFileName}${extension}") [ ".tar.zst" ".tar.xz" ];
matches = builtins.filter (fileName: builtins.hasAttr fileName variantFiles) possibleFileNames;
in
if matches != []
then builtins.getAttr (builtins.elemAt matches 0) variantFiles
else throw "No valid image builder found!";
src = fetchurl cache.imagebuilder;

postPatch = with pkgs; ''
patchShebangs scripts staging_dir/host/bin

substituteInPlace rules.mk \
--replace "SHELL:=/usr/bin/env bash" "SHELL:=${runtimeShell}" \
--replace "/usr/bin/env true" "${coreutils}/bin/true" \
--replace "/usr/bin/env false" "${coreutils}/bin/false"
--replace-warn "/usr/bin/env bash" "${runtimeShell}" \
--replace-warn "/usr/bin/env true" "${coreutils}/bin/true" \
--replace-warn "/usr/bin/env false" "${coreutils}/bin/false"

substituteInPlace Makefile \
--replace-quiet ' $(APK) add' ' -$(APK) add'
'';

configurePhase =
let
installPackages = pkgs.writeScript "install-openwrt-packages" (
repositories = lib.concatMapStringsSep "\n"
(repo: fetchurl repo.sourceInfo)
([ cache.corePackages cache.kmodPackages ] ++ lib.attrValues cache.feeds);

installRepositories = if cache.apk
then ''
cat > repositories <<EOF
${repositories}
EOF
''
else ''
echo "src imagebuilder file:packages" > repositories.conf
'';

installPackages = writeScript "install-openwrt-packages" (
lib.concatMapStrings (pname:
let
package = allPackages.${pname};
Expand All @@ -117,8 +116,7 @@ pkgs.stdenv.mkDerivation ({
runHook preConfigure

${installPackages}

echo "src imagebuilder file:packages" > repositories.conf
${installRepositories}

# if the user provided key-build, key-build.pub and key-build.ucert in /run/openwrt use it
# NOTE: they need to be owned by group nixbld and have permission 440
Expand All @@ -143,7 +141,7 @@ pkgs.stdenv.mkDerivation ({
zlib unzip bzip2 zstd
ncurses which rsync git file getopt wget
bash perl python311 dtc
] ++ lib.optional (lib.versionOlder release "21" && release != "snapshot") python2;
] ++ lib.optional (openwrtLib.releaseOlder release "21") python2;


buildFlags = [
Expand All @@ -168,9 +166,9 @@ pkgs.stdenv.mkDerivation ({
};
in
''
buildFlagsArray+=(${mkBuildFlagsArray flags})
buildFlagsArray+=(${mkBuildFlagsArray flags})
'';

installPhase = ''
runHook preInstall

Expand All @@ -190,4 +188,9 @@ pkgs.stdenv.mkDerivation ({
'';

dontFixup = true;

passthru = (extraArgs.passthru or {}) // {
config = openwrtLib.takeAttrs configArgs args;
};

} // extraArgs)
60 changes: 60 additions & 0 deletions cache/17.01.1/default.nix

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions cache/17.01.1/targets/apm821xx/nand/default.nix

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions cache/17.01.1/targets/apm821xx/sata/default.nix

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading