From b8fd28af2f6e6b50ea6941ca62501794dfc2dcc1 Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 3 Aug 2023 17:01:26 +0200 Subject: [PATCH] move flake-parts into pkgs or toplevel --- .../devShells/default.nix => devShell.nix | 0 flake-parts/modules.nix | 11 --- flake-parts/writers/default.nix | 45 ---------- flake-parts/writers/writers.nix | 89 ------------------- flake.nix | 16 ++-- flake-parts/formatting.nix => formatter.nix | 1 + .../installer/flake-module.nix | 0 .../merge-after-ci/default.nix | 0 .../merge-after-ci/script.sh | 0 .../tea-create-pr/default.nix | 0 {flake-parts => pkgs}/tea-create-pr/script.sh | 0 11 files changed, 10 insertions(+), 152 deletions(-) rename flake-parts/devShells/default.nix => devShell.nix (100%) delete mode 100644 flake-parts/modules.nix delete mode 100644 flake-parts/writers/default.nix delete mode 100644 flake-parts/writers/writers.nix rename flake-parts/formatting.nix => formatter.nix (99%) rename flake-parts/installer.nix => pkgs/installer/flake-module.nix (100%) rename {flake-parts => pkgs}/merge-after-ci/default.nix (100%) rename {flake-parts => pkgs}/merge-after-ci/script.sh (100%) rename {flake-parts => pkgs}/tea-create-pr/default.nix (100%) rename {flake-parts => pkgs}/tea-create-pr/script.sh (100%) diff --git a/flake-parts/devShells/default.nix b/devShell.nix similarity index 100% rename from flake-parts/devShells/default.nix rename to devShell.nix diff --git a/flake-parts/modules.nix b/flake-parts/modules.nix deleted file mode 100644 index da9e465e..00000000 --- a/flake-parts/modules.nix +++ /dev/null @@ -1,11 +0,0 @@ -# export some of our flake moduels for re-use in other projects -{ lib -, self -, ... -}: { - flake.modules.flake-parts = { - writers = ./writers; - }; - flake.nixosModules = lib.mapAttrs (_: nix: { imports = [ nix ]; }) (self.lib.findNixFiles ../nixosModules); - flake.clanModules = lib.mapAttrs (_: nix: { imports = [ nix ]; }) (self.lib.findNixFiles ../clanModules); -} diff --git a/flake-parts/writers/default.nix b/flake-parts/writers/default.nix deleted file mode 100644 index bd733e27..00000000 --- a/flake-parts/writers/default.nix +++ /dev/null @@ -1,45 +0,0 @@ -{ flake-parts-lib, ... }: { - options.perSystem = flake-parts-lib.mkPerSystemOption ( - { config - , lib - , pkgs - , ... - }: - let - writers = pkgs.callPackage ./writers.nix { }; - in - { - options.writers = { - writePureShellScript = lib.mkOption { - type = lib.types.functionTo (lib.types.functionTo lib.types.package); - description = '' - Create a script that runs in a `pure` environment, in the sense that: - - the behavior is similar to `nix-shell --pure` - - `PATH` only contains exactly the packages passed via the `PATH` arg - - `NIX_PATH` is set to the path of the current `pkgs` - - `TMPDIR` is set up and cleaned up even if the script fails - - out, if set, is kept as-is - - all environment variables are unset, except: - - the ones listed in `keepVars` defined in ./default.nix - - the ones listed via the `KEEP_VARS` variable - ''; - }; - writePureShellScriptBin = lib.mkOption { - type = lib.types.functionTo (lib.types.functionTo (lib.types.functionTo lib.types.package)); - description = '' - Creates a script in a `bin/` directory in the output; suitable for use with `lib.makeBinPath`, etc. - See {option}`writers.writePureShellScript` - ''; - }; - }; - - config.writers = { - inherit - (writers) - writePureShellScript - writePureShellScriptBin - ; - }; - } - ); -} diff --git a/flake-parts/writers/writers.nix b/flake-parts/writers/writers.nix deleted file mode 100644 index ed928773..00000000 --- a/flake-parts/writers/writers.nix +++ /dev/null @@ -1,89 +0,0 @@ -{ lib -, bash -, coreutils -, gawk -, path -, # nixpkgs path - writeScript -, writeScriptBin -, ... -}: -let - # Docs at modules/flake-parts/writers.nix - writePureShellScript = PATH: script: - writeScript "script.sh" (mkScript PATH script); - - # Docs at modules/flake-parts/writers.nix - writePureShellScriptBin = binName: PATH: script: - writeScriptBin binName (mkScript PATH script); - - mkScript = PATH: scriptText: '' - #!${bash}/bin/bash - set -Eeuo pipefail - - export PATH="${lib.makeBinPath PATH}" - export NIX_PATH=nixpkgs=${path} - - export TMPDIR=$(${coreutils}/bin/mktemp -d) - - trap "${coreutils}/bin/chmod -R +w '$TMPDIR'; ${coreutils}/bin/rm -rf '$TMPDIR'" EXIT - - if [ -z "''${IMPURE:-}" ]; then - ${cleanEnv} - fi - - ${scriptText} - ''; - - # list taken from nix source: src/nix-build/nix-build.cc - keepVars = lib.concatStringsSep " " [ - "HOME" - "XDG_RUNTIME_DIR" - "USER" - "LOGNAME" - "DISPLAY" - "WAYLAND_DISPLAY" - "WAYLAND_SOCKET" - "PATH" - "TERM" - "IN_NIX_SHELL" - "NIX_SHELL_PRESERVE_PROMPT" - "TZ" - "PAGER" - "NIX_BUILD_SHELL" - "SHLVL" - "http_proxy" - "https_proxy" - "ftp_proxy" - "all_proxy" - "no_proxy" - - # We want to keep our own variables as well - "out" - "IMPURE" - "KEEP_VARS" - "NIX_PATH" - "TMPDIR" - ]; - - cleanEnv = '' - - KEEP_VARS="''${KEEP_VARS:-}" - - unsetVars=$( - ${coreutils}/bin/comm \ - <(${gawk}/bin/awk 'BEGIN{for(v in ENVIRON) print v}' | ${coreutils}/bin/cut -d = -f 1 | ${coreutils}/bin/sort) \ - <(echo "${keepVars} $KEEP_VARS" | ${coreutils}/bin/tr " " "\n" | ${coreutils}/bin/sort) \ - -2 \ - -3 - ) - - unset $unsetVars - ''; -in -{ - inherit - writePureShellScript - writePureShellScriptBin - ; -} diff --git a/flake.nix b/flake.nix index 7e7553b7..af62a833 100644 --- a/flake.nix +++ b/flake.nix @@ -20,18 +20,20 @@ "aarch64-linux" ]; imports = [ - ./flake-parts/devShells - ./flake-parts/formatting.nix - ./flake-parts/merge-after-ci - ./flake-parts/modules.nix - ./flake-parts/installer.nix - ./flake-parts/tea-create-pr - ./flake-parts/writers + ./devShell.nix + ./formatter.nix ./templates/flake-module.nix ./templates/python-project/flake-module.nix ./pkgs/clan-cli/flake-module.nix ./pkgs/nix-unit/flake-module.nix + ./pkgs/installer/flake-module.nix + ./pkgs/tea-create-pr + ./pkgs/merge-after-ci ./lib/flake-module.nix + ({ self, lib, ... }: { + flake.nixosModules = lib.mapAttrs (_: nix: { imports = [ nix ]; }) (self.lib.findNixFiles ./nixosModules); + flake.clanModules = lib.mapAttrs (_: nix: { imports = [ nix ]; }) (self.lib.findNixFiles ./clanModules); + }) ]; }); } diff --git a/flake-parts/formatting.nix b/formatter.nix similarity index 99% rename from flake-parts/formatting.nix rename to formatter.nix index 15cbff2c..bcd04f69 100644 --- a/flake-parts/formatting.nix +++ b/formatter.nix @@ -38,3 +38,4 @@ }; }; } + diff --git a/flake-parts/installer.nix b/pkgs/installer/flake-module.nix similarity index 100% rename from flake-parts/installer.nix rename to pkgs/installer/flake-module.nix diff --git a/flake-parts/merge-after-ci/default.nix b/pkgs/merge-after-ci/default.nix similarity index 100% rename from flake-parts/merge-after-ci/default.nix rename to pkgs/merge-after-ci/default.nix diff --git a/flake-parts/merge-after-ci/script.sh b/pkgs/merge-after-ci/script.sh similarity index 100% rename from flake-parts/merge-after-ci/script.sh rename to pkgs/merge-after-ci/script.sh diff --git a/flake-parts/tea-create-pr/default.nix b/pkgs/tea-create-pr/default.nix similarity index 100% rename from flake-parts/tea-create-pr/default.nix rename to pkgs/tea-create-pr/default.nix diff --git a/flake-parts/tea-create-pr/script.sh b/pkgs/tea-create-pr/script.sh similarity index 100% rename from flake-parts/tea-create-pr/script.sh rename to pkgs/tea-create-pr/script.sh