diff options
author | Alyssa Ross <hi@alyssa.is> | 2023-02-22 12:44:00 +0000 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2023-02-22 12:50:02 +0000 |
commit | 01498855f84ee87d66e6295efcaf7a32d67f4dad (patch) | |
tree | 25c5f3e1f17d5e23094b7a132e56e390c930dd20 | |
parent | 8dc2fa52cae39fae0af9ac0738b7a2fade83d4ec (diff) | |
download | spectrum-01498855f84ee87d66e6295efcaf7a32d67f4dad.tar spectrum-01498855f84ee87d66e6295efcaf7a32d67f4dad.tar.gz spectrum-01498855f84ee87d66e6295efcaf7a32d67f4dad.tar.bz2 spectrum-01498855f84ee87d66e6295efcaf7a32d67f4dad.tar.lz spectrum-01498855f84ee87d66e6295efcaf7a32d67f4dad.tar.xz spectrum-01498855f84ee87d66e6295efcaf7a32d67f4dad.tar.zst spectrum-01498855f84ee87d66e6295efcaf7a32d67f4dad.zip |
nix: centralise source cleaning
This was getting very repetitive. Having a single copy of the sources shared between builds will also save on store space, and means we don't need to support overriding the path to the scripts directory in Makefiles. Signed-off-by: Alyssa Ross <hi@alyssa.is>
-rw-r--r-- | Documentation/default.nix | 10 | ||||
-rw-r--r-- | host/initramfs/Makefile | 13 | ||||
-rw-r--r-- | host/initramfs/default.nix | 10 | ||||
-rw-r--r-- | host/rootfs/Makefile | 9 | ||||
-rw-r--r-- | host/rootfs/default.nix | 9 | ||||
-rw-r--r-- | host/start-vm/default.nix | 8 | ||||
-rw-r--r-- | img/app/Makefile | 5 | ||||
-rw-r--r-- | img/app/default.nix | 14 | ||||
-rw-r--r-- | nix/checks.nix | 16 | ||||
-rw-r--r-- | nix/eval-config.nix | 2 | ||||
-rw-r--r-- | nix/src.nix | 14 | ||||
-rw-r--r-- | release/live/Makefile | 9 | ||||
-rw-r--r-- | release/live/default.nix | 12 | ||||
-rw-r--r-- | scripts/default.nix | 13 | ||||
-rw-r--r-- | vm/sys/net/Makefile | 5 | ||||
-rw-r--r-- | vm/sys/net/default.nix | 14 |
16 files changed, 57 insertions, 106 deletions
diff --git a/Documentation/default.nix b/Documentation/default.nix index 564a476..a8f43ef 100644 --- a/Documentation/default.nix +++ b/Documentation/default.nix @@ -9,14 +9,8 @@ stdenvNoCC.mkDerivation { name = "spectrum-docs"; - src = with lib; cleanSourceWith { - src = cleanSource ./.; - filter = name: _type: - builtins.baseNameOf name != ".jekyll-cache" && - builtins.baseNameOf name != "_site" && - !(hasSuffix ".nix" name) && - !(hasSuffix ".svg" name); - }; + inherit (config) src; + sourceRoot = "source/Documentation"; buildPhase = '' runHook preBuild diff --git a/host/initramfs/Makefile b/host/initramfs/Makefile index 63e24ef..b0e236f 100644 --- a/host/initramfs/Makefile +++ b/host/initramfs/Makefile @@ -8,7 +8,6 @@ QEMU_KVM = qemu-kvm CPIO = cpio CPIOFLAGS = --reproducible -R +0:+0 -H newc -SCRIPTS = ../../scripts TAR = tar TAR2EXT4 = tar2ext4 VERITYSETUP = veritysetup @@ -57,10 +56,10 @@ build/rootfs.verity.roothash: build/rootfs.verity build/rootfs.verity.superblock: build/rootfs.verity tail -n +2 build/rootfs.verity > $@ -build/live.img: $(SCRIPTS)/format-uuid.sh $(SCRIPTS)/make-gpt.sh build/rootfs.verity.superblock build/rootfs.verity.roothash $(ROOT_FS) - $(SCRIPTS)/make-gpt.sh $@.tmp \ - build/rootfs.verity.superblock:2c7357ed-ebd2-46d9-aec1-23d437ec2bf5:$$($(SCRIPTS)/format-uuid.sh "$$(dd if=build/rootfs.verity.roothash bs=32 skip=1 count=1 status=none)") \ - $(ROOT_FS):4f68bce3-e8cd-4db1-96e7-fbcaf984b709:$$($(SCRIPTS)/format-uuid.sh "$$(head -c 32 build/rootfs.verity.roothash)") +build/live.img: ../../scripts/format-uuid.sh ../../scripts/make-gpt.sh build/rootfs.verity.superblock build/rootfs.verity.roothash $(ROOT_FS) + ../../scripts/make-gpt.sh $@.tmp \ + build/rootfs.verity.superblock:2c7357ed-ebd2-46d9-aec1-23d437ec2bf5:$$(../../scripts/format-uuid.sh "$$(dd if=build/rootfs.verity.roothash bs=32 skip=1 count=1 status=none)") \ + $(ROOT_FS):4f68bce3-e8cd-4db1-96e7-fbcaf984b709:$$(../../scripts/format-uuid.sh "$$(head -c 32 build/rootfs.verity.roothash)") mv $@.tmp $@ build/loop.tar: build/live.img @@ -70,8 +69,8 @@ build/loop.tar: build/live.img .tar.ext4: $(TAR2EXT4) -i $< -o $@ -build/loop.img: $(SCRIPTS)/make-gpt.sh build/loop.ext4 - $(SCRIPTS)/make-gpt.sh $@.tmp \ +build/loop.img: ../../scripts/make-gpt.sh build/loop.ext4 + ../../scripts/make-gpt.sh $@.tmp \ build/loop.ext4:56a3bbc3-aefa-43d9-a64d-7b3fd59bbc4e mv $@.tmp $@ diff --git a/host/initramfs/default.nix b/host/initramfs/default.nix index e5ddeb9..4d3c5ed 100644 --- a/host/initramfs/default.nix +++ b/host/initramfs/default.nix @@ -10,7 +10,7 @@ let inherit (config) pkgs; in pkgs.callPackage ( }: let - inherit (lib) cleanSource cleanSourceWith concatMapStringsSep hasSuffix; + inherit (lib) concatMapStringsSep hasSuffix; linux = rootfs.kernel; @@ -80,12 +80,8 @@ in stdenvNoCC.mkDerivation { name = "initramfs"; - src = cleanSourceWith { - filter = name: _type: - name != "${toString ./.}/build" && - !(hasSuffix ".nix" name); - src = cleanSource ./.; - }; + inherit (config) src; + sourceRoot = "source/host/initramfs"; MICROCODE = microcode; PACKAGES_CPIO = packagesCpio; diff --git a/host/rootfs/Makefile b/host/rootfs/Makefile index 9559c06..4c187b0 100644 --- a/host/rootfs/Makefile +++ b/host/rootfs/Makefile @@ -6,7 +6,6 @@ # QEMU_KVM = qemu-system-x86_64 -enable-kvm. QEMU_KVM = qemu-kvm -SCRIPTS = ../../scripts VERITYSETUP = veritysetup # tar2ext4 will leave half a filesystem behind if it's interrupted @@ -134,10 +133,10 @@ build/rootfs.verity.roothash: build/rootfs.verity build/rootfs.verity.superblock: build/rootfs.verity tail -n +2 build/rootfs.verity > $@ -build/live.img: $(SCRIPTS)/format-uuid.sh $(SCRIPTS)/make-gpt.sh build/rootfs.verity.superblock build/rootfs.verity.roothash build/rootfs.ext4 - $(SCRIPTS)/make-gpt.sh $@.tmp \ - build/rootfs.verity.superblock:2c7357ed-ebd2-46d9-aec1-23d437ec2bf5:$$($(SCRIPTS)/format-uuid.sh "$$(dd if=build/rootfs.verity.roothash bs=32 skip=1 count=1 status=none)") \ - build/rootfs.ext4:4f68bce3-e8cd-4db1-96e7-fbcaf984b709:$$($(SCRIPTS)/format-uuid.sh "$$(head -c 32 build/rootfs.verity.roothash)") +build/live.img: ../../scripts/format-uuid.sh ../../scripts/make-gpt.sh build/rootfs.verity.superblock build/rootfs.verity.roothash build/rootfs.ext4 + ../../scripts/make-gpt.sh $@.tmp \ + build/rootfs.verity.superblock:2c7357ed-ebd2-46d9-aec1-23d437ec2bf5:$$(../../scripts/format-uuid.sh "$$(dd if=build/rootfs.verity.roothash bs=32 skip=1 count=1 status=none)") \ + build/rootfs.ext4:4f68bce3-e8cd-4db1-96e7-fbcaf984b709:$$(../../scripts/format-uuid.sh "$$(head -c 32 build/rootfs.verity.roothash)") mv $@.tmp $@ run: build/live.img $(EXT_FS) build/rootfs.verity.roothash diff --git a/host/rootfs/default.nix b/host/rootfs/default.nix index 0a84f55..ad997d1 100644 --- a/host/rootfs/default.nix +++ b/host/rootfs/default.nix @@ -11,7 +11,7 @@ pkgs.pkgsStatic.callPackage ( }: let - inherit (lib) cleanSource cleanSourceWith concatMapStringsSep hasSuffix; + inherit (lib) concatMapStringsSep hasSuffix; inherit (nixosAllHardware.config.hardware) firmware; start-vm = import ../start-vm { @@ -120,11 +120,8 @@ in stdenvNoCC.mkDerivation { name = "spectrum-rootfs"; - src = cleanSourceWith { - filter = name: _type: - name != "${toString ./.}/build" && !(hasSuffix ".nix" name); - src = cleanSource ./.; - }; + inherit (config) src; + sourceRoot = "source/host/rootfs"; nativeBuildInputs = [ s6-rc tar2ext4 ]; diff --git a/host/start-vm/default.nix b/host/start-vm/default.nix index 6851304..a7ca521 100644 --- a/host/start-vm/default.nix +++ b/host/start-vm/default.nix @@ -5,16 +5,14 @@ { lib, stdenv, meson, ninja, rustc }: let - inherit (lib) cleanSource cleanSourceWith hasSuffix; + inherit (lib) hasSuffix; in stdenv.mkDerivation { name = "start-vm"; - src = cleanSourceWith { - filter = name: _type: !(hasSuffix ".nix" name); - src = cleanSource ./.; - }; + inherit (config) src; + sourceRoot = "source/host/start-vm"; nativeBuildInputs = [ meson ninja rustc ]; diff --git a/img/app/Makefile b/img/app/Makefile index c5a4684..7a59693 100644 --- a/img/app/Makefile +++ b/img/app/Makefile @@ -11,7 +11,6 @@ prefix = /usr/local imgdir = $(prefix)/img VMM = qemu -SCRIPTS = ../../scripts HOST_BUILD_FILES = \ build/host/appvm/blk/root.img \ @@ -29,9 +28,9 @@ build/host/appvm/vmlinux: $(VMLINUX) mkdir -p $$(dirname $@) cp $(VMLINUX) $@ -build/host/appvm/blk/root.img: $(SCRIPTS)/make-gpt.sh $(SCRIPTS)/sfdisk-field.awk build/rootfs.ext4 +build/host/appvm/blk/root.img: ../../scripts/make-gpt.sh ../../scripts/sfdisk-field.awk build/rootfs.ext4 mkdir -p $$(dirname $@) - $(SCRIPTS)/make-gpt.sh $@.tmp \ + ../../scripts/make-gpt.sh $@.tmp \ build/rootfs.ext4:4f68bce3-e8cd-4db1-96e7-fbcaf984b709:5460386f-2203-4911-8694-91400125c604:root mv $@.tmp $@ diff --git a/img/app/default.nix b/img/app/default.nix index e7d5366..5386afc 100644 --- a/img/app/default.nix +++ b/img/app/default.nix @@ -13,9 +13,7 @@ config.pkgs.pkgsStatic.callPackage ( }: let - inherit (lib) cleanSource cleanSourceWith concatMapStringsSep hasSuffix; - - scripts = import ../../scripts { inherit config; }; + inherit (lib) concatMapStringsSep hasSuffix; packages = [ execline kmod mdevd s6 s6-linux-init s6-rc @@ -66,19 +64,15 @@ in stdenvNoCC.mkDerivation { name = "spectrum-appvm"; - src = cleanSourceWith { - filter = name: _type: - name != "${toString ./.}/build" && - !(hasSuffix ".nix" name); - src = cleanSource ./.; - }; + inherit (config) src; + sourceRoot = "source/img/app"; nativeBuildInputs = [ jq s6-rc tar2ext4 util-linux ]; PACKAGES_TAR = packagesTar; VMLINUX = "${kernel.dev}/vmlinux"; - makeFlags = [ "SCRIPTS=${scripts}" "prefix=$(out)" ]; + makeFlags = [ "prefix=$(out)" ]; enableParallelBuilding = true; diff --git a/nix/checks.nix b/nix/checks.nix index bbaf78a..555ad8d 100644 --- a/nix/checks.nix +++ b/nix/checks.nix @@ -23,13 +23,7 @@ rustfmt = config.pkgs.callPackage ( { lib, runCommand, rustfmt }: runCommand "spectrum-rustfmt" { - src = lib.cleanSourceWith { - filter = path: type: - (builtins.baseNameOf path != "build" && type == "directory") - || builtins.match ''.*[^/]\.rs'' path != null; - src = lib.cleanSource ../.; - }; - + inherit (config) src; nativeBuildInputs = [ rustfmt ]; } '' shopt -s globstar @@ -41,13 +35,7 @@ shellcheck = config.pkgs.callPackage ( { lib, runCommand, shellcheck }: runCommand "spectrum-shellcheck" { - src = lib.cleanSourceWith { - filter = path: type: - (builtins.baseNameOf path != "build" && type == "directory") - || builtins.match ''.*[^/]\.sh'' path != null; - src = lib.cleanSource ../.; - }; - + inherit (config) src; nativeBuildInputs = [ shellcheck ]; } '' shopt -s globstar diff --git a/nix/eval-config.nix b/nix/eval-config.nix index 467f877..8ba7744 100644 --- a/nix/eval-config.nix +++ b/nix/eval-config.nix @@ -10,4 +10,6 @@ ({ pkgs ? import <nixpkgs> {} }: { inherit pkgs; + + src = import ./src.nix { inherit (pkgs) lib; }; }) config diff --git a/nix/src.nix b/nix/src.nix new file mode 100644 index 0000000..9c0be2c --- /dev/null +++ b/nix/src.nix @@ -0,0 +1,14 @@ +# SPDX-License-Identifier: MIT +# SPDX-FileCopyrightText: 2023 Alyssa Ross <hi@alyssa.is> + +{ lib }: + +lib.cleanSourceWith { + filter = path: type: + path != toString ../Documentation/_site && + path != toString ../Documentation/.jekyll-cache && + path != toString ../Documentation/diagrams/stack.svg && + (type == "file" -> !lib.hasSuffix ".nix" path) && + (type == "directory" -> builtins.baseNameOf path != "build"); + src = lib.cleanSource ../.; +} diff --git a/release/live/Makefile b/release/live/Makefile index 773d597..f887f0a 100644 --- a/release/live/Makefile +++ b/release/live/Makefile @@ -10,15 +10,14 @@ MCOPY = mcopy MKFS_FAT = mkfs.fat MMD = mmd OBJCOPY = objcopy -SCRIPTS = ../../scripts TRUNCATE = truncate VERITYSETUP = veritysetup -build/live.img: $(SCRIPTS)/format-uuid.sh $(SCRIPTS)/make-gpt.sh build/boot.fat build/rootfs.verity.superblock build/rootfs.verity.roothash $(ROOT_FS) $(EXT_FS) - $(SCRIPTS)/make-gpt.sh $@.tmp \ +build/live.img: ../../scripts/format-uuid.sh ../../scripts/make-gpt.sh build/boot.fat build/rootfs.verity.superblock build/rootfs.verity.roothash $(ROOT_FS) $(EXT_FS) + ../../scripts/make-gpt.sh $@.tmp \ build/boot.fat:c12a7328-f81f-11d2-ba4b-00a0c93ec93b \ - build/rootfs.verity.superblock:2c7357ed-ebd2-46d9-aec1-23d437ec2bf5:$$($(SCRIPTS)/format-uuid.sh "$$(dd if=build/rootfs.verity.roothash bs=32 skip=1 count=1 status=none)") \ - $(ROOT_FS):4f68bce3-e8cd-4db1-96e7-fbcaf984b709:$$($(SCRIPTS)/format-uuid.sh "$$(head -c 32 build/rootfs.verity.roothash)") \ + build/rootfs.verity.superblock:2c7357ed-ebd2-46d9-aec1-23d437ec2bf5:$$(../../scripts/format-uuid.sh "$$(dd if=build/rootfs.verity.roothash bs=32 skip=1 count=1 status=none)") \ + $(ROOT_FS):4f68bce3-e8cd-4db1-96e7-fbcaf984b709:$$(../../scripts/format-uuid.sh "$$(head -c 32 build/rootfs.verity.roothash)") \ $(EXT_FS):9293e1ff-cee4-4658-88be-898ec863944f mv $@.tmp $@ diff --git a/release/live/default.nix b/release/live/default.nix index 4301ccc..66bba26 100644 --- a/release/live/default.nix +++ b/release/live/default.nix @@ -9,13 +9,12 @@ let inherit (config) pkgs; - inherit (pkgs.lib) cleanSource cleanSourceWith hasSuffix toUpper; + inherit (pkgs.lib) hasSuffix toUpper; extfs = pkgs.pkgsStatic.callPackage ../../host/initramfs/extfs.nix { inherit config; }; rootfs = import ../../host/rootfs { inherit config; }; - scripts = import ../../scripts { inherit config; }; initramfs = import ../../host/initramfs { inherit config rootfs; }; efiArch = stdenv.hostPlatform.efiArch; in @@ -23,12 +22,8 @@ in stdenvNoCC.mkDerivation { name = "spectrum-live.img"; - src = cleanSourceWith { - filter = name: _type: - name != "${toString ./.}/build" && - !(hasSuffix ".nix" name); - src = cleanSource ./.; - }; + inherit (config) src; + sourceRoot = "source/release/live"; nativeBuildInputs = [ cryptsetup dosfstools jq mtools util-linux ]; @@ -40,7 +35,6 @@ stdenvNoCC.mkDerivation { EFINAME = "BOOT${toUpper efiArch}.EFI"; buildFlags = [ "build/live.img" ]; - makeFlags = [ "SCRIPTS=${scripts}" ]; installPhase = '' runHook preInstall diff --git a/scripts/default.nix b/scripts/default.nix deleted file mode 100644 index 2237cb5..0000000 --- a/scripts/default.nix +++ /dev/null @@ -1,13 +0,0 @@ -# SPDX-License-Identifier: MIT -# SPDX-FileCopyrightText: 2022 Alyssa Ross <hi@alyssa.is> - -{ config ? import ../nix/eval-config.nix {} }: - -let - inherit (config.pkgs.lib) cleanSource cleanSourceWith hasSuffix; -in - -cleanSourceWith { - src = cleanSource ./.; - filter = name: _type: !(hasSuffix ".nix" name); -} diff --git a/vm/sys/net/Makefile b/vm/sys/net/Makefile index 2b9004b..076e991 100644 --- a/vm/sys/net/Makefile +++ b/vm/sys/net/Makefile @@ -8,7 +8,6 @@ QEMU_KVM = qemu-kvm CLOUD_HYPERVISOR = cloud-hypervisor VMM = qemu -SCRIPTS = ../../../scripts HOST_BUILD_FILES = \ build/host/data/netvm/blk/root.img \ @@ -31,9 +30,9 @@ build/host/data/netvm/vmlinux: $(VMLINUX) mkdir -p $$(dirname $@) cp $(VMLINUX) $@ -build/host/data/netvm/blk/root.img: $(SCRIPTS)/make-gpt.sh $(SCRIPTS)/sfdisk-field.awk build/rootfs.ext4 +build/host/data/netvm/blk/root.img: ../../../scripts/make-gpt.sh ../../../scripts/sfdisk-field.awk build/rootfs.ext4 mkdir -p $$(dirname $@) - $(SCRIPTS)/make-gpt.sh $@.tmp \ + ../../../scripts/make-gpt.sh $@.tmp \ build/rootfs.ext4:4f68bce3-e8cd-4db1-96e7-fbcaf984b709:ea21da27-0391-48da-9235-9d2ab2ca7844:root mv $@.tmp $@ diff --git a/vm/sys/net/default.nix b/vm/sys/net/default.nix index e9a2f05..9d75728 100644 --- a/vm/sys/net/default.nix +++ b/vm/sys/net/default.nix @@ -14,9 +14,7 @@ config.pkgs.pkgsStatic.callPackage ( }: let - inherit (lib) cleanSource cleanSourceWith concatMapStringsSep hasSuffix; - - scripts = import ../../../scripts { inherit config; }; + inherit (lib) concatMapStringsSep hasSuffix; connman = connmanMinimal; @@ -75,20 +73,14 @@ in stdenvNoCC.mkDerivation { name = "spectrum-netvm"; - src = cleanSourceWith { - filter = name: _type: - name != "${toString ./.}/build" && - !(hasSuffix ".nix" name); - src = cleanSource ./.; - }; + inherit (config) src; + sourceRoot = "source/vm/sys/net"; nativeBuildInputs = [ jq s6-rc tar2ext4 util-linux ]; PACKAGES_TAR = packagesTar; VMLINUX = "${kernel.dev}/vmlinux"; - makeFlags = [ "SCRIPTS=${scripts}" ]; - installPhase = '' mv build/svc $out ''; |