NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.06k stars 14.04k forks source link

Package Homer #152343

Open hacker1024 opened 2 years ago

hacker1024 commented 2 years ago

Project description

A dead simple static HOMepage for your servER to keep your services on hand, from a simple yaml configuration file.

Homer is a homepage to link to other hosted services. As the configuration is all done in YAML, it shouldn't be too hard to represent in a Nix derivation.

Metadata

Kranzes commented 2 years ago

I managed to package it, the only issue is, that it's just a static site basically? It doesn't have a binary or anything. What would you like to do with it?

aanderse commented 2 years ago

I was thinking about trying out homer too. Please post if you don't mind 👍

Kranzes commented 2 years ago

Again, it is just a static site with html/js/css, you can get it already built from homer's releases on github. It does not have a binary. Take a look at this: https://github.com/pborzenkov/nix-config/blob/master/nixos/machines/rock/dashboard.nix

aanderse commented 2 years ago

Oh I thought you had to "build" it with your custom yaml file. Is that yaml file read at runtime?

Kranzes commented 2 years ago

I believe it is, yes.

aanderse commented 2 years ago

Oh... lol. Since fetchzip exists so we'll consider this "packaged" already.

@hacker1024 please feel free to ping if you need a hand running this at all.

Stunkymonkey commented 2 years ago

i agree, that using fetchzip is simple, but on the other hand the application has to be updated by yourself manually every now and then.

Stunkymonkey commented 2 years ago

i would welcome this as a package in nixpkgs. Therefore I will reopen it.

estaroc commented 1 year ago

Does anyone have any advice on how to get this working? I looked at the linked repo but I had trouble replicating their setup: I am new to nixos and haven't messed around much with custom derivations yet so I assume I am missing some crucial step (I could not get around a "the option 'pkgs' does not exist" error.)

@aanderse are you still offering help with this?

hacker1024 commented 1 year ago

Perfect timing @estaroc - I just got round to setting this up yesterday. This is my WIP Homer derivation and setup. Once I'm happy with it, I'll submit a PR to Nixpkgs, but I'm not 100% sure I like the API yet. Suggestions are welcome! Regardless, it should be enough to get you started for now.

First, the Homer derivation. Unlike other solutions online, this uses symlinkJoin for adding assets, allowing the base Homer derivation to remain unmodified during use, and depending on no special Web server setup.

pkgs/homer.nix

{ lib, fetchzip, writeTextFile, runCommandLocal, symlinkJoin }:

let
  homer = fetchzip rec {
    pname = "homer";
    version = "22.11.2";
    url =
      "https://github.com/bastienwirtz/${pname}/releases/download/v${version}/${pname}.zip";
    hash = "sha256-kqD7hm4W51MTSxiYd+6O8Dbnf3c3E60av7x0HYVcAPQ=";
    stripRoot = false;

    passthru = {
      withAssets = { name ? null, config, extraAssets ? [ ] }:
        let nameSuffix = lib.optionalString (name != null) "-${name}";
        in symlinkJoin {
          name = "homer-root${nameSuffix}";
          paths = [
            homer
            (writeTextFile {
              name = "homer-configuration${nameSuffix}";
              text = builtins.toJSON config;
              destination = "/assets/config.yml";
            })
          ] ++ lib.optional (extraAssets != [ ])
            (runCommandLocal "homer-assets${nameSuffix}" { }
              (builtins.concatStringsSep "\n" (map (asset: ''
                mkdir -p $out/assets/${dirOf asset}
                ln -s ${asset} $out/assets/${asset}
              '') extraAssets)));
        };
    };
  };
in homer

Next, the derivation can be added in a Nixpkgs overlay, like so:

configuration.nix

{
  nixpkgs.overlays = [
    (self: super: {
      homer = super.callPackage ./pkgs/homer { };
    })
  ];
}

Finally, you can create a customized Homer derivation like so. This can then be used as a directory root for a Web server.

pkgs.homer.withAssets {
  name = "homelab";
  config = {
    /* https://github.com/bastienwirtz/homer/blob/main/docs/configuration.md */
  };
  extraAssets = [
    /* Any extra assets (such as icons) to include.
    /* These can be referenced through "assets/" in the Homer configuration. */
  ];
}
Stunkymonkey commented 1 year ago

for the config it might be nice to have the options with something like: https://github.com/Stunkymonkey/nixos/blob/master/modules/services/homer/config.nix

hacker1024 commented 1 year ago

Oh... lol. Since fetchzip exists so we'll consider this "packaged" already.

It would be nice to build this properly from source, to allow easy modifications. This is tricky at the moment, though, as it's a non-binary Yarn project and there's not much support for this in Nixpkgs.

tecosaur commented 6 days ago

Just tried this myself. For anybody else, Homer has recently switched to pnpm, and so you'll want a script like this:

{ lib
, fetchFromGitHub
, pnpm
, nodejs
, pkgs
, config ? {}
}:

let
  formatYaml = pkgs.formats.yaml { };
  yaml-conf = formatYaml.generate "config.yml" config;
in pkgs.stdenv.mkDerivation rec {
  pname = "homer";
  version = "24.10.1";
  src = fetchFromGitHub {
    owner = "bastienwirtz";
    repo = "homer";
    rev = "v${version}";
    hash = "sha256-9OuX32p9eEmyR7af8rIRYUvc1wmmgrYfJXsmChV9D+k=";
  };

  pnpmDeps = pnpm.fetchDeps {
    inherit pname version src patches;
    hash = "sha256-5unoY8lPaX9sZAJEBICpxSddwLV8liK1tbamB2ulvew=";
  };

  patches = [ ./sass-embedded.patch ];

  nativeBuildInputs = with pkgs; [
    nodejs
    dart-sass
    pnpm.configHook
  ];

  buildPhase = ''
    runHook preBuild
    export SASS_EMBEDDED_BIN_PATH="${pkgs.dart-sass}/bin/sass"
    pnpm build
    runHook postBuild
  '';

  installPhase = ''
    runHook preInstall
    mkdir -p $out
    cp -R dist/* $out/
    cp -r ${yaml-conf} $out/assets/config.yml
    runHook postInstall
  '';
}
sass-embedded.patch ```diff diff --git a/package.json b/package.json index f121431..97f1b11 100644 --- a/package.json +++ b/package.json @@ -28,5 +28,10 @@ "vite-plugin-pwa": "^0.20.5" }, "license": "Apache-2.0", - "packageManager": "pnpm@9.12.1+sha512.e5a7e52a4183a02d5931057f7a0dbff9d5e9ce3161e33fa68ae392125b79282a8a8a470a51dfc8a0ed86221442eb2fb57019b0990ed24fab519bf0e1bc5ccfc4" + "packageManager": "pnpm@9.12.1+sha512.e5a7e52a4183a02d5931057f7a0dbff9d5e9ce3161e33fa68ae392125b79282a8a8a470a51dfc8a0ed86221442eb2fb57019b0990ed24fab519bf0e1bc5ccfc4", + "pnpm": { + "patchedDependencies": { + "sass-embedded": "patches/sass-embedded.patch" + } + } } diff --git a/patches/sass-embedded.patch b/patches/sass-embedded.patch new file mode 100644 index 0000000..f941a8e --- /dev/null +++ b/patches/sass-embedded.patch @@ -0,0 +1,15 @@ +diff --git a/dist/lib/src/compiler-path.js b/dist/lib/src/compiler-path.js +index ae33aa3028e1a120d9e84b043bb19a71f1083b96..7a49d16a54982312ad638632d6750d7bec670f02 100644 +--- a/dist/lib/src/compiler-path.js ++++ b/dist/lib/src/compiler-path.js +@@ -24,6 +24,10 @@ function isLinuxMusl(path) { + } + /** The full command for the embedded compiler executable. */ + exports.compilerCommand = (() => { ++ const binPath = process.env.SASS_EMBEDDED_BIN_PATH; ++ if (binPath) { ++ return [binPath]; ++ } + const platform = process.platform === 'linux' && isLinuxMusl(process.execPath) + ? 'linux-musl' + : process.platform; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4c4267a..fd278e1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4,6 +4,11 @@ settings: autoInstallPeers: true excludeLinksFromLockfile: false +patchedDependencies: + sass-embedded: + hash: 6wjvcsryx2tfkpottp4wf5nbzi + path: patches/sass-embedded.patch + importers: .: @@ -26,7 +31,7 @@ importers: devDependencies: '@vitejs/plugin-vue': specifier: ^5.1.4 - version: 5.1.4(vite@5.4.9(sass-embedded@1.79.5)(sass@1.79.5)(terser@5.35.0))(vue@3.5.12) + version: 5.1.4(vite@5.4.9(sass-embedded@1.79.5(patch_hash=6wjvcsryx2tfkpottp4wf5nbzi))(sass@1.79.5)(terser@5.35.0))(vue@3.5.12) '@vue/eslint-config-prettier': specifier: ^10.0.0 version: 10.0.0(eslint@9.12.0)(prettier@3.3.3) @@ -44,13 +49,13 @@ importers: version: 3.3.3 sass-embedded: specifier: ^1.79.5 - version: 1.79.5 + version: 1.79.5(patch_hash=6wjvcsryx2tfkpottp4wf5nbzi) vite: specifier: ^5.4.9 - version: 5.4.9(sass-embedded@1.79.5)(sass@1.79.5)(terser@5.35.0) + version: 5.4.9(sass-embedded@1.79.5(patch_hash=6wjvcsryx2tfkpottp4wf5nbzi))(sass@1.79.5)(terser@5.35.0) vite-plugin-pwa: specifier: ^0.20.5 - version: 0.20.5(vite@5.4.9(sass-embedded@1.79.5)(sass@1.79.5)(terser@5.35.0))(workbox-build@7.1.0)(workbox-window@7.1.0) + version: 0.20.5(vite@5.4.9(sass-embedded@1.79.5(patch_hash=6wjvcsryx2tfkpottp4wf5nbzi))(sass@1.79.5)(terser@5.35.0))(workbox-build@7.1.0)(workbox-window@7.1.0) packages: @@ -3516,9 +3521,9 @@ snapshots: '@types/trusted-types@2.0.7': {} - '@vitejs/plugin-vue@5.1.4(vite@5.4.9(sass-embedded@1.79.5)(sass@1.79.5)(terser@5.35.0))(vue@3.5.12)': + '@vitejs/plugin-vue@5.1.4(vite@5.4.9(sass-embedded@1.79.5(patch_hash=6wjvcsryx2tfkpottp4wf5nbzi))(sass@1.79.5)(terser@5.35.0))(vue@3.5.12)': dependencies: - vite: 5.4.9(sass-embedded@1.79.5)(sass@1.79.5)(terser@5.35.0) + vite: 5.4.9(sass-embedded@1.79.5(patch_hash=6wjvcsryx2tfkpottp4wf5nbzi))(sass@1.79.5)(terser@5.35.0) vue: 3.5.12 '@vue/compiler-core@3.5.12': @@ -4693,7 +4698,7 @@ snapshots: sass-embedded-win32-x64@1.79.5: optional: true - sass-embedded@1.79.5: + sass-embedded@1.79.5(patch_hash=6wjvcsryx2tfkpottp4wf5nbzi): dependencies: '@bufbuild/protobuf': 2.2.0 buffer-builder: 0.2.0 @@ -4975,18 +4980,18 @@ snapshots: varint@6.0.0: {} - vite-plugin-pwa@0.20.5(vite@5.4.9(sass-embedded@1.79.5)(sass@1.79.5)(terser@5.35.0))(workbox-build@7.1.0)(workbox-window@7.1.0): + vite-plugin-pwa@0.20.5(vite@5.4.9(sass-embedded@1.79.5(patch_hash=6wjvcsryx2tfkpottp4wf5nbzi))(sass@1.79.5)(terser@5.35.0))(workbox-build@7.1.0)(workbox-window@7.1.0): dependencies: debug: 4.3.7 pretty-bytes: 6.1.1 tinyglobby: 0.2.9 - vite: 5.4.9(sass-embedded@1.79.5)(sass@1.79.5)(terser@5.35.0) + vite: 5.4.9(sass-embedded@1.79.5(patch_hash=6wjvcsryx2tfkpottp4wf5nbzi))(sass@1.79.5)(terser@5.35.0) workbox-build: 7.1.0 workbox-window: 7.1.0 transitivePeerDependencies: - supports-color - vite@5.4.9(sass-embedded@1.79.5)(sass@1.79.5)(terser@5.35.0): + vite@5.4.9(sass-embedded@1.79.5(patch_hash=6wjvcsryx2tfkpottp4wf5nbzi))(sass@1.79.5)(terser@5.35.0): dependencies: esbuild: 0.21.5 postcss: 8.4.47 @@ -4994,7 +4999,7 @@ snapshots: optionalDependencies: fsevents: 2.3.3 sass: 1.79.5 - sass-embedded: 1.79.5 + sass-embedded: 1.79.5(patch_hash=6wjvcsryx2tfkpottp4wf5nbzi) terser: 5.35.0 vue-eslint-parser@9.4.3(eslint@9.12.0): -- 2.47.0 ```