Compare commits

...

3 Commits

Author SHA1 Message Date
Tim Van Baak 9e621aea66 Update README 2024-07-18 23:37:20 -07:00
Tim Van Baak e16e492695 Refactor to symlinkJoin with passthru 2024-07-18 23:34:25 -07:00
Tim Van Baak de23766af9 Add nixfmt formatter 2024-07-18 23:20:16 -07:00
7 changed files with 37 additions and 33 deletions

View File

@ -2,11 +2,14 @@
Repository of lists of one-liners to use as a message-of-the-day.
This repository was a learning exercise; this is not a good example to follow of how to distribute text files with Nix.
## flake
The defaultPackage output of this repository's flake is a derivation containing the motd files in this repository.
Package `motd` is a folder of the MOTD files in `motd/`. Each file's path is also accessible as a passthru attribute on the package.
```
$ nix eval --raw .#motd.rebirth
/nix/store/ikp1hxb1hrzific5wyghm2lvzv27qqxp-motd/boi-rebirth-fortunes.txt
```
## sources

View File

@ -17,11 +17,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1640223855,
"narHash": "sha256-2bOGDrou/P0E85O5CzcZcHrvDBR78kRIwSPMlaLnFb8=",
"lastModified": 1721369373,
"narHash": "sha256-KomTFhD1yPKYvU7cqJGBRyQACfmGJMMkUWJpvw3K7B8=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "e7f5c0a08e442ed5772852b9f832d5d716020ebf",
"rev": "9d5188abf958325668881e99aa74866b69214639",
"type": "github"
},
"original": {

View File

@ -1,38 +1,39 @@
{
description = "A flake of MOTD files.";
inputs.nixpkgs.url = github:NixOS/nixpkgs;
inputs.flake-utils.url = github:numtide/flake-utils;
inputs.nixpkgs.url = "github:NixOS/nixpkgs";
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = { self, nixpkgs, flake-utils }:
let
motdFiles = {
"40k" = ./40k-thought-for-the-day.txt;
rebirth = ./boi-rebirth-fortunes.txt;
bofh = ./bofh-excuses.txt;
discordium = ./discordium.txt;
};
in
flake-utils.lib.eachDefaultSystem (system:
outputs =
{
self,
nixpkgs,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
motd = pkgs.stdenv.mkDerivation {
pname = "motd";
version = "1.0";
builder = builtins.toFile "motd-builder.sh" ''
source $stdenv/setup
mkdir -p $out
${builtins.foldl'
(a: b: "${a}\n${b}")
""
(map
(attr: "cp ${motdFiles.${attr}} $out/${attr}.txt")
(builtins.attrNames motdFiles))}
'';
};
inherit (pkgs) symlinkJoin;
in
{
defaultPackage = motd;
formatter = pkgs.nixfmt-rfc-style;
packages.default = self.packages.${system}.motd;
packages.motd = symlinkJoin {
name = "motd";
paths = [ ./motd ];
passthru =
let
motd = "${self.packages.${system}.motd}";
in
{
"40k" = "${motd}/40k-thought-for-the-day.txt";
rebirth = "${motd}/boi-rebirth-fortunes.txt";
bofh = "${motd}/bofh-excuses.txt";
discordium = "${motd}/discordium.txt";
};
};
}
);
}