From 6307f71c7921c6defb66625659fd4b7d9ac0400d Mon Sep 17 00:00:00 2001 From: Mirko Lenz Date: Sun, 8 Dec 2024 21:10:37 +0100 Subject: [PATCH] feat: move more packages to overlays --- flake-modules/{scripts.nix => packages.nix} | 9 ++++- modules/default.nix | 3 ++ modules/images.nix | 40 --------------------- modules/registry.nix | 20 +++++++++++ modules/users.nix | 15 -------- overlays/build-apptainer.nix | 19 ++++++++++ overlays/build-container.nix | 24 +++++++++++++ overlays/default.nix | 9 +++++ {modules => overlays}/userctl.py | 0 9 files changed, 83 insertions(+), 56 deletions(-) rename flake-modules/{scripts.nix => packages.nix} (78%) delete mode 100644 modules/images.nix delete mode 100644 modules/users.nix create mode 100644 overlays/build-apptainer.nix create mode 100644 overlays/build-container.nix rename {modules => overlays}/userctl.py (100%) diff --git a/flake-modules/scripts.nix b/flake-modules/packages.nix similarity index 78% rename from flake-modules/scripts.nix rename to flake-modules/packages.nix index 985613a..3da85e6 100644 --- a/flake-modules/scripts.nix +++ b/flake-modules/packages.nix @@ -7,7 +7,14 @@ in { packages = { - inherit (pkgs) system-manager system-setup; + inherit (pkgs) + system-manager + system-setup + findgpu + userctl + build-apptainer + build-container + ; system-install = pkgs.writeShellApplication { name = "system-install"; text = '' diff --git a/modules/default.nix b/modules/default.nix index 98a85d8..9c8787c 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -9,6 +9,9 @@ nixglhost uv findgpu + userctl + build-apptainer + build-container ]; }; } diff --git a/modules/images.nix b/modules/images.nix deleted file mode 100644 index 6cd4a71..0000000 --- a/modules/images.nix +++ /dev/null @@ -1,40 +0,0 @@ -{ - self, - pkgs, - lib, - ... -}: -{ - environment.systemPackages = [ - (pkgs.writeShellApplication { - # https://github.com/NixOS/nixpkgs/blob/aa9d4729cbc99dabacb50e3994dcefb3ea0f7447/pkgs/build-support/docker/default.nix#L490 - name = "build-container"; - text = '' - if [ "$#" -lt 1 ]; then - echo "Usage: $0 IMAGE_NAME [OUTPUT_FOLDER=.]" >&2 - exit 1 - fi - cd "''${2:-.}" || exit 1 - BUILDER_SCRIPT="$1-builder.sh" - ${lib.getExe pkgs.nix} build --show-trace -o "$BUILDER_SCRIPT" "${self.outPath}#image-$1" - ./"$BUILDER_SCRIPT" \ - | ${lib.getExe' pkgs.pigz "pigz"} -nTR \ - > "$1.tar.gz" - rm "$BUILDER_SCRIPT" - ''; - }) - (pkgs.writeShellApplication { - name = "build-apptainer"; - text = '' - if [ "$#" -lt 1 ]; then - echo "Usage: $0 IMAGE_NAME [OUTPUT_FOLDER=.]" >&2 - exit 1 - fi - cd "''${2:-.}" || exit 1 - build-container "$1" # we already changed to the output folder - ${lib.getExe pkgs.apptainer} build "$1.sif" "docker-archive:$1.tar.gz" - rm "$1.tar.gz" - ''; - }) - ]; -} diff --git a/modules/registry.nix b/modules/registry.nix index 856339b..c67f69f 100644 --- a/modules/registry.nix +++ b/modules/registry.nix @@ -32,6 +32,26 @@ in path = inputs.nixpkgs.outPath; }; } + { + from = { + type = "indirect"; + id = "stable"; + }; + to = { + type = "path"; + path = inputs.nixpkgs.outPath; + }; + } + { + from = { + type = "indirect"; + id = "unstable"; + }; + to = { + type = "path"; + path = inputs.nixpkgs-unstable.outPath; + }; + } ]; } ); diff --git a/modules/users.nix b/modules/users.nix deleted file mode 100644 index 0704518..0000000 --- a/modules/users.nix +++ /dev/null @@ -1,15 +0,0 @@ -{ pkgs, ... }: -let - userctl = pkgs.writers.writePython3Bin "userctl" { - libraries = with pkgs.python3Packages; [ typer ]; - flakeIgnore = [ - "E203" - "E501" - ]; - } (builtins.readFile ./userctl.py); -in -{ - environment = { - systemPackages = [ userctl ]; - }; -} diff --git a/overlays/build-apptainer.nix b/overlays/build-apptainer.nix new file mode 100644 index 0000000..18b30c9 --- /dev/null +++ b/overlays/build-apptainer.nix @@ -0,0 +1,19 @@ +{ + writeShellApplication, + lib, + apptainer, + build-container, +}: +writeShellApplication { + name = "build-apptainer"; + text = '' + if [ "$#" -lt 1 ]; then + echo "Usage: $0 IMAGE_NAME [OUTPUT_FOLDER=.]" >&2 + exit 1 + fi + cd "''${2:-.}" || exit 1 + ${lib.getExe build-container} "$1" # we already changed to the output folder + ${lib.getExe apptainer} build "$1.sif" "docker-archive:$1.tar.gz" + rm "$1.tar.gz" + ''; +} diff --git a/overlays/build-container.nix b/overlays/build-container.nix new file mode 100644 index 0000000..7a70207 --- /dev/null +++ b/overlays/build-container.nix @@ -0,0 +1,24 @@ +{ + writeShellApplication, + lib, + nix, + pigz, + self, +}: +writeShellApplication { + # https://github.com/NixOS/nixpkgs/blob/aa9d4729cbc99dabacb50e3994dcefb3ea0f7447/pkgs/build-support/docker/default.nix#L490 + name = "build-container"; + text = '' + if [ "$#" -lt 1 ]; then + echo "Usage: $0 IMAGE_NAME [OUTPUT_FOLDER=.]" >&2 + exit 1 + fi + cd "''${2:-.}" || exit 1 + BUILDER_SCRIPT="$1-builder.sh" + ${lib.getExe nix} build --show-trace -o "$BUILDER_SCRIPT" "${self.outPath}#image-$1" + ./"$BUILDER_SCRIPT" \ + | ${lib.getExe' pigz "pigz"} -nTR \ + > "$1.tar.gz" + rm "$BUILDER_SCRIPT" + ''; +} diff --git a/overlays/default.nix b/overlays/default.nix index 07f82e1..ae58b1c 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -23,4 +23,13 @@ final: prev: { "E501" ]; } (builtins.readFile ./findgpu.py); + userctl = final.writers.writePython3Bin "userctl" { + libraries = with final.python3Packages; [ typer ]; + flakeIgnore = [ + "E203" + "E501" + ]; + } (builtins.readFile ./userctl.py); + build-container = final.callPackage ./build-container.nix { inherit (inputs) self; }; + build-apptainer = final.callPackage ./build-apptainer.nix { }; } diff --git a/modules/userctl.py b/overlays/userctl.py similarity index 100% rename from modules/userctl.py rename to overlays/userctl.py