Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
61 lines (52 loc) · 1.93 KB
/
Copy pathflake.nix
File metadata and controls
61 lines (52 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
{
description = "A flake that exports all of my scripts as nix packages";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
writeNuApplicationLib = import ./default.nix;
lib = pkgs.lib;
symlinkJoin = pkgs.symlinkJoin;
writers = pkgs.writers;
nushell = pkgs.nushell;
devtools = with pkgs; [nushell gum];
scripts = {
test = {
name = "test";
modules = [];
runtimeInputs = [];
runtimeEnv = null;
text = builtins.readFile ./src/test/main.nu;
};
};
# Helper: build a package from one script attr
buildScriptPackage = script:
writeNuApplicationLib {
inherit lib symlinkJoin writers nushell;
}{
name = script.name;
modules = script.modules or [];
runtimeInputs = script.runtimeInputs or [];
runtimeEnv = script.runtimeEnv or null;
text = script.text;
};
# Map scripts attribute set to a package attribute set
packagesFromScripts = lib.mapAttrs (_: v: buildScriptPackage v) scripts;
buildDevShellForScript = script:
pkgs.mkShell {
packages = script.runtimeInputs ++ devtools ++ [];
shellHook = "echo Devshell for ${script.name} loaded";
}; # Map scripts attribute set to a package attribute set
devshellsForScripts = lib.mapAttrs (_: v: buildDevShellForScript v) scripts;
in
{
packages = packagesFromScripts;
devShells = devshellsForScripts;
# Optionally expose a default that picks one script, e.g. "test"
# defaultPackage = packagesFromScripts.test;
});
}