{ inputs.nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; outputs = { self, nixpkgs }: let forAllSystems = f: nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed (sys: f nixpkgs.legacyPackages.${sys}); in { devShells = forAllSystems (pkgs: { default = pkgs.mkShell { packages = with pkgs; [ rustc cargo rustfmt rust-analyzer clippy ]; }; }); packages = forAllSystems (pkgs: { default = pkgs.rustPlatform.buildRustPackage { pname = "inshellah"; version = "0.1.1"; src = pkgs.lib.cleanSource ./.; cargoLock.lockFile = ./Cargo.lock; meta = { description = "nushell completion indexer"; mainProgram = "inshellah"; }; }; }); checks = forAllSystems ( pkgs: let checkSrc = pkgs.lib.cleanSourceWith { src = ./.; filter = path: type: let base = baseNameOf path; in !(type == "directory" && (base == ".git" || base == "target")); }; cargoDeps = pkgs.rustPlatform.importCargoLock { lockFile = ./Cargo.lock; }; rustInputs = with pkgs; [ cargo clippy stdenv.cc rustc ]; fakeInshellah = pkgs.writeShellScriptBin "inshellah" '' if [ "''${1:-}" = complete ]; then if [ -n "''${INSHELLAH_STATIC_FILE:-}" ] && [ -s "$INSHELLAH_STATIC_FILE" ]; then cat "$INSHELLAH_STATIC_FILE" printf '\n' else printf 'null\n' fi else printf 'null\n' fi ''; fakeNix = pkgs.writeShellScriptBin "nix" '' if [ "''${1:-}" = eval ]; then printf 'raw package description\n' else printf 'header\nbuild\nflake#pkg\n' fi ''; fakeSystemctl = pkgs.writeShellScriptBin "systemctl" '' printf 'demo.service loaded active running Demo Unit\n' ''; fakeKubectl = pkgs.writeShellScriptBin "kubectl" '' printf '%s\n' "$*" > "$KUBECTL_ARGS_FILE" if [ "''${1:-}" = get ] && [ "''${2:-}" = deployment ]; then printf 'deploy-a\n' elif [ "''${1:-}" = get ]; then printf 'pod-a\n' fi ''; fakeCargo = pkgs.writeShellScriptBin "cargo" '' cat <<'JSON' {"packages":[{"name":"app-lib","version":"0.1.0","targets":[{"name":"app-lib","kind":["lib"]},{"name":"app-cli","kind":["bin"]},{"name":"app-integration","kind":["test"]}]},{"name":"helper-lib","version":"0.2.0","targets":[{"name":"helper-lib","kind":["lib"]}]}]} JSON ''; fakeGit = pkgs.writeShellScriptBin "git" '' case "''${1:-}" in remote) printf 'origin\nupstream\n' ;; for-each-ref) printf 'main\tcommit\tMain branch\nfeature\tcommit\tFeature branch\n' ;; worktree) if [ "''${2:-}" = list ]; then printf 'worktree /repo/linked\n' fi ;; esac ''; fakeCompletionBackends = pkgs.symlinkJoin { name = "inshellah-fake-completion-backends"; paths = [ fakeInshellah fakeNix fakeSystemctl fakeKubectl fakeCargo fakeGit ]; }; rustCheckPhase = '' echo "running rust checks" rm -rf source-rust cp -R ${checkSrc} source-rust chmod -R u+w source-rust pushd source-rust export CARGO_HOME="$TMPDIR/cargo-home" export CARGO_TARGET_DIR="$TMPDIR/cargo-target" mkdir -p .cargo "$CARGO_HOME" cat > .cargo/config.toml < "$INSHELLAH_STATIC_FILE" nu --no-config-file -c 'source ${./nix/inshellah-completer.nu}; source ${./tests/nushell-completer.nu}' ''; mkShellCheck = name: inputs: phase: pkgs.runCommand name { nativeBuildInputs = inputs; } '' ${phase} touch $out ''; in { rust = mkShellCheck "inshellah-rust-check" rustInputs rustCheckPhase; nushell = mkShellCheck "inshellah-nushell-check" [ pkgs.nushell ] nushellCheckPhase; default = mkShellCheck "inshellah-check" (rustInputs ++ [ pkgs.nushell ]) '' ${rustCheckPhase} ${nushellCheckPhase} ''; } ); nixosModules.default = { pkgs, ... }: { imports = [ ./nix/module.nix ]; programs.inshellah.package = self.packages.${pkgs.stdenv.hostPlatform.system}.default; }; }; }