templates icon indicating copy to clipboard operation
templates copied to clipboard

Template request: an isolated project

Open woile opened this issue 2 years ago • 1 comments

I think it would be very useful to have a general template where people can add their dependencies and run nix develop (or whatever command is needed to open my shell with the new apps). With some documentation on how to use it on the flake itself.

I would like to initialize a flake, add packages like nixpkgs.git nixpkgs.grep nixpkgs.sed nixpkgs.redis mygithubdependency.app. And finally run a command and have the shell with those deps, this way people using my project could run the scripts of whatever I've configured. I tried the different templates but I couldn't do it, I find very hard to achieve this 😅

I think maybe one of the hardest parts for me is to import another flake on github. This would be useful to import other projects in my projects.

Thanks!

woile avatar Jan 14 '23 09:01 woile

I think I've figured it out:

/*
  This flake provides a shell where you can add flakes

  Adding dependencies:
    1. Add your flake repository as an input url
    2. Add the repository name to the function signature
    3. Add your repo's package to buildInputs

  Opening shell with your deps:
    ```sh
    nix develop
    ```

  For compatibility with nix-shell add the template compat:
    ```sh
    nix flake new . -t templates#compat
    ```
*/
{
  description = "Build your shell";
  inputs = {
    utils = { url = "github:numtide/flake-utils"; };
    wpa_passphrase_rs = { url = "github:woile/wpa_passphrase_rs/main"; };
    # point 1: add repo url
  };
  # point 2: add to function
  outputs = { self, nixpkgs, utils, wpa_passphrase_rs }:
    utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs { inherit system; };
      in
      {
        devShell = with pkgs; mkShell {
          # point 3: add package
          buildInputs = [
            gnugrep
            gnused
            wpa_passphrase_rs.defaultPackage.${system}
          ];
        };
      }
    );
}

I can normally install using github:woile/wpa_passphrase_rs#wpa_passphrase. How would I do it here? doing wpa_passphrase.wpa_passphrase doesn't seem to work. But it does work with defaultPackage.

Would you be interested in adding a template like this?

woile avatar Jan 14 '23 12:01 woile