aboutsummaryrefslogtreecommitdiff
path: root/examples/system/hello.nix
blob: 8c207f156fac3e12bb9203734d3cff710caa9470 (plain)
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
nixpkgs:
let
  pkgs = nixpkgs.legacyPackages.x86_64-linux;
  generateSystemd = type: name: config:
    (nixpkgs.lib.nixosSystem {
      modules = [{ systemd."${type}s".${name} = config; }];
      system = "x86_64-linux";
    }).config.systemd.units."${name}.${type}".text;

  mkService = generateSystemd "service";

  service = pkgs.writeTextFile {
    name = "hello.service";
    text = mkService "hello" {
      unitConfig.WantedBy = [ "multi-user.target" ];
      path = [ pkgs.hello ];
      script = "hello -g lel; touch $HOME/oof";
    };
  };
in
pkgs.writeShellScriptBin "activate" ''
  mkdir -p $HOME/.config/systemd/user
  rm $HOME/.config/systemd/user/hello.service
  ln -s ${service} $HOME/.config/systemd/user/hello.service
  systemctl --user daemon-reload
  systemctl --user restart hello
''