Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions modules/apk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# **`apk` Module**

The `apk` module offers pseudo-declarative package and repository management using [`apk`](https://github.com/alpinelinux/apk-tools).

## Features

This module is capable of:

- Package Management
- Installing packages
- Removing packages

## Package Management

### Installing

```yaml
type: apk
install:
packages:
- package-1
- package-2
```

### Removing Packages

```yaml
type: apk
remove:
packages:
- package-1
- package-2
```
65 changes: 65 additions & 0 deletions modules/apk/apk.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env nu

# Remove packages.
def remove_pkgs [remove: record]: nothing -> nothing {
let remove = $remove
| default [] packages

let remove_list = $remove.packages
| str trim

if ($remove.packages | is-not-empty) {
print $'(ansi green)Removing packages:(ansi reset)'
$remove_list
| each {
print $'- (ansi cyan)($in)(ansi reset)'
}

try {
^apk remove ...($remove_list)
} catch {|err|
return (error make {
msg: $"Failed to remove packages\n($err.msg)"
})
}
}
}

# Install packages.
#
# You can specify a list of packages to install, and you can
# specify a list of packages for a specific repo to install.
def install_pkgs [install: record]: nothing -> nothing {
let install = $install
| default [] packages

# Gather lists of the various ways a package is installed
# to report back to the user.
let install_list = $install.packages
| str trim

if ($install_list | is-not-empty) {
print $'(ansi green)Installing packages:(ansi reset)'
$install_list
| each {
print $'- (ansi cyan)($in)(ansi reset)'
}
try {
^apk add ...($install_list)
} catch {|err|
return (error make {
msg: $"Failed to install packages\n($err.msg)"
})
}
}
}

def main [config: string]: nothing -> nothing {
let config = $config
| from json
| default {} remove
| default {} install

remove_pkgs $config.remove
install_pkgs $config.install
}
32 changes: 32 additions & 0 deletions modules/apk/apk.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import "@typespec/json-schema";
using TypeSpec.JsonSchema;

@jsonSchema("/modules/apk-latest.json")
model ApkModuleLatest {
...ApkModuleV1;
}

@jsonSchema("/modules/apk-v1.json")
model ApkModuleV1 {
/**
* The apk module offers pseudo-declarative package and repository management using apk.
* https://blue-build.org/reference/modules/apk/
*/
type: "apk" | "apk@v1" | "apk@latest";

/** Configuration of packages removal. */
remove?: Remove;

/** Configuration of packages install. */
install?: Install;
}

model Install {
/** List of packages to install. */
packages: Array<string>;
}

model Remove {
/** List of packages to remove. */
packages: Array<string>;
}
11 changes: 11 additions & 0 deletions modules/apk/module.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: apk
shortdesc: The apk module offers pseudo-declarative package and repository management using apt.
example: |
type: apk
install:
packages:
- git
remove:
packages:
- firefox
- firefox-langpacks
33 changes: 33 additions & 0 deletions modules/apt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# **`apt` Module**

The `apt` module offers pseudo-declarative package and repository management using [`apt`](https://salsa.debian.org/apt-team/apt).

## Features

This module is capable of:

- Package Management
- Installing packages
- Removing packages

## Package Management

### Installing

```yaml
type: apt
install:
packages:
- package-1
- package-2
```

### Removing Packages

```yaml
type: apt
remove:
packages:
- package-1
- package-2
```
69 changes: 69 additions & 0 deletions modules/apt/apt.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env nu

# Remove packages.
def remove_pkgs [remove: record]: nothing -> nothing {
let remove = $remove
| default [] packages

let remove_list = $remove.packages
| str trim

if ($remove.packages | is-not-empty) {
print $'(ansi green)Removing packages:(ansi reset)'
$remove_list
| each {
print $'- (ansi cyan)($in)(ansi reset)'
}

try {
^apt-get -y remove ...($remove_list)
} catch {|err|
return (error make {
msg: $"Failed to remove packages\n($err.msg)"
})
}
}
}

# Install packages.
#
# You can specify a list of packages to install, and you can
# specify a list of packages for a specific repo to install.
def install_pkgs [install: record]: nothing -> nothing {
let install = $install
| default [] packages

# Gather lists of the various ways a package is installed
# to report back to the user.
let install_list = $install.packages
| str trim

if ($install_list | is-not-empty) {
print $'(ansi green)Installing packages:(ansi reset)'
$install_list
| each {
print $'- (ansi cyan)($in)(ansi reset)'
}
try {
^apt-get -y install ...($install_list)
} catch {|err|
return (error make {
msg: $"Failed to install packages\n($err.msg)"
})
}
}
}

def main [config: string]: nothing -> nothing {
let config = $config
| from json
| default {} remove
| default {} install

$env.DEBIAN_FRONTEND = 'noninteractive'

^apt-get update

remove_pkgs $config.remove
install_pkgs $config.install
}
32 changes: 32 additions & 0 deletions modules/apt/apt.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import "@typespec/json-schema";
using TypeSpec.JsonSchema;

@jsonSchema("/modules/apt-latest.json")
model AptModuleLatest {
...AptModuleV1;
}

@jsonSchema("/modules/apt-v1.json")
model AptModuleV1 {
/**
* The apt module offers pseudo-declarative package and repository management using apt.
* https://blue-build.org/reference/modules/apt/
*/
type: "apt" | "apt@v1" | "apt@latest";

/** Configuration of packages removal. */
remove?: Remove;

/** Configuration of packages install. */
install?: Install;
}

model Install {
/** List of packages to install. */
packages: Array<string>;
}

model Remove {
/** List of packages to remove. */
packages: Array<string>;
}
11 changes: 11 additions & 0 deletions modules/apt/module.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: apt
shortdesc: The apt module offers pseudo-declarative package and repository management using apt.
example: |
type: apt
install:
packages:
- git
remove:
packages:
- firefox
- firefox-langpacks
33 changes: 33 additions & 0 deletions modules/pacman/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# **`pacman` Module**

The `pacman` module offers pseudo-declarative package and repository management using [`pacman`](https://gitlab.archlinux.org/pacman/pacman/).

## Features

This module is capable of:

- Package Management
- Installing packages
- Removing packages

## Package Management

### Installing

```yaml
type: pacman
install:
packages:
- package-1
- package-2
```

### Removing Packages

```yaml
type: pacman
remove:
packages:
- package-1
- package-2
```
11 changes: 11 additions & 0 deletions modules/pacman/module.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: pacman
shortdesc: The pacman module offers pseudo-declarative package and repository management using apt.
example: |
type: pacman
install:
packages:
- git
remove:
packages:
- firefox
- firefox-langpacks
Loading