From 9a65ff8c87d8160384d9558769108eced531f0af Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Wed, 22 Feb 2023 16:27:38 +0000 Subject: nix/eval-config.nix: fix custom configuration When I introduced the global src attribute, I broke custom configurations, since they wouldn't be passing that key in, and nor should they. To allow for non-customisable globals like src, we need to separate them from config. Here, I've modified eval-config.nix to take a callback, so that it can provide multiple attributes, and handle command line arguments itself so that doesn't need to be in every entry point any more. This gives us an interface similar to the NixOS module system's, where a variety of globals are available that can be pulled out of the passed attribute set as required, but with the additional advantage that files are usable directly from nix-build, and support command line arguments. Signed-off-by: Alyssa Ross Fixes: 0149885 ("nix: centralise source cleaning") --- Documentation/default.nix | 6 +++--- Documentation/jekyll.nix | 4 ++-- host/initramfs/default.nix | 11 +++++++---- host/initramfs/shell.nix | 4 ++-- host/rootfs/default.nix | 7 ++++--- host/rootfs/shell.nix | 4 ++-- host/start-vm/default.nix | 6 +++--- host/start-vm/shell.nix | 4 ++-- img/app/default.nix | 10 ++++------ img/app/shell.nix | 7 +++---- nix/checks.nix | 12 +++++------- nix/eval-config.nix | 23 ++++++++++++++--------- release.nix | 16 ++++++++-------- release/combined/default.nix | 4 ++-- release/combined/eosimages.nix | 4 ++-- release/combined/run-vm.nix | 4 ++-- release/installer/default.nix | 5 ++--- release/installer/run-vm.nix | 4 ++-- release/live/default.nix | 7 ++++--- release/live/shell.nix | 4 ++-- shell.nix | 4 ++-- vm/app/catgirl.nix | 4 ++-- vm/app/lynx.nix | 4 ++-- vm/make-vm.nix | 4 ++-- vm/sys/net/default.nix | 10 ++++------ vm/sys/net/shell.nix | 6 ++---- 26 files changed, 89 insertions(+), 89 deletions(-) diff --git a/Documentation/default.nix b/Documentation/default.nix index a8f43ef..90f8e88 100644 --- a/Documentation/default.nix +++ b/Documentation/default.nix @@ -2,14 +2,14 @@ # SPDX-FileCopyrightText: 2022 Unikie # SPDX-License-Identifier: MIT -{ config ? import ../nix/eval-config.nix {} }: config.pkgs.callPackage ( +import ../nix/eval-config.nix ({ config, src, ... }: config.pkgs.callPackage ( { lib, stdenvNoCC, jekyll, drawio-headless }: stdenvNoCC.mkDerivation { name = "spectrum-docs"; - inherit (config) src; + inherit src; sourceRoot = "source/Documentation"; buildPhase = '' @@ -26,4 +26,4 @@ stdenvNoCC.mkDerivation { } ) { jekyll = import ./jekyll.nix { inherit config; }; -} +}) diff --git a/Documentation/jekyll.nix b/Documentation/jekyll.nix index 6f2866f..fe16186 100644 --- a/Documentation/jekyll.nix +++ b/Documentation/jekyll.nix @@ -1,7 +1,7 @@ # SPDX-FileCopyrightText: 2022 Alyssa Ross # SPDX-License-Identifier: MIT -{ config ? import ../nix/eval-config.nix {} }: config.pkgs.callPackage ( +import ../nix/eval-config.nix ({ config, ... }: config.pkgs.callPackage ( { bundlerApp }: @@ -10,4 +10,4 @@ bundlerApp { gemdir = ./.; exes = [ "jekyll" ]; } -) { } +) { }) diff --git a/host/initramfs/default.nix b/host/initramfs/default.nix index 4d3c5ed..828ba5d 100644 --- a/host/initramfs/default.nix +++ b/host/initramfs/default.nix @@ -1,10 +1,13 @@ # SPDX-FileCopyrightText: 2021-2022 Alyssa Ross # SPDX-License-Identifier: MIT -{ config ? import ../../nix/eval-config.nix {} +import ../../nix/eval-config.nix ( +{ config, src , rootfs ? import ../rootfs { inherit config; } +, ... }: -let inherit (config) pkgs; in pkgs.callPackage ( +config.pkgs.callPackage ( + { lib, stdenvNoCC, makeModulesClosure, runCommand, writeReferencesToFile , pkgsStatic, busybox, cpio, microcodeAmd, microcodeIntel }: @@ -80,7 +83,7 @@ in stdenvNoCC.mkDerivation { name = "initramfs"; - inherit (config) src; + inherit src; sourceRoot = "source/host/initramfs"; MICROCODE = microcode; @@ -96,4 +99,4 @@ stdenvNoCC.mkDerivation { enableParallelBuilding = true; } -) {} +) {}) diff --git a/host/initramfs/shell.nix b/host/initramfs/shell.nix index 48c1f81..5475737 100644 --- a/host/initramfs/shell.nix +++ b/host/initramfs/shell.nix @@ -1,7 +1,7 @@ # SPDX-License-Identifier: MIT # SPDX-FileCopyrightText: 2021-2022 Alyssa Ross -{ config ? import ../../nix/eval-config.nix {} }: +import ../../nix/eval-config.nix ({ config, ... } @ args: let inherit (config) pkgs; @@ -23,4 +23,4 @@ initramfs.overrideAttrs ({ nativeBuildInputs ? [], ... }: { EXT_FS = extfs; KERNEL = "${rootfs.kernel}/${stdenv.hostPlatform.linux-kernel.target}"; ROOT_FS = rootfs; -}) +})) diff --git a/host/rootfs/default.nix b/host/rootfs/default.nix index ad997d1..acc0719 100644 --- a/host/rootfs/default.nix +++ b/host/rootfs/default.nix @@ -2,7 +2,8 @@ # SPDX-FileCopyrightText: 2021-2022 Alyssa Ross # SPDX-FileCopyrightText: 2022 Unikie -{ config ? import ../../nix/eval-config.nix {} }: let inherit (config) pkgs; in +import ../../nix/eval-config.nix ( +{ config, src, ... }: let inherit (config) pkgs; in pkgs.pkgsStatic.callPackage ( { lib, stdenvNoCC, nixos, runCommand, writeReferencesToFile, s6-rc, tar2ext4 @@ -120,7 +121,7 @@ in stdenvNoCC.mkDerivation { name = "spectrum-rootfs"; - inherit (config) src; + inherit src; sourceRoot = "source/host/rootfs"; nativeBuildInputs = [ s6-rc tar2ext4 ]; @@ -142,4 +143,4 @@ stdenvNoCC.mkDerivation { platforms = platforms.linux; }; } -) {} +) {}) diff --git a/host/rootfs/shell.nix b/host/rootfs/shell.nix index ea8410a..94e84be 100644 --- a/host/rootfs/shell.nix +++ b/host/rootfs/shell.nix @@ -2,7 +2,7 @@ # SPDX-FileCopyrightText: 2021 Alyssa Ross # SPDX-FileCopyrightText: 2022 Unikie -{ config ? import ../../nix/eval-config.nix {} }: +import ../../nix/eval-config.nix ({ config, ... } @ args: let rootfs = import ./. { inherit config; }; @@ -21,4 +21,4 @@ rootfs.overrideAttrs ( EXT_FS = pkgsStatic.callPackage ../initramfs/extfs.nix { inherit config; }; INITRAMFS = import ../initramfs { inherit config rootfs; }; KERNEL = "${passthru.kernel}/${stdenv.hostPlatform.linux-kernel.target}"; -}) +})) diff --git a/host/start-vm/default.nix b/host/start-vm/default.nix index a7ca521..767a967 100644 --- a/host/start-vm/default.nix +++ b/host/start-vm/default.nix @@ -1,7 +1,7 @@ # SPDX-License-Identifier: MIT # SPDX-FileCopyrightText: 2022 Alyssa Ross -{ config ? import ../../nix/eval-config.nix {} }: config.pkgs.callPackage ( +import ../../nix/eval-config.nix ({ config, src, ... }: config.pkgs.callPackage ( { lib, stdenv, meson, ninja, rustc }: let @@ -11,11 +11,11 @@ in stdenv.mkDerivation { name = "start-vm"; - inherit (config) src; + inherit src; sourceRoot = "source/host/start-vm"; nativeBuildInputs = [ meson ninja rustc ]; doCheck = true; } -) { } +) { }) diff --git a/host/start-vm/shell.nix b/host/start-vm/shell.nix index 5192b76..cbc1fee 100644 --- a/host/start-vm/shell.nix +++ b/host/start-vm/shell.nix @@ -1,7 +1,7 @@ # SPDX-License-Identifier: MIT # SPDX-FileCopyrightText: 2021 Alyssa Ross -{ config ? import ../../nix/eval-config.nix {} }: +import ../../nix/eval-config.nix ({ config, ... }: with config.pkgs; @@ -10,4 +10,4 @@ with config.pkgs; { nativeBuildInputs = nativeBuildInputs ++ [ rustfmt ]; -}) +})) diff --git a/img/app/default.nix b/img/app/default.nix index 5386afc..7aa22ad 100644 --- a/img/app/default.nix +++ b/img/app/default.nix @@ -1,10 +1,8 @@ # SPDX-License-Identifier: MIT # SPDX-FileCopyrightText: 2021-2022 Alyssa Ross -{ config ? import ../../nix/eval-config.nix {} -, terminfo ? config.pkgs.foot.terminfo -}: - +import ../../nix/eval-config.nix ( +{ config, src, terminfo ? config.pkgs.foot.terminfo, ... }: config.pkgs.pkgsStatic.callPackage ( { lib, stdenvNoCC, runCommand, writeReferencesToFile, buildPackages @@ -64,7 +62,7 @@ in stdenvNoCC.mkDerivation { name = "spectrum-appvm"; - inherit (config) src; + inherit src; sourceRoot = "source/img/app"; nativeBuildInputs = [ jq s6-rc tar2ext4 util-linux ]; @@ -83,4 +81,4 @@ stdenvNoCC.mkDerivation { platforms = platforms.linux; }; } -) {} +) {}) diff --git a/img/app/shell.nix b/img/app/shell.nix index 83dcd76..7a323aa 100644 --- a/img/app/shell.nix +++ b/img/app/shell.nix @@ -1,9 +1,8 @@ # SPDX-License-Identifier: MIT # SPDX-FileCopyrightText: 2021-2022 Alyssa Ross -{ config ? import ../../nix/eval-config.nix {} -, run ? ../../vm/app/catgirl.nix -}: +import ../../nix/eval-config.nix ( +{ config, run ? ../../vm/app/catgirl.nix, ... }: with config.pkgs; @@ -21,4 +20,4 @@ with config.pkgs; shellHook = '' export RUN_IMG="$(printf "%s\n" "$runDef"/blk/run.img)" ''; -}) +})) diff --git a/nix/checks.nix b/nix/checks.nix index f399ef7..d5a40c0 100644 --- a/nix/checks.nix +++ b/nix/checks.nix @@ -1,9 +1,7 @@ # SPDX-License-Identifier: MIT # SPDX-FileCopyrightText: 2022 Unikie -{ config ? import ../nix/eval-config.nix {} }: - -{ +import ../nix/eval-config.nix ({ config, src, ... }: { recurseForDerivations = true; doc-links = config.pkgs.callPackage ( @@ -23,7 +21,7 @@ reuse = config.pkgs.callPackage ( { lib, runCommand, reuse }: runCommand "spectrum-reuse" { - inherit (config) src; + inherit src; nativeBuildInputs = [ reuse ]; } '' reuse --root $src lint @@ -34,7 +32,7 @@ rustfmt = config.pkgs.callPackage ( { lib, runCommand, rustfmt }: runCommand "spectrum-rustfmt" { - inherit (config) src; + inherit src; nativeBuildInputs = [ rustfmt ]; } '' shopt -s globstar @@ -46,7 +44,7 @@ shellcheck = config.pkgs.callPackage ( { lib, runCommand, shellcheck }: runCommand "spectrum-shellcheck" { - inherit (config) src; + inherit src; nativeBuildInputs = [ shellcheck ]; } '' shopt -s globstar @@ -54,4 +52,4 @@ touch $out '' ) {}; -} +}) diff --git a/nix/eval-config.nix b/nix/eval-config.nix index 8ba7744..5164534 100644 --- a/nix/eval-config.nix +++ b/nix/eval-config.nix @@ -1,15 +1,20 @@ # SPDX-License-Identifier: MIT # SPDX-FileCopyrightText: 2022 Unikie +# SPDX-FileCopyrightText: 2023 Alyssa Ross -{ config ? - let customPath = builtins.tryEval ; in +# The empty list of attribute set arguments is required, because +# otherwise Nix will not pass arguments supplied on the command line +# with --arg/--argstr. +callback: { ... } @ args: + +callback (args // rec { + config = ({ pkgs ? import {} }: { + inherit pkgs; + }) args.config or (let customPath = builtins.tryEval ; in if customPath.success then import customPath.value else if builtins.pathExists ../config.nix then import ../config.nix - else {} -}: - -({ pkgs ? import {} }: { - inherit pkgs; + else {}) +; - src = import ./src.nix { inherit (pkgs) lib; }; -}) config + src = import ./src.nix { inherit (config.pkgs) lib; }; +}) diff --git a/release.nix b/release.nix index 15471d0..707c86c 100644 --- a/release.nix +++ b/release.nix @@ -3,16 +3,16 @@ # This file is built to populate the binary cache. -# Set config = {} to disable implicitly reading config.nix, since -# we'll want the result to be the same as on the binary cache. If it -# turns out there is a compelling reason to read the default config -# here, we can reconsider this. -{ config ? import nix/eval-config.nix { config = {}; } }: - -{ +import nix/eval-config.nix ({ config, ... }: { doc = import ./Documentation { inherit config; }; checks = import nix/checks.nix { inherit config; }; combined = import release/combined/run-vm.nix { inherit config; }; -} +}) + +# Set config = {} to disable implicitly reading config.nix, since +# we'll want the result to be the same as on the binary cache. If it +# turns out there is a compelling reason to read the default config +# here, we can reconsider this. +{ config = {}; } diff --git a/release/combined/default.nix b/release/combined/default.nix index 2865376..7f7b3a2 100644 --- a/release/combined/default.nix +++ b/release/combined/default.nix @@ -3,7 +3,7 @@ # SPDX-FileCopyrightText: 2021 Yureka # SPDX-FileCopyrightText: 2022 Unikie -{ config ? import ../../nix/eval-config.nix {} }: with config.pkgs; +import ../../nix/eval-config.nix ({ config, ... } @ args: with config.pkgs; let inherit (builtins) storeDir; @@ -113,4 +113,4 @@ runCommand "spectrum-installer" { fillPartition $out 0 ${esp} fillPartition $out 1 ${rootfs} fillPartition $out 2 ${eosimages} -'' +'') diff --git a/release/combined/eosimages.nix b/release/combined/eosimages.nix index 9f2ab10..b2dba13 100644 --- a/release/combined/eosimages.nix +++ b/release/combined/eosimages.nix @@ -1,7 +1,7 @@ # SPDX-License-Identifier: MIT # SPDX-FileCopyrightText: 2021-2022 Alyssa Ross -{ config ? import ../../nix/eval-config.nix {} }: with config.pkgs; +import ../../nix/eval-config.nix ({ config, ... }: with config.pkgs; runCommand "eosimages.img" { nativeBuildInputs = [ e2fsprogs tar2ext4 ]; @@ -15,4 +15,4 @@ runCommand "eosimages.img" { tar -chf $NIX_BUILD_TOP/eosimages.tar * tar2ext4 -i $NIX_BUILD_TOP/eosimages.tar -o $out e2label $out eosimages -'' +'') diff --git a/release/combined/run-vm.nix b/release/combined/run-vm.nix index 2fc474e..10bd8bf 100644 --- a/release/combined/run-vm.nix +++ b/release/combined/run-vm.nix @@ -1,7 +1,7 @@ # SPDX-License-Identifier: MIT # SPDX-FileCopyrightText: 2021 Alyssa Ross -{ config ? import ../../nix/eval-config.nix {} }: with config.pkgs; +import ../../nix/eval-config.nix ({ config, ... }: with config.pkgs; let image = import ./. { inherit config; }; @@ -22,4 +22,4 @@ writeShellScript "run-spectrum-installer-vm.sh" '' -drive file=${qemu_kvm}/share/qemu/edk2-${stdenv.hostPlatform.qemuArch}-code.fd,format=raw,if=pflash,readonly=true \ -drive file=${image},id=drive1,format=raw,if=none,readonly=true \ -drive file=/proc/self/fd/3,format=raw,if=virtio -'' +'') diff --git a/release/installer/default.nix b/release/installer/default.nix index 0c57704..16a7d35 100644 --- a/release/installer/default.nix +++ b/release/installer/default.nix @@ -1,7 +1,7 @@ # SPDX-License-Identifier: MIT # SPDX-FileCopyrightText: 2021-2022 Alyssa Ross -{ config ? import ../../nix/eval-config.nix {}, extraConfig ? {} }: +import ../../nix/eval-config.nix ({ config, extraConfig ? {}, ... }: with config.pkgs; let @@ -21,5 +21,4 @@ in ] ++ config.boot.kernelParams); store = writeReferencesToFile config.system.build.toplevel; -} - +}) diff --git a/release/installer/run-vm.nix b/release/installer/run-vm.nix index fe014f8..c42155b 100644 --- a/release/installer/run-vm.nix +++ b/release/installer/run-vm.nix @@ -1,7 +1,7 @@ # SPDX-License-Identifier: MIT # SPDX-FileCopyrightText: 2021-2022 Alyssa Ross -{ config ? import ../../nix/eval-config.nix {} }: +import ../../nix/eval-config.nix ({ config, ... }: let inherit (builtins) storeDir; @@ -43,4 +43,4 @@ writeShellScript "run-spectrum-installer-vm.sh" '' -kernel ${installer.kernel} \ -initrd ${installer.initramfs} \ -append ${escapeShellArg installer.kernelParams} -'' +'') diff --git a/release/live/default.nix b/release/live/default.nix index 66bba26..c36c34b 100644 --- a/release/live/default.nix +++ b/release/live/default.nix @@ -2,7 +2,8 @@ # SPDX-FileCopyrightText: 2021-2022 Alyssa Ross # SPDX-FileCopyrightText: 2022 Unikie -{ config ? import ../../nix/eval-config.nix {} }: config.pkgs.callPackage ( +import ../../nix/eval-config.nix ({ config, src, ... }: +config.pkgs.callPackage ( { stdenvNoCC, cryptsetup, dosfstools, jq, mtools, util-linux, stdenv , systemd }: @@ -22,7 +23,7 @@ in stdenvNoCC.mkDerivation { name = "spectrum-live.img"; - inherit (config) src; + inherit src; sourceRoot = "source/release/live"; nativeBuildInputs = [ cryptsetup dosfstools jq mtools util-linux ]; @@ -46,4 +47,4 @@ stdenvNoCC.mkDerivation { passthru = { inherit rootfs; }; } -) {} +) {}) diff --git a/release/live/shell.nix b/release/live/shell.nix index dcf2059..7cec144 100644 --- a/release/live/shell.nix +++ b/release/live/shell.nix @@ -1,7 +1,7 @@ # SPDX-License-Identifier: MIT # SPDX-FileCopyrightText: 2021-2022 Alyssa Ross -{ config ? import ../../nix/eval-config.nix {} }: +import ../../nix/eval-config.nix ({ config, ... }: with config.pkgs; @@ -12,4 +12,4 @@ with config.pkgs; OVMF_CODE = "${qemu_kvm}/share/qemu/edk2-${stdenv.hostPlatform.qemuArch}-code.fd"; } -) +)) diff --git a/shell.nix b/shell.nix index 77deb2c..c249aa6 100644 --- a/shell.nix +++ b/shell.nix @@ -2,7 +2,7 @@ # SPDX-FileCopyrightText: 2022 Unikie # SPDX-License-Identifier: MIT -{ config ? import nix/eval-config.nix {} }: with config.pkgs; +import nix/eval-config.nix ({ config, ... }: with config.pkgs; mkShell { nativeBuildInputs = [ b4 reuse rustfmt ]; @@ -13,4 +13,4 @@ mkShell { export "GIT_CONFIG_VALUE_''${GIT_CONFIG_COUNT:-0}"=https://spectrum-os.org/lists/archives/spectrum-devel/%s GIT_CONFIG_COUNT+=1 ''; -} +}) diff --git a/vm/app/catgirl.nix b/vm/app/catgirl.nix index a4c05e3..f74acc9 100644 --- a/vm/app/catgirl.nix +++ b/vm/app/catgirl.nix @@ -1,7 +1,7 @@ # SPDX-License-Identifier: MIT # SPDX-FileCopyrightText: 2021-2022 Alyssa Ross -{ config ? import ../../../nix/eval-config.nix {} }: +import ../../nix/eval-config.nix ({ config, ... }: import ../make-vm.nix { inherit config; } { providers.net = [ "netvm" ]; @@ -14,4 +14,4 @@ import ../make-vm.nix { inherit config; } { ${catgirl}/bin/catgirl -h irc.libera.chat -j "#spectrum" -n $nick '' ) { }; -} +}) diff --git a/vm/app/lynx.nix b/vm/app/lynx.nix index 00d449e..d0b36a0 100644 --- a/vm/app/lynx.nix +++ b/vm/app/lynx.nix @@ -1,7 +1,7 @@ # SPDX-License-Identifier: MIT # SPDX-FileCopyrightText: 2021-2022 Alyssa Ross -{ config ? import ../../../nix/eval-config.nix {} }: +import ../../nix/eval-config.nix ({ config, ... }: import ../make-vm.nix { inherit config; } { providers.net = [ "netvm" ]; @@ -12,4 +12,4 @@ import ../make-vm.nix { inherit config; } { ${lynx}/bin/lynx https://spectrum-os.org '' ) { }; -} +}) diff --git a/vm/make-vm.nix b/vm/make-vm.nix index 0d7c1f9..da3bdf7 100644 --- a/vm/make-vm.nix +++ b/vm/make-vm.nix @@ -1,9 +1,9 @@ # SPDX-License-Identifier: MIT # SPDX-FileCopyrightText: 2022 Alyssa Ross -{ config ? import ../nix/eval-config.nix {} }: +import ../nix/eval-config.nix ({ config, ... }: import ../vm-lib/make-vm.nix { inherit (config) pkgs; basePaths = (import ../img/app { inherit config; }).packagesSysroot; -} +}) diff --git a/vm/sys/net/default.nix b/vm/sys/net/default.nix index 9d75728..a30f5f5 100644 --- a/vm/sys/net/default.nix +++ b/vm/sys/net/default.nix @@ -1,10 +1,8 @@ # SPDX-License-Identifier: MIT # SPDX-FileCopyrightText: 2021-2022 Alyssa Ross -{ config ? import ../../../nix/eval-config.nix {} -, terminfo ? config.pkgs.foot.terminfo -}: - +import ../../../nix/eval-config.nix ( +{ config, src, terminfo ? config.pkgs.foot.terminfo, ... }: config.pkgs.pkgsStatic.callPackage ( { lib, stdenvNoCC, runCommand, writeReferencesToFile, buildPackages @@ -73,7 +71,7 @@ in stdenvNoCC.mkDerivation { name = "spectrum-netvm"; - inherit (config) src; + inherit src; sourceRoot = "source/vm/sys/net"; nativeBuildInputs = [ jq s6-rc tar2ext4 util-linux ]; @@ -94,4 +92,4 @@ stdenvNoCC.mkDerivation { platforms = platforms.linux; }; } -) {} +) {}) diff --git a/vm/sys/net/shell.nix b/vm/sys/net/shell.nix index 849920d..f298431 100644 --- a/vm/sys/net/shell.nix +++ b/vm/sys/net/shell.nix @@ -1,9 +1,7 @@ # SPDX-License-Identifier: MIT # SPDX-FileCopyrightText: 2021 Alyssa Ross -{ config ? import ../../../nix/eval-config.nix {} }: - -with config.pkgs; +import ../../../nix/eval-config.nix ({ config, ... }: with config.pkgs; (import ./. { inherit config; }).overrideAttrs ( { passthru ? {}, nativeBuildInputs ? [], ... }: @@ -12,4 +10,4 @@ with config.pkgs; nativeBuildInputs = nativeBuildInputs ++ [ cloud-hypervisor jq qemu_kvm reuse ]; KERNEL = "${passthru.kernel.dev}/vmlinux"; -}) +})) -- cgit 1.4.1