Skip to content

Commit

Permalink
feat: select the right module based on context
Browse files Browse the repository at this point in the history
  • Loading branch information
msteen committed Aug 1, 2023
1 parent db15398 commit b988e24
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 31 deletions.
31 changes: 12 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,27 @@ Experimental support for VS Code Server in NixOS. The NodeJS by default supplied

## Installation

### NixOS module
The support for VS Code Server is implemented as a systemd module. Both NixOS and Home Manager are supported, but since they each configure systemd modules slightly differently, a custom module for each had to be defined. To install, all you need to do is import the module and configure it as needed, at least enabling it.

You can add the module to your system in various ways. After the installation
you'll have to manually enable the service for each user (see below).
These instructions also work for Home Manager. You will just have to add the import and configuration in your Home Manager configuration instead.

#### Install as a tarball
### Install as a tarball

```nix
{
imports = [
# This will import the NixOS or HM module depending on whether this is added to a NixOS or HM configuration.
(fetchTarball "https://github.com/nix-community/nixos-vscode-server/tarball/master")
# Or if you want to be explicit about it for some reason:
# "${fetchTarball "https://github.com/msteen/nixos-vscode-server/tarball/master"}/modules/vscode-server/nixos.nix"
# "${fetchTarball "https://github.com/msteen/nixos-vscode-server/tarball/master"}/modules/vscode-server/home.nix"
];
services.vscode-server.enable = true;
}
```

#### Install as a flake
### Install as a flake

```nix
{
Expand All @@ -30,7 +33,11 @@ you'll have to manually enable the service for each user (see below).
outputs = { self, nixpkgs, vscode-server }: {
nixosConfigurations.example = nixpkgs.lib.nixosSystem {
modules = [
# This will import the NixOS or HM module depending on whether this is added to a NixOS or HM configuration.
vscode-server.nixosModules.default
# Or if you want to be explicit about it for some reason:
# vscode-server.nixosModules.nixos
# vscode-server.nixosModules.home
{
services.vscode-server.enable = true;
}
Expand Down Expand Up @@ -81,20 +88,6 @@ Enabling the user service creates a symlink to the Nix store, but the linked sto
ln -sfT /run/current-system/etc/systemd/user/auto-fix-vscode-server.service ~/.config/systemd/user/auto-fix-vscode-server.service
```

### Home Manager

Put this code into your [home-manager](https://github.com/nix-community/home-manager) configuration i.e. in `~/.config/nixpkgs/home.nix`:

```nix
{
imports = [
"${fetchTarball "https://github.com/msteen/nixos-vscode-server/tarball/master"}/modules/vscode-server/home.nix"
];
services.vscode-server.enable = true;
}
```

## Usage

When using VS Code as released by Microsoft without any special needs, just enabling and starting the service should be enough to make things work. If you have some custom build or needs, there are a few options available that might help you out.
Expand Down
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
{
nixosModule = self.nixosModules.default; # Deprecrated, but perhaps still in use.
nixosModules.default = import ./modules/vscode-server;
nixosModules.nixos = import ./modules/vscode-server/nixos.nix; # Silly, but explicit.
nixosModules.home = self.homeModules.default; # Backwards compatiblity.
homeModules.default = import ./modules/vscode-server/home.nix; # Consistent with homeConfigurations.
}
Expand Down
File renamed without changes.
17 changes: 6 additions & 11 deletions modules/vscode-server/default.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import ./module.nix ({
name,
description,
serviceConfig,
}: {
systemd.user.services.${name} = {
enable = true;
inherit description serviceConfig;
wantedBy = [ "default.target" ];
};
})
{ lib }:
import (
if lib ? hm
then ./home.nix
else ./nixos.nix
)
2 changes: 1 addition & 1 deletion modules/vscode-server/home.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ./module.nix ({
import ./_module.nix ({
name,
description,
serviceConfig,
Expand Down
11 changes: 11 additions & 0 deletions modules/vscode-server/nixos.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import ./_module.nix ({
name,
description,
serviceConfig,
}: {
systemd.user.services.${name} = {
enable = true;
inherit description serviceConfig;
wantedBy = [ "default.target" ];
};
})

0 comments on commit b988e24

Please sign in to comment.