From 5e7cb415aa656c85fe042b1c79b386efe862a7cc Mon Sep 17 00:00:00 2001 From: Smaug123 Date: Sat, 30 Sep 2023 00:48:28 +0100 Subject: [PATCH] Extract shell script --- flake.lock | 18 +++++++++++++++++- flake.nix | 36 +++--------------------------------- 2 files changed, 20 insertions(+), 34 deletions(-) diff --git a/flake.lock b/flake.lock index ab9bed7..ee3068a 100644 --- a/flake.lock +++ b/flake.lock @@ -90,7 +90,23 @@ "inputs": { "anki-compiler": "anki-compiler", "flake-utils": "flake-utils_2", - "nixpkgs": "nixpkgs_2" + "nixpkgs": "nixpkgs_2", + "scripts": "scripts" + } + }, + "scripts": { + "locked": { + "lastModified": 1696031019, + "narHash": "sha256-MuKEC8ZZ1Znm2idxQEQYU18z/1l9rjBZaj5gdKd9elQ=", + "owner": "Smaug123", + "repo": "flake-shell-script", + "rev": "05cc0582a193d3b42b6b4e64c6ec7a9bca4bb3c5", + "type": "github" + }, + "original": { + "owner": "Smaug123", + "repo": "flake-shell-script", + "type": "github" } }, "systems": { diff --git a/flake.nix b/flake.nix index 2a5eef5..ad61e7e 100644 --- a/flake.nix +++ b/flake.nix @@ -5,6 +5,7 @@ flake-utils.url = github:numtide/flake-utils; nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.11"; anki-compiler.url = "github:Smaug123/anki-dotnet"; + scripts.url = "github:Smaug123/flake-shell-script"; }; outputs = { @@ -12,6 +13,7 @@ nixpkgs, flake-utils, anki-compiler, + scripts, }: let commit = self.shortRev or "dirty"; date = self.lastModifiedDate or self.lastModified or "19700101"; @@ -19,38 +21,6 @@ in flake-utils.lib.eachDefaultSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; - in let - createShellScript = name: contents: - pkgs.stdenv.mkDerivation { - __contentAddressed = true; - pname = name; - version = "0.1.0"; - src = contents; - - buildInputs = [ - pkgs.shellcheck - ]; - - phases = ["configurePhase" "buildPhase" "installPhase"]; - - configurePhase = '' - ${pkgs.shellcheck}/bin/shellcheck "${contents}" - ''; - - buildPhase = '' - cp "${contents}" run.sh - patchShebangs run.sh - sed -i 's_"/bin/bash"_"${pkgs.bash}/bin/bash"_' run.sh - sed -i 's_"/bin/sh"_"${pkgs.bash}/bin/bash"_' run.sh - ''; - - installPhase = '' - mkdir -p $out - mv run.sh $out/run.sh - ''; - }; - in let - buildAnki = createShellScript "anki" ./build.sh; in { packages.default = pkgs.stdenv.mkDerivation { __contentAddressed = true; @@ -59,7 +29,7 @@ src = ./.; buildInputs = []; installPhase = '' - ${buildAnki}/run.sh . "${anki-compiler.packages.${system}.default}/bin/AnkiStatic" "$out" + ${scripts.lib.createShellScript pkgs "anki" ./build.sh}/run.sh . "${anki-compiler.packages.${system}.default}/bin/AnkiStatic" "$out" ''; }; devShells.default = pkgs.mkShell {