diff --git a/flake.nix b/flake.nix index 4e11fbe..ab66e42 100644 --- a/flake.nix +++ b/flake.nix @@ -42,15 +42,31 @@ }@inputs: let flake = ./.; nixpkgs = nixpkgs-25-05; - overlays = [ self.overlays.default ]; self-lib = import ./lib { inherit flake self inputs; }; + + # Create overlay that includes legacy packages + overlayWithLegacy = system: final: prev: + let + baseOverlay = (import ./overlay { inherit flake self inputs nixpkgs; }) final prev; + legacyPackages = import ./legacy { inherit system pkgs self; }; + pkgs = import nixpkgs { + inherit system; + overlays = [ (import rust-overlay) ]; + }; + in + baseOverlay // legacyPackages; + + overlays = [ self.overlays.default ]; in self-lib.forAllSystemsWithPkgs ([(import rust-overlay)] ++ overlays) ({ system, pkgs, }: { - packages.${system} = import ./package { inherit system pkgs self; }; - legacyPackages.${system} = import ./legacy { inherit system pkgs self; }; - devShells.${system} = import ./devshell { inherit system pkgs self; }; + packages.${system} = import ./package { inherit system self pkgs; }; + devShells.${system} = import ./devshell { inherit system self pkgs; }; + legacyPackages.${system} = import ./legacy { + inherit system self; + pkgs = import nixpkgs { inherit system; }; + }; nixosConfigurations = { "devvm-manual|${system}" = import ./nixos/system/devvm-manual/default.nix { inherit flake self inputs system; }; diff --git a/legacy/default.nix b/legacy/default.nix index 6a3dda3..973e287 100644 --- a/legacy/default.nix +++ b/legacy/default.nix @@ -1,4 +1,7 @@ { self, system, pkgs }: -{ +let writers = pkgs.callPackage ./writer { }; -} +in { + # NOTE(yukkop): duplicate writers in root of legacyPackages and writers due nixpkgs legacyPackages consistency + writers = writers; +} // writers diff --git a/legacy/writer/default.nix b/legacy/writer/default.nix index 4a9c488..8b2f29a 100644 --- a/legacy/writer/default.nix +++ b/legacy/writer/default.nix @@ -1,41 +1,11 @@ { - lib, - writers, - gcc, -}: let - writeC = name: argsOrScript: - if lib.isAttrs argsOrScript && !lib.isDerivation argsOrScript - then - writers.makeBinWriter ( - argsOrScript - // { - compileScript = '' - # Force gcc to treat the input file as C code - ${gcc}/bin/gcc -fsyntax-only -xc $contentPath - if [ $? -ne 0 ]; then - echo "Syntax check failed" - exit 1 - fi - ${gcc}/bin/gcc -xc -o $out $contentPath - ''; - } - ) - name - else - writers.makeBinWriter { - compileScript = '' - # Force gcc to treat the input file as C code - ${gcc}/bin/gcc -fsyntax-only -xc $contentPath - if [ $? -ne 0 ]; then - echo "Syntax check failed" - exit 1 - fi - ${gcc}/bin/gcc -xc -o $out $contentPath - ''; - } - name - argsOrScript; - writeMinC = name: includes: body: + callPackage +}: rec { + writeShellApplication = callPackage ./writeShellApplication.nix {}; + writeC = callPackage ./writeC.nix {}; + writeCBin = name: writeC "/bin/${name}"; + writeMinCBin = name: includes: body: writeMinC "/bin/${name}" includes body; + writeMinC = name: includes: body: writeC name '' ${builtins.concatStringsSep "\n" (map (h: "#include " + h) includes)} @@ -43,9 +13,4 @@ ${body} } ''; -in { - writeCBin = name: writeC "/bin/${name}"; - writeC = writeC; - writeMinCBin = name: includes: body: writeMinC "/bin/${name}" includes body; - writeMinC = writeMinC; } diff --git a/legacy/writer/writeC.nix b/legacy/writer/writeC.nix new file mode 100644 index 0000000..c802451 --- /dev/null +++ b/legacy/writer/writeC.nix @@ -0,0 +1,35 @@ +{ lib, writers, gcc }: +name: argsOrScript: + if + lib.isAttrs argsOrScript + && !lib.isDerivation argsOrScript + then + writers.makeBinWriter ( + argsOrScript + // { + compileScript = '' + # Force gcc to treat the input file as C code + ${gcc}/bin/gcc -fsyntax-only -xc $contentPath + if [ $? -ne 0 ]; then + echo "Syntax check failed" + exit 1 + fi + ${gcc}/bin/gcc -xc -o $out $contentPath + ''; + } + ) + name + else + writers.makeBinWriter { + compileScript = '' + # Force gcc to treat the input file as C code + ${gcc}/bin/gcc -fsyntax-only -xc $contentPath + if [ $? -ne 0 ]; then + echo "Syntax check failed" + exit 1 + fi + ${gcc}/bin/gcc -xc -o $out $contentPath + ''; + } + name + argsOrScript diff --git a/legacy/writer/writeDashApplication.nix b/legacy/writer/writeShellApplication.nix similarity index 81% rename from legacy/writer/writeDashApplication.nix rename to legacy/writer/writeShellApplication.nix index 1d7dbd4..ba1b80e 100644 --- a/legacy/writer/writeDashApplication.nix +++ b/legacy/writer/writeShellApplication.nix @@ -1,3 +1,10 @@ +{ + writeTextFile, + lib, + shellcheck-minimal, + stdenv, + runtimeShell, +}: { /* The name of the script to write. @@ -87,6 +94,8 @@ Type: Bool */ inheritPath ? true, + + shell ? runtimeShell, }: writeTextFile { inherit @@ -99,27 +108,26 @@ writeTextFile { destination = "/bin/${name}"; allowSubstitutes = true; preferLocalBuild = false; - text = - '' - #!${dash}/bin/dash - ${lib.concatMapStringsSep "\n" (option: "set -o ${option}") bashOptions} - '' - + lib.optionalString (runtimeEnv != null) ( - lib.concatStrings ( - lib.mapAttrsToList (name: value: '' - ${lib.toShellVar name value} - export ${name} - '') runtimeEnv - ) + text = '' + #!${shell} + ${lib.concatMapStringsSep "\n" (option: "set -o ${option}") bashOptions} + '' + + lib.optionalString (runtimeEnv != null) ( + lib.concatStrings ( + lib.mapAttrsToList (name: value: '' + ${lib.toShellVar name value} + export ${name} + '') runtimeEnv ) - + lib.optionalString (runtimeInputs != [ ]) '' + ) + + lib.optionalString (runtimeInputs != [ ]) '' - export PATH="${lib.makeBinPath runtimeInputs}${lib.optionalString inheritPath ":$PATH"}" - '' - + '' + export PATH="${lib.makeBinPath runtimeInputs}${lib.optionalString inheritPath ":$PATH"}" + '' + + '' - ${text} - ''; + ${text} + ''; checkPhase = let @@ -140,11 +148,10 @@ writeTextFile { if checkPhase == null then '' runHook preCheck - #dryrun - ${dash}/bin/dash -n -O extglob "$target" + ${stdenv.shellDryRun} "$target" ${shellcheckCommand} runHook postCheck '' else checkPhase; -}; +} diff --git a/nixos/module/generic/postgresql.nix b/nixos/module/generic/postgresql.nix index 992639c..d667a36 100644 --- a/nixos/module/generic/postgresql.nix +++ b/nixos/module/generic/postgresql.nix @@ -49,7 +49,7 @@ in { extensions = let packages = { inherit (cfg.package.pkgs) pg_net pgjwt pg_cron http pg_smtp_client plsh; - hemar = inputs.hutil.packages.${system}.pg-15-hemar; + hemar = self.packages.${system}.pg-15-hemar; }; in lib.attrValues ( diff --git a/overlay/default.nix b/overlay/default.nix index 0343fc9..8f74480 100644 --- a/overlay/default.nix +++ b/overlay/default.nix @@ -5,7 +5,7 @@ in final: prev: ( packages = self.packages.${prev.system}; legacyPackages = self.legacyPackages.${prev.system}; in { - hectic = packages; + hectic = packages // legacyPackages; postgresql_17 = prev.postgresql_17 // {pkgs = prev.postgresql_17.pkgs // { http = packages.pg-17-ext-http; pg_smtp_client = packages.pg-17-ext-smtp-client; @@ -27,6 +27,5 @@ in final: prev: ( plsh = packages.pg-15-ext-plsh; hemar = packages.pg-15-ext-hemar; };}; - writers = prev.writers // legacyPackages.writers; } ) diff --git a/overlay/writeDashApplication.nix b/overlay/writeDashApplication.nix deleted file mode 100644 index 1d7dbd4..0000000 --- a/overlay/writeDashApplication.nix +++ /dev/null @@ -1,150 +0,0 @@ -{ - /* - The name of the script to write. - - Type: String - */ - name, - /* - The shell script's text, not including a shebang. - - Type: String - */ - text, - /* - Inputs to add to the shell script's `$PATH` at runtime. - - Type: [String|Derivation] - */ - runtimeInputs ? [ ], - /* - Extra environment variables to set at runtime. - - Type: AttrSet - */ - runtimeEnv ? null, - /* - `stdenv.mkDerivation`'s `meta` argument. - - Type: AttrSet - */ - meta ? { }, - /* - `stdenv.mkDerivation`'s `passthru` argument. - - Type: AttrSet - */ - passthru ? { }, - /* - The `checkPhase` to run. Defaults to `shellcheck` on supported - platforms and `bash -n`. - - The script path will be given as `$target` in the `checkPhase`. - - Type: String - */ - checkPhase ? null, - /* - Checks to exclude when running `shellcheck`, e.g. `[ "SC2016" ]`. - - See for a list of checks. - - Type: [String] - */ - excludeShellChecks ? [ ], - /* - Extra command-line flags to pass to ShellCheck. - - Type: [String] - */ - extraShellCheckFlags ? [ ], - /* - Bash options to activate with `set -o` at the start of the script. - - Defaults to `[ "errexit" "nounset" "pipefail" ]`. - - Type: [String] - */ - bashOptions ? [ - "errexit" - "nounset" - "pipefail" - ], - /* - Extra arguments to pass to `stdenv.mkDerivation`. - - :::{.caution} - Certain derivation attributes are used internally, - overriding those could cause problems. - ::: - - Type: AttrSet - */ - derivationArgs ? { }, - /* - Whether to inherit the current `$PATH` in the script. - - Type: Bool - */ - inheritPath ? true, -}: -writeTextFile { - inherit - name - meta - passthru - derivationArgs - ; - executable = true; - destination = "/bin/${name}"; - allowSubstitutes = true; - preferLocalBuild = false; - text = - '' - #!${dash}/bin/dash - ${lib.concatMapStringsSep "\n" (option: "set -o ${option}") bashOptions} - '' - + lib.optionalString (runtimeEnv != null) ( - lib.concatStrings ( - lib.mapAttrsToList (name: value: '' - ${lib.toShellVar name value} - export ${name} - '') runtimeEnv - ) - ) - + lib.optionalString (runtimeInputs != [ ]) '' - - export PATH="${lib.makeBinPath runtimeInputs}${lib.optionalString inheritPath ":$PATH"}" - '' - + '' - - ${text} - ''; - - checkPhase = - let - excludeFlags = lib.optionals (excludeShellChecks != [ ]) [ - "--exclude" - (lib.concatStringsSep "," excludeShellChecks) - ]; - # GHC (=> shellcheck) isn't supported on some platforms (such as risc-v) - # but we still want to use writeShellApplication on those platforms - shellcheckCommand = lib.optionalString shellcheck-minimal.compiler.bootstrapAvailable '' - # use shellcheck which does not include docs - # pandoc takes long to build and documentation isn't needed for just running the cli - ${lib.getExe shellcheck-minimal} ${ - lib.escapeShellArgs (excludeFlags ++ extraShellCheckFlags) - } "$target" - ''; - in - if checkPhase == null then - '' - runHook preCheck - #dryrun - ${dash}/bin/dash -n -O extglob "$target" - ${shellcheckCommand} - runHook postCheck - '' - else - checkPhase; -}; diff --git a/package/sentinèlla/default.nix b/package/sentinèlla/default.nix index 92e0ca4..90c1fbf 100644 --- a/package/sentinèlla/default.nix +++ b/package/sentinèlla/default.nix @@ -1,25 +1,35 @@ { symlinkJoin, writeShellApplication, socat, dash, hectic, curl }: let - base64 = writeShellApplication { + shell = "${dash}/bin/dash"; + bashOptions = [ + "errexit" + "nounset" + ]; + + base64 = hectic.writeShellApplication { + inherit shell bashOptions; name = "base64"; runtimeInputs = [ ]; text = builtins.readFile ./base64.sh; }; # TODO: writeDashApplication - probe = writeShellApplication { + probe = hectic.writeShellApplication { + inherit shell bashOptions; name = "probe"; runtimeInputs = [ socat dash probe-loop ]; text = builtins.readFile ./probe.sh; }; - probe-loop = writeShellApplication { + probe-loop = hectic.writeShellApplication { + inherit shell bashOptions; name = "probe-loop"; runtimeInputs = [ base64 ]; text = builtins.readFile ./probe-loop.sh; }; - sentinel = writeShellApplication { + sentinel = hectic.writeShellApplication { + inherit shell bashOptions; name = "sentinel"; runtimeInputs = [ hectic.shellplot curl ]; text = builtins.readFile ./sentinel.sh; diff --git a/package/sentinèlla/probe.sh b/package/sentinèlla/probe.sh index ffeb0d1..a89d185 100644 --- a/package/sentinèlla/probe.sh +++ b/package/sentinèlla/probe.sh @@ -1,15 +1,5 @@ #!/usr/bin/env dash -# -# -# -# -# -# -# -# - -set -euo pipefail socat -V >/dev/null dash -c 'echo ok' >/dev/null