diff --git a/.gitignore b/.gitignore index 62cd3e7..3799b2b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -result* \ No newline at end of file +result* +.buildroot +build \ No newline at end of file diff --git a/buildroot.nix b/buildroot.nix new file mode 100644 index 0000000..9722ef1 --- /dev/null +++ b/buildroot.nix @@ -0,0 +1,84 @@ +# nix-build --expr 'with import {}; callPackage ./buildroot.nix {}' +{ + pkgs ? import {}, + packagName ? "buildroot", + packageVersion ? "2021.02.7", + packageSha256 ? "0kdkar2pbd9k0q4i4a87xnqmsdr7njj6mc8x2avvhh9skw2qrg64", + outputFolder ? "$PWD/.buildroot", + withXConfig ? false, + withGConfig ? false, +}: + +let + + +buildRootPath = "usr/src/${packagName}-${packageVersion}"; +package = pkgs.stdenv.mkDerivation rec { + name = "${packagName}"; + version = "${packageVersion}"; + src = pkgs.fetchzip { + url = "https://buildroot.org/downloads/buildroot-${packageVersion}.tar.gz"; + sha256 = "${packageSha256}"; + }; + phases = [ "unpackPhase" "installPhase" ]; + installPhase = '' + mkdir -p $out/${buildRootPath} + cp -R . $out/${buildRootPath} + ''; +}; + + +makeBuildRoot = pkgs.writeShellScriptBin "makeBuildRoot" '' + BR2_DL_DIR="${outputFolder}/dl" ${pkgs.gnumake}/bin/make O="${outputFolder}" -C "${package}/${buildRootPath}" $@ +''; + +makeBuildRootScriptPaths = [ pkgs.gnumake]; + +qtPaths = if withXConfig then [pkgs.qt5.base] else []; +gtkPaths = if withGConfig then [ + pkgs.gtk2.dev + pkgs.gtkmm2 + pkgs.gnome2.libglade + pkgs.glib + ] else []; +in +{ + package = package; + makeBuildRoot = { + command = makeBuildRoot; + scriptPaths = makeBuildRootScriptPaths; + paths = makeBuildRootScriptPaths ++ [ + pkgs.which + pkgs.pkg-config + pkgs.ncurses.dev + pkgs.rsync + pkgs.bc + pkgs.unzip + pkgs.cpio + pkgs.wget + pkgs.git + pkgs.subversion + pkgs.gnused + pkgs.file + pkgs.perl + pkgs.flock + pkgs.bash + pkgs.gnugrep + pkgs.coreutils-full + pkgs.binutils + pkgs.gcc + pkgs.gnupatch + pkgs.gzip + pkgs.bzip2 + pkgs.gnutar + pkgs.cacert + pkgs.python3Full + pkgs.lzma + pkgs.gdbm + pkgs.readline + + ] + ++ qtPaths + ++ gtkPaths; + }; +} \ No newline at end of file diff --git a/examples/buildroot_nix-build.nix b/examples/buildroot_nix-build.nix new file mode 100644 index 0000000..3c247b1 --- /dev/null +++ b/examples/buildroot_nix-build.nix @@ -0,0 +1,17 @@ +{ pkgs ? import {}}: +let + +buildroot = pkgs.callPackage ../buildroot.nix {}; + +in + +pkgs.stdenv.mkDerivation rec { + name = "makeBuildRoot"; + phases = "installPhase"; + installPhase = '' + mkdir -p $out/bin + cp ${buildroot.makeBuildRoot.command}/bin/makeBuildRoot $out/bin/makeBuildRoot + ''; +} + + diff --git a/examples/buildroot_nix-docker.nix b/examples/buildroot_nix-docker.nix new file mode 100644 index 0000000..9279d6a --- /dev/null +++ b/examples/buildroot_nix-docker.nix @@ -0,0 +1,30 @@ +{ pkgs ? import {}}: +let + +buildroot = pkgs.callPackage ../buildroot.nix {}; + +buildrootBaseImage = pkgs.dockerTools.pullImage { + imageName = "buildroot/base"; + imageDigest = "sha256:d81f16ae5635f1548fe3a9dafef5f41932fa5a209368cb7d74fa9a8dea2b2b07"; + finalImageName = "buildroot/base"; + finalImageTag = "20210922.2200"; + sha256 = "0mqjy3zq2v6rrhizgb9nvhczl87lcfphq9601wcprdika2jz7qh8"; +}; + +in + +pkgs.dockerTools.buildImage { + name = "buildroot-nix"; + tag = "latest"; + + fromImage = buildrootBaseImage; + + contents = [ + buildroot.package + buildroot.makeBuildRoot.command + buildroot.makeBuildRoot.scriptPaths + ]; + + config.Cmd = [ "${pkgs.bash}/bin/bash" ]; +} + diff --git a/examples/buildroot_nix-shell.nix b/examples/buildroot_nix-shell.nix new file mode 100644 index 0000000..83547ce --- /dev/null +++ b/examples/buildroot_nix-shell.nix @@ -0,0 +1,25 @@ +{ pkgs ? import {}}: +let + +buildroot = pkgs.callPackage ../buildroot.nix {}; + +in + +pkgs.stdenv.mkDerivation { + name = "buildroot-shell"; + buildInputs = buildroot.makeBuildRoot.paths ++ [ + buildroot.package + buildroot.makeBuildRoot.command + ]; + hardeningDisable = [ "all" ]; + shellHook = '' + alias make='makeBuildRoot' + ''; + phases = [ "nobuildPhase" ]; + nobuildPhase = '' + echo + echo "This derivation is not meant to be built, aborting"; + echo + exit 1 + ''; +}